aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/e_widget_ilist.c
blob: 13d1da0037959fa4d6c4ed55503812c3cc5efa06 (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
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
#include "e.h"

typedef struct _E_Widget_Queue_Item E_Widget_Queue_Item;
typedef struct _E_Widget_Data       E_Widget_Data;
typedef struct _E_Widget_Callback   E_Widget_Callback;

struct _E_Widget_Data
{
   Evas_Object *o_widget, *o_scrollframe, *o_ilist;
   Eina_List   *callbacks;
   const char **value;
   struct
   {
      Eina_List   *queue;
      Ecore_Timer *timer;
      int          count;
      int          show_nth;
      int          select_nth;
   } queue;
};

struct _E_Widget_Callback
{
   void        (*func)(void *data);
   void       *data;
   const char *value;
};

struct _E_Widget_Queue_Item
{
   int          command;
   Evas_Object *icon;
   Evas_Object *end;
   const char  *label;
   int          header;
   void         (*func)(void *data);
   void        *data;
   const char  *val;
   int          relative, use_relative;
   int          item;
};

static void      _e_wid_del_hook(Evas_Object *obj);
static void      _e_wid_focus_hook(Evas_Object *obj);
static void      _e_wid_cb_scrollframe_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void      _e_wid_cb_item_sel(void *data, void *data2);
static void      _e_wid_cb_item_hilight(void *data, void *data2);
static void      _e_wid_cb_selected(void *data, Evas_Object *obj, void *event_info);
static void      _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);

static Eina_Bool _queue_timer(void *data);
static void      _queue_queue(Evas_Object *obj);
static void      _queue_append(Evas_Object *obj, int command, Evas_Object *icon, Evas_Object *end, const char *label, int header, void (*func)(void *data), void *data, const char *val, int relative, int use_relative, int item);
static void      _queue_remove(Evas_Object *obj, E_Widget_Queue_Item *qi, int del);

enum
{
   CMD_ADD,
   CMD_REMOVE,
   CMD_APPEND,
   CMD_PREPEND,
   CMD_APPEND_RELATIVE,
   CMD_PREPEND_RELATIVE,
   CMD_SELECT,
   CMD_UNSELECT,
   CMD_RANGE_SELECT,
   CMD_MULTI_SELECT,
   CMD_LABEL_SET,
   CMD_ICON_SET,
   CMD_END_SET,
   CMD_SHOW
};

static Eina_Bool
_queue_timer(void *data)
{
   Evas_Object *obj;
   E_Widget_Data *wd;
   int num;
   double start = ecore_time_get();

   obj = data;
   wd = e_widget_data_get(obj);
   if (!wd) return EINA_FALSE;
   wd->queue.timer = NULL;
   e_widget_ilist_freeze(obj);
   num = 0;
   while (wd->queue.queue)
     {
        E_Widget_Queue_Item *qi;

        qi = eina_list_data_get(wd->queue.queue);
        if (qi->command == CMD_ADD)
          {
             E_Widget_Callback *wcb, *rcb;

             wcb = E_NEW(E_Widget_Callback, 1);
             if (!wcb) break;
             wcb->func = qi->func;
             wcb->data = qi->data;
             if (qi->val) wcb->value = eina_stringshare_add(qi->val);
             if (qi->use_relative == CMD_APPEND)
               {
                  wd->callbacks = eina_list_append(wd->callbacks, wcb);
                  e_ilist_append(wd->o_ilist, qi->icon, qi->end, qi->label, qi->header,
                                 _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
               }
             else if (qi->use_relative == CMD_PREPEND)
               {
                  wd->callbacks = eina_list_prepend(wd->callbacks, wcb);
                  e_ilist_prepend(wd->o_ilist, qi->icon, qi->end, qi->label, qi->header,
                                  _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
               }
             else if (qi->use_relative == CMD_APPEND_RELATIVE)
               {
                  rcb = eina_list_nth(wd->callbacks, qi->relative);
                  if (rcb)
                    {
                       wd->callbacks = eina_list_append_relative(wd->callbacks, wcb, rcb);
                       e_ilist_append_relative(wd->o_ilist, qi->icon, qi->end, qi->label, qi->header,
                                               _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb, qi->relative);
                    }
                  else
                    {
                       wd->callbacks = eina_list_append(wd->callbacks, wcb);
                       e_ilist_append(wd->o_ilist, qi->icon, qi->end, qi->label, qi->header,
                                      _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
                    }
               }
             else if (qi->use_relative == CMD_PREPEND_RELATIVE)
               {
                  rcb = eina_list_nth(wd->callbacks, qi->relative);
                  if (rcb)
                    {
                       wd->callbacks = eina_list_prepend_relative(wd->callbacks, wcb, rcb);
                       e_ilist_prepend_relative(wd->o_ilist, qi->icon, qi->end, qi->label, qi->header,
                                                _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb, qi->relative);
                    }
                  else
                    {
                       wd->callbacks = eina_list_prepend(wd->callbacks, wcb);
                       e_ilist_prepend(wd->o_ilist, qi->icon, qi->end, qi->label, qi->header,
                                       _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
                    }
               }
             else
               {
                  E_FREE(wcb);
               }
             if (qi->icon) evas_object_show(qi->icon);
             if (qi->end) evas_object_show(qi->end);
          }
        else if (qi->command == CMD_LABEL_SET)
          e_ilist_nth_label_set(wd->o_ilist, qi->item, qi->label);
        else if (qi->command == CMD_ICON_SET)
          e_ilist_nth_icon_set(wd->o_ilist, qi->item, qi->icon);
        else if (qi->command == CMD_SHOW)
          {
             Evas_Coord x, y, w, h;
             if (num > 0) break;

             e_ilist_nth_geometry_get(wd->o_ilist, qi->item, &x, &y, &w, &h);
             if (qi->use_relative)
               e_scrollframe_child_pos_set(wd->o_scrollframe, x, y);
             else
               e_scrollframe_child_region_show(wd->o_scrollframe, x, y + h, w, h);
          }
        else if (qi->command == CMD_SELECT)
          e_ilist_selected_set(wd->o_ilist, qi->item);
        else if (qi->command == CMD_UNSELECT)
          {
             if ((wd->value) && *(wd->value))
               {
                  eina_stringshare_del(*(wd->value));
                  *(wd->value) = NULL;
               }
             e_ilist_unselect(wd->o_ilist);
          }
#if 0
        else if (qi->command == CMD_REMOVE)
          {
             E_Widget_Callback *wcb;
             Eina_List *item;

             e_ilist_remove_num(wd->o_ilist, qi->item);
             item = eina_list_nth_list(wd->callbacks, qi->item);
             if (item)
               {
                  wcb = eina_list_data_get(item);
                  if (wcb && wcb->value) eina_stringshare_del(wcb->value);
                  free(wcb);
                  wd->callbacks = eina_list_remove_list(wd->callbacks, item);
               }
          }
#endif
        else if (qi->command == CMD_MULTI_SELECT)
          e_ilist_multi_select(wd->o_ilist, qi->item);
        else if (qi->command == CMD_RANGE_SELECT)
          e_ilist_range_select(wd->o_ilist, qi->item);
        else if (qi->command == CMD_END_SET)
          e_ilist_nth_end_set(wd->o_ilist, qi->item, qi->end);
        _queue_remove(obj, qi, 0);

        if ((num++ >= 10) && (ecore_time_get() - start > 0.01))
          break;
     }
   e_widget_ilist_thaw(obj);
   e_widget_ilist_go(obj);
   _queue_queue(obj);
   return ECORE_CALLBACK_CANCEL;
}

static void
_queue_queue(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   if (!wd->queue.queue) return;
   if (wd->queue.timer) return;
   wd->queue.timer = ecore_timer_loop_add(0.00001, _queue_timer, obj);
}

static void
_queue_append(Evas_Object *obj, int command, Evas_Object *icon, Evas_Object *end,
              const char *label, int header, void (*func)(void *data), void *data,
              const char *val, int relative, int use_relative, int item)
{
   E_Widget_Data *wd;
   E_Widget_Queue_Item *qi;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   qi = E_NEW(E_Widget_Queue_Item, 1);
   if (!qi) return;
   qi->command = command;
   qi->icon = icon;
   qi->end = end;
   qi->label = eina_stringshare_add(label);
   qi->header = header;
   qi->func = func;
   qi->data = data;
   qi->val = eina_stringshare_add(val);
   qi->relative = relative;
   qi->use_relative = use_relative;
   qi->item = item;
   wd->queue.queue = eina_list_append(wd->queue.queue, qi);
   _queue_queue(obj);
}

static void
_queue_remove(Evas_Object *obj, E_Widget_Queue_Item *qi, int del)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   wd->queue.queue = eina_list_remove(wd->queue.queue, qi);
   if (del)
     {
        if (qi->icon) evas_object_del(qi->icon);
        if (qi->end) evas_object_del(qi->end);
     }
   eina_stringshare_del(qi->label);
   eina_stringshare_del(qi->val);
   free(qi);
}

static void
_queue_clear(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   while (wd->queue.queue)
     _queue_remove(obj, eina_list_data_get(wd->queue.queue), 1);
   if (wd->queue.timer) ecore_timer_del(wd->queue.timer);
   wd->queue.timer = NULL;
}

static void
_e_wid_disable_hook(Evas_Object *obj)
{
   Eina_Bool disabled;
   E_Widget_Data *wd;

   disabled = e_widget_disabled_get(obj);
   wd = e_widget_data_get(obj);
   if (!wd) return;
   e_ilist_disabled_set(wd->o_ilist, disabled);
   evas_object_freeze_events_set(wd->o_scrollframe, disabled);
}

/* externally accessible functions */
E_API Evas_Object *
e_widget_ilist_add(Evas *evas, int icon_w, int icon_h, const char **value)
{
   Evas_Object *obj, *o;
   E_Widget_Data *wd;

   wd = E_NEW(E_Widget_Data, 1);
   if (!wd) return NULL;

   obj = e_widget_add(evas);

   e_widget_del_hook_set(obj, _e_wid_del_hook);
   e_widget_focus_hook_set(obj, _e_wid_focus_hook);
   e_widget_disable_hook_set(obj, _e_wid_disable_hook);
   e_widget_data_set(obj, wd);

   wd->value = value;

   o = e_scrollframe_add(evas);
   wd->o_scrollframe = o;
   evas_object_show(o);
   e_widget_sub_object_add(obj, o);
   e_widget_resize_object_set(obj, o);
   evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
                                  _e_wid_focus_steal, obj);

   o = e_ilist_add(evas);
   wd->o_ilist = o;
   e_ilist_icon_size_set(o, icon_w, icon_h);
   evas_object_event_callback_add(wd->o_scrollframe, EVAS_CALLBACK_RESIZE,
                                  _e_wid_cb_scrollframe_resize, o);
   e_scrollframe_child_set(wd->o_scrollframe, o);
   e_widget_sub_object_add(obj, o);
   evas_object_show(o);
   evas_object_smart_callback_add(o, "selected", _e_wid_cb_selected, obj);

   evas_object_resize(obj, 32, 32);
   e_widget_size_min_set(obj, 32, 32);
   return obj;
}

E_API void
e_widget_ilist_freeze(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   e_ilist_freeze(wd->o_ilist);
}

E_API void
e_widget_ilist_thaw(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   e_ilist_thaw(wd->o_ilist);
}

E_API void
e_widget_ilist_append(Evas_Object *obj, Evas_Object *icon, const char *label, void (*func)(void *data), void *data, const char *val)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 0, func, data, val, 0, CMD_APPEND, 0);
/*
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wcb = E_NEW(E_Widget_Callback, 1);
   if (!wcb) return;

   wd = e_widget_data_get(obj);
   wcb->func = func;
   wcb->data = data;
   if (val) wcb->value = strdup(val);
   wd->callbacks = eina_list_append(wd->callbacks, wcb);
   e_ilist_append(wd->o_ilist, icon, label, 0, _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
   if (icon) evas_object_show(icon);
 */
}

E_API void
e_widget_ilist_append_full(Evas_Object *obj, Evas_Object *icon, Evas_Object *end, const char *label, void (*func)(void *data), void *data, const char *val)
{
   _queue_append(obj, CMD_ADD, icon, end, label, 0, func, data, val, 0, CMD_APPEND, 0);
}

E_API void
e_widget_ilist_header_append_relative(Evas_Object *obj, Evas_Object *icon, const char *label, int relative)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 1, NULL, NULL, NULL, relative, CMD_APPEND_RELATIVE, 0);
}

E_API void
e_widget_ilist_header_prepend_relative(Evas_Object *obj, Evas_Object *icon, const char *label, int relative)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 1, NULL, NULL, NULL, relative, CMD_PREPEND_RELATIVE, 0);
}

E_API void
e_widget_ilist_append_relative(Evas_Object *obj, Evas_Object *icon, const char *label, void (*func)(void *data), void *data, const char *val, int relative)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 0, func, data, val, relative, CMD_APPEND_RELATIVE, 0);
/*
   E_Widget_Data *wd;
   E_Widget_Callback *wcb, *rcb;

   wcb = E_NEW(E_Widget_Callback, 1);
   if (!wcb) return;

   wd = e_widget_data_get(obj);
   wcb->func = func;
   wcb->data = data;
   if (val) wcb->value = strdup(val);

   rcb = eina_list_nth(wd->callbacks, relative);
   if (rcb)
     {
        wd->callbacks = eina_list_append_relative(wd->callbacks, wcb, rcb);
        e_ilist_append_relative(wd->o_ilist, icon, label, 0, _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb, relative);
     }
   else
     {
        wd->callbacks = eina_list_append(wd->callbacks, wcb);
        e_ilist_append(wd->o_ilist, icon, label, 0, _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
     }

   if (icon) evas_object_show(icon);
 */
}

E_API void
e_widget_ilist_append_relative_full(Evas_Object *obj, Evas_Object *icon, Evas_Object *end, const char *label, void (*func)(void *data), void *data, const char *val, int relative)
{
   _queue_append(obj, CMD_ADD, icon, end, label, 0, func, data, val, relative, CMD_APPEND_RELATIVE, 0);
}

E_API void
e_widget_ilist_prepend(Evas_Object *obj, Evas_Object *icon, const char *label, void (*func)(void *data), void *data, const char *val)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 0, func, data, val, 0, CMD_PREPEND, 0);
/*
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wcb = E_NEW(E_Widget_Callback, 1);
   if (!wcb) return;

   wd = e_widget_data_get(obj);
   wcb->func = func;
   wcb->data = data;
   if (val) wcb->value = strdup(val);
   wd->callbacks = eina_list_prepend(wd->callbacks, wcb);
   e_ilist_prepend(wd->o_ilist, icon, label, 0, _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
   if (icon) evas_object_show(icon);
 */
}

E_API void
e_widget_ilist_header_prepend(Evas_Object *obj, Evas_Object *icon, const char *label)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 1, NULL, NULL, NULL, 0, CMD_PREPEND, 0);
}

E_API void
e_widget_ilist_prepend_full(Evas_Object *obj, Evas_Object *icon, Evas_Object *end, const char *label, void (*func)(void *data), void *data, const char *val)
{
   _queue_append(obj, CMD_ADD, icon, end, label, 0, func, data, val, 0, CMD_PREPEND, 0);
}

E_API void
e_widget_ilist_prepend_relative(Evas_Object *obj, Evas_Object *icon, const char *label, void (*func)(void *data), void *data, const char *val, int relative)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 0, func, data, val, relative, CMD_PREPEND_RELATIVE, 0);
/*
   E_Widget_Data *wd;
   E_Widget_Callback *wcb, *rcb;

   wcb = E_NEW(E_Widget_Callback, 1);
   if (!wcb) return;

   wd = e_widget_data_get(obj);
   wcb->func = func;
   wcb->data = data;
   if (val) wcb->value = strdup(val);

   rcb = eina_list_nth(wd->callbacks, relative);
   if (rcb)
     {
        wd->callbacks = eina_list_prepend_relative(wd->callbacks, wcb, rcb);
        e_ilist_prepend_relative(wd->o_ilist, icon, label, 0, _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb, relative);
     }
   else
     {
        wd->callbacks = eina_list_prepend(wd->callbacks, wcb);
        e_ilist_prepend(wd->o_ilist, icon, label, 0, _e_wid_cb_item_sel, _e_wid_cb_item_hilight, wd, wcb);
     }

   if (icon) evas_object_show(icon);
 */
}

E_API void
e_widget_ilist_prepend_relative_full(Evas_Object *obj, Evas_Object *icon, Evas_Object *end, const char *label, void (*func)(void *data), void *data, const char *val, int relative)
{
   _queue_append(obj, CMD_ADD, icon, end, label, 0, func, data, val, relative, CMD_PREPEND_RELATIVE, 0);
}

E_API void
e_widget_ilist_header_append(Evas_Object *obj, Evas_Object *icon, const char *label)
{
   _queue_append(obj, CMD_ADD, icon, NULL, label, 1, NULL, NULL, NULL, 0, CMD_APPEND, 0);
/*
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wcb = E_NEW(E_Widget_Callback, 1);
   if (!wcb) return;

   wd = e_widget_data_get(obj);
   wd->callbacks = eina_list_append(wd->callbacks, wcb);
   e_ilist_append(wd->o_ilist, icon, label, 1, NULL, NULL, NULL, NULL);
   if (icon) evas_object_show(icon);
 */
}

E_API void
e_widget_ilist_selector_set(Evas_Object *obj, int selector)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   e_ilist_selector_set(wd->o_ilist, selector);
}

E_API void
e_widget_ilist_go(Evas_Object *obj)
{
   E_Widget_Data *wd;
   Evas_Coord mw, mh, vw, vh, w, h;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   wd->o_widget = obj;
   e_ilist_size_min_get(wd->o_ilist, &mw, &mh);
   evas_object_resize(wd->o_ilist, mw, mh);
   e_scrollframe_child_viewport_size_get(wd->o_scrollframe, &vw, &vh);
   evas_object_geometry_get(wd->o_scrollframe, NULL, NULL, &w, &h);
   if (mw > vw)
     {
        Evas_Coord wmw, wmh;

        e_widget_size_min_get(obj, &wmw, &wmh);
        e_widget_size_min_set(obj, mw + (w - vw), wmh);
     }
   else if (mw < vw)
     evas_object_resize(wd->o_ilist, vw, mh);
}

E_API void
e_widget_ilist_clear(Evas_Object *obj)
{
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   _queue_clear(obj);
   e_ilist_clear(wd->o_ilist);
   e_scrollframe_child_pos_set(wd->o_scrollframe, 0, 0);
   EINA_LIST_FREE(wd->callbacks, wcb)
     {
        eina_stringshare_del(wcb->value);
        free(wcb);
     }
}

E_API int
e_widget_ilist_count(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return 0;

   if (wd->queue.queue)
     {
        E_Widget_Queue_Item *qi;
        Eina_List *l;
        int cnt = 0;

        EINA_LIST_FOREACH(wd->queue.queue, l, qi)
          if (qi->command == CMD_ADD) cnt++;

        return cnt + e_ilist_count(wd->o_ilist);
     }
   else
     return e_ilist_count(wd->o_ilist);
}

E_API const Eina_List *
e_widget_ilist_items_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_items_get(wd->o_ilist);
}

E_API Eina_Bool
e_widget_ilist_nth_is_header(Evas_Object *obj, int n)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return EINA_FALSE;
   return e_ilist_nth_is_header(wd->o_ilist, n);
}

E_API void
e_widget_ilist_nth_label_set(Evas_Object *obj, int n, const char *label)
{
   _queue_append(obj, CMD_LABEL_SET, NULL, NULL, label, 0, NULL, NULL, NULL, 0, 0, n);
/*
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   e_ilist_nth_label_set(wd->o_ilist, n, label);
 */
}

E_API const char *
e_widget_ilist_nth_label_get(Evas_Object *obj, int n)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_nth_label_get(wd->o_ilist, n);
}

E_API void
e_widget_ilist_nth_icon_set(Evas_Object *obj, int n, Evas_Object *icon)
{
   _queue_append(obj, CMD_ICON_SET, icon, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, n);
/*
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   e_ilist_nth_icon_set(wd->o_ilist, n, icon);
 */
}

E_API Evas_Object *
e_widget_ilist_nth_icon_get(Evas_Object *obj, int n)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_nth_icon_get(wd->o_ilist, n);
}

E_API void
e_widget_ilist_nth_end_set(Evas_Object *obj, int n, Evas_Object *end)
{
   _queue_append(obj, CMD_END_SET, NULL, end, NULL, 0, NULL, NULL, NULL, 0, 0, n);
}

E_API Evas_Object *
e_widget_ilist_nth_end_get(Evas_Object *obj, int n)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_nth_end_get(wd->o_ilist, n);
}

E_API void *
e_widget_ilist_nth_data_get(Evas_Object *obj, int n)
{
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   wcb = eina_list_nth(wd->callbacks, n);

   if (!wcb)
     return NULL;
   else
     return wcb->data;
}

E_API const char *
e_widget_ilist_nth_value_get(Evas_Object *obj, int n)
{
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   wcb = eina_list_nth(wd->callbacks, n);

   if (!wcb)
     return NULL;
   else
     return wcb->value;
}

/**
 * Return if the given item returned by e_widget_ilist_items_get()
 * is a header.
 *
 * This avoids expensive lookups to the nth element, however it's not
 * able to check any validity on the given pointer and may crash. Be
 * sure to use only with valid return of e_widget_ilist_items_get().
 */
E_API Eina_Bool
e_widget_ilist_item_is_header(const E_Ilist_Item *it)
{
   return it->header;
}

/**
 * Return the label of given item returned by e_widget_ilist_items_get().
 *
 * This avoids expensive lookups to the nth element, however it's not
 * able to check any validity on the given pointer and may crash. Be
 * sure to use only with valid return of e_widget_ilist_items_get().
 */
E_API const char *
e_widget_ilist_item_label_get(const E_Ilist_Item *it)
{
   return it->label;
}

/**
 * Return the icon of given item returned by e_widget_ilist_items_get().
 *
 * This avoids expensive lookups to the nth element, however it's not
 * able to check any validity on the given pointer and may crash. Be
 * sure to use only with valid return of e_widget_ilist_items_get().
 *
 * Do not delete this object!
 */
E_API Evas_Object *
e_widget_ilist_item_icon_get(const E_Ilist_Item *it)
{
   return it->o_icon;
}

/**
 * Return the end of given item returned by e_widget_ilist_items_get().
 *
 * This avoids expensive lookups to the nth element, however it's not
 * able to check any validity on the given pointer and may crash. Be
 * sure to use only with valid return of e_widget_ilist_items_get().
 *
 * Do not delete this object!
 */
E_API Evas_Object *
e_widget_ilist_item_end_get(const E_Ilist_Item *it)
{
   return it->o_end;
}

/**
 * Return the data of given item returned by e_widget_ilist_items_get().
 *
 * This avoids expensive lookups to the nth element, however it's not
 * able to check any validity on the given pointer and may crash. Be
 * sure to use only with valid return of e_widget_ilist_items_get().
 *
 * Do not delete this object!
 */
E_API void *
e_widget_ilist_item_data_get(const E_Ilist_Item *it)
{
   E_Widget_Callback *wcb = it->data2;

   if (!wcb)
     return NULL;
   else
     return wcb->data;
}

E_API const char *
e_widget_ilist_item_value_get(const E_Ilist_Item *it)
{
   E_Widget_Callback *wcb = it->data2;

   if (!wcb)
     return NULL;
   else
     return wcb->value;
}

/**
 * Show the nth element of an ilist
 * @param obj the ilist
 * @param n the number of the element to show
 * @param top if true, place this item at the top, otherwise scroll just
 * enough to show the element (from the current position).
 */
E_API void
e_widget_ilist_nth_show(Evas_Object *obj, int n, int top)
{
   _queue_append(obj, CMD_SHOW, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, top, n);
/*
   E_Widget_Data *wd;
   Evas_Coord x, y, w, h;

   wd = e_widget_data_get(obj);
   e_ilist_nth_geometry_get(wd->o_ilist, n, &x, &y, &w, &h);
   if (top)
     e_scrollframe_child_pos_set(wd->o_scrollframe, x, y);
   else
     e_scrollframe_child_region_show(wd->o_scrollframe, x, y, w, h);
 */
}

E_API void
e_widget_ilist_selected_set(Evas_Object *obj, int n)
{
   _queue_append(obj, CMD_SELECT, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, n);
/*
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   e_ilist_selected_set(wd->o_ilist, n);
 */
}

E_API const Eina_List *
e_widget_ilist_selected_items_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_selected_items_get(wd->o_ilist);
}

E_API int
e_widget_ilist_selected_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return 0;
   return e_ilist_selected_get(wd->o_ilist);
}

E_API const char *
e_widget_ilist_selected_label_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_selected_label_get(wd->o_ilist);
}

E_API Evas_Object *
e_widget_ilist_selected_icon_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_selected_icon_get(wd->o_ilist);
}

E_API void *
e_widget_ilist_selected_data_get(Evas_Object *obj)
{
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   wcb = eina_list_nth(wd->callbacks, e_ilist_selected_get(wd->o_ilist));

   return wcb ? wcb->data : NULL;
}

E_API Evas_Object *
e_widget_ilist_selected_end_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   return e_ilist_selected_end_get(wd->o_ilist);
}

E_API int
e_widget_ilist_selected_count_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return 0;
   return e_ilist_selected_count_get(wd->o_ilist);
}

E_API const char *
e_widget_ilist_selected_value_get(Evas_Object *obj)
{
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wd = e_widget_data_get(obj);
   if (!wd) return NULL;
   wcb = eina_list_nth(wd->callbacks, e_ilist_selected_get(wd->o_ilist));

   if (!wcb)
     return NULL;
   else
     return wcb->value;
}

E_API void
e_widget_ilist_unselect(Evas_Object *obj)
{
   _queue_append(obj, CMD_UNSELECT, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, 0);
/*
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if ((wd->value) && *(wd->value))
       {
          free(*(wd->value));
 *(wd->value) = NULL;
       }
   e_ilist_unselect(wd->o_ilist);
 */
}

E_API void
e_widget_ilist_remove_num(Evas_Object *obj, int n)
{
/*    _queue_append(obj, CMD_REMOVE, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, n); */
   E_Widget_Callback *wcb;
   E_Widget_Data *wd;
   Eina_List *item;

   if (n < 0) return;
   wd = e_widget_data_get(obj);
   if (!wd) return;
   e_ilist_remove_num(wd->o_ilist, n);
   item = eina_list_nth_list(wd->callbacks, n);
   if (item)
     {
        wcb = eina_list_data_get(item);
        if (wcb) eina_stringshare_del(wcb->value);
        free(wcb);
        wd->callbacks = eina_list_remove_list(wd->callbacks, item);
     }
}

E_API void
e_widget_ilist_multi_select_set(Evas_Object *obj, Eina_Bool multi)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   e_ilist_multi_select_set(wd->o_ilist, multi);
}

E_API Eina_Bool
e_widget_ilist_multi_select_get(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return EINA_FALSE;
   return e_ilist_multi_select_get(wd->o_ilist);
}

E_API void
e_widget_ilist_multi_select(Evas_Object *obj, int n)
{
   _queue_append(obj, CMD_MULTI_SELECT, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, n);
/*
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   e_ilist_multi_select(wd->o_ilist, n);
 */
}

E_API void
e_widget_ilist_range_select(Evas_Object *obj, int n)
{
   _queue_append(obj, CMD_RANGE_SELECT, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, 0, n);
/*
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   e_ilist_range_select(wd->o_ilist, n);
 */
}

E_API Eina_Bool
e_widget_ilist_custom_edje_file_set(Evas_Object *obj, const char *file, const char *group)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return EINA_FALSE;
   if (group)
     {
        char buf[1024];

        snprintf(buf, sizeof(buf), "%s/scrollframe", group);
        e_scrollframe_custom_edje_file_set(wd->o_scrollframe, file, buf);
     }
   return e_ilist_custom_edje_file_set(wd->o_ilist, file, group);
}

E_API void
e_widget_ilist_preferred_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
{
   Evas_Coord ww, hh, mw, mh, vw, vh;
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   evas_object_geometry_get(wd->o_scrollframe, NULL, NULL, &ww, &hh);
   evas_object_resize(wd->o_scrollframe, 200, 200);
   e_scrollframe_child_viewport_size_get(wd->o_scrollframe, &vw, &vh);
   e_ilist_size_min_get(wd->o_ilist, &mw, &mh);
   evas_object_resize(wd->o_scrollframe, ww, hh);
   if (w) *w = 200 - vw + mw;
   if (h) *h = 200 - vh + mh;
}

static void
_e_wid_del_hook(Evas_Object *obj)
{
   E_Widget_Data *wd;
   E_Widget_Callback *wcb;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   _queue_clear(obj);
   EINA_LIST_FREE(wd->callbacks, wcb)
     {
        if (wcb) eina_stringshare_del(wcb->value);
        free(wcb);
     }
   free(wd);
}

static void
_e_wid_focus_hook(Evas_Object *obj)
{
   E_Widget_Data *wd;

   wd = e_widget_data_get(obj);
   if (!wd) return;
   if (e_widget_focus_get(obj))
     {
        edje_object_signal_emit(e_scrollframe_edje_object_get(wd->o_scrollframe), "e,state,focused", "e");
        evas_object_focus_set(wd->o_ilist, 1);
     }
   else
     {
        edje_object_signal_emit(e_scrollframe_edje_object_get(wd->o_scrollframe), "e,state,unfocused", "e");
        evas_object_focus_set(wd->o_ilist, 0);
     }
}

static void
_e_wid_cb_scrollframe_resize(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Evas_Coord mw, mh, vw, vh, w, h;

   e_scrollframe_child_viewport_size_get(obj, &vw, &vh);
   e_ilist_size_min_get(data, &mw, &mh);
   evas_object_geometry_get(data, NULL, NULL, &w, &h);
   if (vw >= mw)
     {
        if (w != vw) evas_object_resize(data, vw, h);
        evas_object_smart_callback_call(data, "changed", obj);
     }
}

static void
_e_wid_cb_item_sel(void *data, void *data2)
{
   E_Widget_Data *wd;
   Evas_Coord x, y, w, h;
   E_Widget_Callback *wcb;

   wd = data;
   wcb = data2;
   e_ilist_selected_geometry_get(wd->o_ilist, &x, &y, &w, &h);
   e_scrollframe_child_region_show(wd->o_scrollframe, x, y, w, h);
   if (wd->o_widget)
     {
        if (wd->value)
          {
             if (*(wd->value)) eina_stringshare_del(*(wd->value));
             if (wcb->value)
               *(wd->value) = eina_stringshare_ref(wcb->value);
             else
               *(wd->value) = NULL;
          }
        if (wcb->func) wcb->func(wcb->data);
        e_widget_change(wd->o_widget);
     }
}

static void
_e_wid_cb_item_hilight(void *data, void *data2 EINA_UNUSED)
{
   E_Widget_Data *wd;
   Evas_Coord x, y, w, h;

   wd = data;
   e_ilist_selected_geometry_get(wd->o_ilist, &x, &y, &w, &h);
   e_scrollframe_child_region_show(wd->o_scrollframe, x, y, w, h);
}

static void
_e_wid_cb_selected(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   evas_object_smart_callback_call(data, "selected", event_info);
}

static void
_e_wid_focus_steal(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   e_widget_focus_steal(data);
}