summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_menu.c
blob: d188a04a23bab4a8ab9ea1c812debd50fa910605 (plain)
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
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define ELM_WIDGET_PROTECTED
#define ELM_INTERFACE_ATSPI_ACCESSIBLE_PROTECTED
#define ELM_INTERFACE_ATSPI_SELECTION_PROTECTED

#define ELM_WIDGET_ITEM_PROTECTED
#include <Elementary.h>

#include "elm_priv.h"
#include "elm_widget_menu.h"

#define MY_CLASS ELM_MENU_CLASS

#define MY_CLASS_NAME "Elm_Menu"
#define MY_CLASS_NAME_LEGACY "elm_menu"

#define ELM_PRIV_MENU_SIGNALS(cmd) \
   cmd(SIG_CLICKED, "clicked", "") \
   cmd(SIG_DISMISSED, "dismissed", "")

ELM_PRIV_MENU_SIGNALS(ELM_PRIV_STATIC_VARIABLE_DECLARE);

static const Evas_Smart_Cb_Description _smart_callbacks[] = {
   ELM_PRIV_MENU_SIGNALS(ELM_PRIV_SMART_CALLBACKS_DESC)
   {SIG_WIDGET_LANG_CHANGED, ""}, /**< handled by elm_widget */
   {SIG_WIDGET_ACCESS_CHANGED, ""}, /**< handled by elm_widget */
   {NULL, NULL}
};
#undef ELM_PRIV_MENU_SIGNALS

EOLIAN static void
_elm_menu_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   Elm_Menu_Item_Data *it;
   Eina_List *l;

   EINA_LIST_FOREACH(sd->items, l, it)
     elm_wdg_item_translate(EO_OBJ(it));
}

static void
_item_del(Elm_Object_Item *eo_item)
{
   Elm_Object_Item *child;
   ELM_MENU_ITEM_DATA_GET(eo_item, item);

   Eina_List *itr, *itr2;
   EINA_LIST_FOREACH_SAFE(item->submenu.items, itr, itr2, child)
     _item_del(child);
   eina_list_free(item->submenu.items);

   efl_del(eo_item);
}

static void
_submenu_hide(Elm_Menu_Item_Data *item)
{
   Eina_List *l;
   Elm_Object_Item *eo_item2;

   evas_object_hide(item->submenu.hv);
   item->submenu.open = EINA_FALSE;

   EINA_LIST_FOREACH(item->submenu.items, l, eo_item2)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item2, item2);
        if (item2->submenu.open) _submenu_hide(item2);
     }
}

static void
_elm_menu_item_elm_widget_item_disable(Eo *eo_item, Elm_Menu_Item_Data *item)
{
   if (elm_object_item_disabled_get((Elm_Object_Item*)eo_item))
     {
        elm_layout_signal_emit(VIEW(item), "elm,state,disabled", "elm");
        if (item->submenu.open) _submenu_hide(item);
     }
   else
     elm_layout_signal_emit(VIEW(item), "elm,state,enabled", "elm");

   if (item->dbus_menu) _elm_dbus_menu_update(item->dbus_menu);
   edje_object_message_signal_process(elm_layout_edje_get(VIEW(item)));
}

static void
_elm_menu_item_elm_widget_item_signal_emit(Eo *eo_item EINA_UNUSED, Elm_Menu_Item_Data *item,
                       const char *emission,
                       const char *source)
{
   elm_layout_signal_emit(VIEW(item), emission, source);
}

static inline void
_parent_geometry_get(Elm_Menu_Data *sd, int *x, int *y, int *w, int *h)
{
   Eina_Rect r;

   r = efl_gfx_geometry_get(sd->parent);
   if (efl_isa(sd->parent, EFL_UI_WIN_CLASS))
     {
        if (sd->menu_bar && efl_canvas_object_is_frame_object_get(sd->obj))
          r.pos = efl_gfx_position_get(sd->obj);
        else
          r.pos = EINA_POSITION2D(0, 0);
     }
   if (x) *x = r.x;
   if (y) *y = r.y;
   if (w) *w = r.w;
   if (h) *h = r.h;
}

static void
_submenu_sizing_eval(Elm_Menu_Item_Data *parent_it)
{
   Eina_List *l;
   Elm_Object_Item *eo_item;
   Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2,
              h2, bx, by, bw, bh, px, py, pw, ph;
   ELM_MENU_DATA_GET_OR_RETURN(WIDGET(parent_it), sd);

   EINA_LIST_FOREACH(parent_it->submenu.items, l, eo_item)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item, item);
        elm_layout_sizing_eval(VIEW(item));
        if (_elm_config->atspi_mode)
          elm_interface_atspi_accessible_state_changed_signal_emit(eo_item, ELM_ATSPI_STATE_SHOWING, EINA_TRUE);
     }


   evas_object_geometry_get
     (parent_it->submenu.location, &x_p, &y_p, &w_p, &h_p);
   evas_object_geometry_get(VIEW(parent_it), &x2, &y2, &w2, &h2);
   evas_object_geometry_get(parent_it->submenu.bx, &bx, &by, &bw, &bh);
   _parent_geometry_get(sd, &px, &py, &pw, &ph);

   if (sd->menu_bar && !parent_it->parent)
     {
        x_p = x2;
        y_p = y2 + h2;
     }
   else
     {
        x_p = x2 + w2;
        y_p = y2;
     }

   /* If it overflows on the right, adjust the x */
   if ((x_p + bw > px + pw) || efl_ui_mirrored_get(WIDGET(parent_it)))
     x_p = x2 - bw;

   /* If it overflows on the left, adjust the x - usually only happens
    * with an RTL interface */
   if (x_p < px)
     x_p = x2 + w2;

   /* If after all the adjustments it still overflows, fix it */
   if (x_p + bw > px + pw)
     x_p = x2 - bw;

   if (y_p + bh > py + ph)
     y_p -= y_p + bh - (py + ph);

   if (sd->menu_bar && (y_p < py))
     y_p = py;

   evas_object_move(parent_it->submenu.location, x_p, y_p);
   evas_object_resize(parent_it->submenu.location, bw, h_p);
   evas_object_size_hint_min_set(parent_it->submenu.location, bw, h_p);
   evas_object_size_hint_max_set(parent_it->submenu.location, bw, h_p);
   elm_hover_target_set(parent_it->submenu.hv, parent_it->submenu.location);

   EINA_LIST_FOREACH(parent_it->submenu.items, l, eo_item)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item, item);
        if (item->submenu.open) _submenu_sizing_eval(item);
     }
}

static void
_sizing_eval(Evas_Object *obj)
{
   Eina_List *l;
   Elm_Object_Item *eo_item;
   Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bw, bh;
   Elm_Widget_Smart_Data *hover;

   ELM_MENU_DATA_GET(obj, sd);

   if (!sd->parent) return;

   EINA_LIST_FOREACH(sd->items, l, eo_item)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item, item);
        elm_layout_sizing_eval(VIEW(item));
     }

   evas_object_geometry_get(sd->location, NULL, NULL, &w_p, &h_p);
   _parent_geometry_get(sd, &x2, &y2, &w2, &h2);
   evas_object_geometry_get(sd->bx, NULL, NULL, &bw, &bh);

   x_p = sd->xloc;
   y_p = sd->yloc;

   if (efl_ui_mirrored_get(obj)) x_p -= w_p;

   if (x_p + bw > x2 + w2) x_p -= x_p + bw - (x2 + w2);
   if (x_p < x2) x_p = x2;

   if (y_p + h_p + bh > y2 + h2) y_p -= y_p + h_p + bh - (y2 + h2);
   if (y_p < y2) y_p = y2;

   efl_gfx_geometry_set(sd->location, EINA_RECT(x_p, y_p, bw, h_p));
   evas_object_size_hint_min_set(sd->location, bw, h_p);
   evas_object_size_hint_max_set(sd->location, bw, h_p);
   elm_hover_target_set(sd->hv, sd->location);

   hover = efl_data_scope_get(sd->hv, ELM_WIDGET_CLASS);
   edje_object_part_geometry_get(hover->resize_obj, "bottom", NULL,
                                 NULL, &bw, &bh);
   evas_object_size_hint_min_set(obj, bw, bh);

   EINA_LIST_FOREACH(sd->items, l, eo_item)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item, item);
        if (item->submenu.open) _submenu_sizing_eval(item);
     }
}

EOLIAN static Efl_Ui_Theme_Apply
_elm_menu_elm_widget_theme_apply(Eo *obj, Elm_Menu_Data *sd)
{
   Efl_Ui_Theme_Apply int_ret = EFL_UI_THEME_APPLY_FAILED;

   Eina_List *l, *_l, *_ll, *ll = NULL;
   Elm_Object_Item *eo_item;
   const char *s;
   char style[1024];

   int_ret = elm_obj_widget_theme_apply(efl_super(obj, MY_CLASS));
   if (!int_ret) return EFL_UI_THEME_APPLY_FAILED;

   if (sd->menu_bar)
      snprintf(style, sizeof(style), "main_menu/%s", elm_widget_style_get(obj));
   else
      snprintf(style, sizeof(style), "menu/%s", elm_widget_style_get(obj));
   elm_object_style_set(sd->hv, style);

   ll = eina_list_append(ll, sd->items);
   EINA_LIST_FOREACH(ll, _ll, l)
     {
        EINA_LIST_FOREACH(l, _l, eo_item)
          {
             ELM_MENU_ITEM_DATA_GET(eo_item, item);
             ll = eina_list_append(ll, item->submenu.items);
             if (item->separator)
               {
                  if (!elm_layout_theme_set(VIEW(item), "menu", "separator",
                                            elm_widget_style_get(obj)))
                    CRI("Failed to set layout!");
               }
             else if (item->submenu.bx)
               {
                  if (sd->menu_bar && !item->parent) s = "main_menu_submenu";
                  else s = "item_with_submenu";

                  if (!elm_layout_theme_set(VIEW(item), "menu", s,
                                            elm_widget_style_get(obj)))
                    CRI("Failed to set layout!");
                  snprintf(style, sizeof(style), "menu/%s", elm_widget_style_get(WIDGET(item)));
                  elm_object_style_set(item->submenu.hv, style);

                  elm_object_item_text_set(eo_item,
                                           item->label);
                  if (item->icon_str)
                    elm_menu_item_icon_name_set(eo_item,
                                                item->icon_str);
               }
             else
               {
                  if (!elm_layout_theme_set(VIEW(item), "menu", "item",
                                            elm_widget_style_get(obj)))
                    CRI("Failed to set layout!");

                  elm_object_item_text_set(eo_item,
                                           item->label);
                  if (item->icon_str)
                    elm_menu_item_icon_name_set(eo_item,
                                                item->icon_str);
               }
             elm_wdg_item_disable(eo_item);
             /* SEOZ
             edje_object_scale_set
               (VIEW(item), efl_ui_scale_get(obj) *
               elm_config_scale_get());
               */
          }
     }

   eina_list_free(ll); //fixme: test

   _sizing_eval(obj);

   return int_ret;
}

EOLIAN static void
_elm_menu_item_elm_widget_item_part_text_set(Eo *eo_item EINA_UNUSED,
                                             Elm_Menu_Item_Data *item,
                                             const char *part,
                                             const char *label)
{
   if (part && strcmp(part, "default")) return;

   eina_stringshare_replace(&item->label, label);

   if (label)
     elm_layout_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
   else
     elm_layout_signal_emit(VIEW(item), "elm,state,text,hidden", "elm");

   edje_object_message_signal_process(elm_layout_edje_get(VIEW(item)));
   elm_layout_text_set(VIEW(item), "elm.text", label);

   _sizing_eval(WIDGET(item));
}

EOLIAN static const char *
_elm_menu_item_elm_widget_item_part_text_get(Eo *eo_item EINA_UNUSED,
                                             Elm_Menu_Item_Data *it,
                                             const char *part)
{
   if (part && strcmp(part, "default")) return NULL;

   return it->label;
}

EOLIAN static void
_elm_menu_item_elm_widget_item_part_content_set(Eo *eo_item EINA_UNUSED,
                                                Elm_Menu_Item_Data *item,
                                                const char *part,
                                                Evas_Object *content)
{
   if (part && strcmp(part, "default")) return;

   if (content == item->content) return;

   evas_object_del(item->content);
   item->content = content;
   if (item->content)
     elm_layout_content_set(VIEW(item), "elm.swallow.content", item->content);

   _sizing_eval(WIDGET(item));
}

EOLIAN static Evas_Object *
_elm_menu_item_elm_widget_item_part_content_get(Eo *eo_item EINA_UNUSED,
                                                Elm_Menu_Item_Data *it,
                                                const char *part)
{
   if (part && strcmp(part, "default")) return NULL;

   return it->content;
}

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

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

static void
_parent_del_cb(void *data,
               Evas *e EINA_UNUSED,
               Evas_Object *obj,
               void *event_info EINA_UNUSED)
{
   ELM_MENU_DATA_GET(data, sd);
   ELM_WIDGET_DATA_GET_OR_RETURN(data, wd);

   evas_object_event_callback_del_full
     (obj, EVAS_CALLBACK_RESIZE, _parent_resize_cb, wd->obj);
   sd->parent = NULL;
}

static void
_item_move_resize_cb(void *data,
                     Evas *e EINA_UNUSED,
                     Evas_Object *obj EINA_UNUSED,
                     void *event_info EINA_UNUSED)
{
   Elm_Menu_Item_Data *item = data;

   if (item->submenu.open) _submenu_sizing_eval(item);
}

static void
_menu_hide(void *data,
           Evas_Object *obj EINA_UNUSED,
           void *event_info EINA_UNUSED)
{
   Eina_List *l;
   Elm_Object_Item *eo_item2;

   ELM_MENU_DATA_GET(data, sd);

   if (!sd->menu_bar)
     {
        evas_object_hide(sd->hv);
        evas_object_hide(data);
     }

   EINA_LIST_FOREACH(sd->items, l, eo_item2)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item2, item2);
        if (item2->submenu.open) _submenu_hide(item2);
     }
}

static void
_hover_dismissed_cb(void *data, const Efl_Event *event)
{
   _menu_hide(data, event->object, event->info);
   efl_event_callback_legacy_call
     (data, EFL_UI_EVENT_CLICKED, NULL);
   efl_event_callback_legacy_call(data, ELM_MENU_EVENT_DISMISSED, NULL);
}

static void
_submenu_open_cb(void *data,
                 Evas_Object *obj EINA_UNUSED,
                 const char *emission EINA_UNUSED,
                 const char *source EINA_UNUSED)
{
   Elm_Menu_Item_Data *item = data;

   item->submenu.open = EINA_TRUE;
   evas_object_show(item->submenu.hv);
   _submenu_sizing_eval(item);
}

void
_elm_dbus_menu_item_select_cb(Elm_Object_Item *obj_item)
{
  ELM_MENU_ITEM_DATA_GET(obj_item, item);
  if (item->func) item->func((void *)(WIDGET_ITEM_DATA_GET(EO_OBJ(item))), WIDGET(item), obj_item);
}

static void
_menu_item_select_cb(void *data,
                     Evas_Object *obj EINA_UNUSED,
                     const char *emission EINA_UNUSED,
                     const char *source EINA_UNUSED)
{
   Elm_Menu_Item_Data *item = data;

   if (item->submenu.items)
     {
        if (!item->submenu.open) _submenu_open_cb(item, NULL, NULL, NULL);
        else _submenu_hide(item);
     }
   else _menu_hide(WIDGET(item), NULL, NULL);

   if (item->func) item->func((void *)(WIDGET_ITEM_DATA_GET(EO_OBJ(item))), WIDGET(item), EO_OBJ(item));
}

static void
_menu_item_activate_cb(void *data,
                       Evas_Object *obj EINA_UNUSED,
                       const char *emission EINA_UNUSED,
                       const char *source EINA_UNUSED)
{
   Eina_List *l;
   Elm_Object_Item *eo_item2;
   Elm_Menu_Item_Data *item = data;

   item->selected = 1;
   if (item->parent)
     {
        EINA_LIST_FOREACH(item->parent->submenu.items, l, eo_item2)
          {
             if (eo_item2 != EO_OBJ(item))
               elm_menu_item_selected_set(eo_item2, 0);
          }
        elm_interface_atspi_accessible_event_emit(ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN, EO_OBJ(item->parent), ELM_INTERFACE_ATSPI_SELECTION_EVENT_SELECTION_CHANGED, NULL);
     }
   else
     {
        Eina_Bool was_open = EINA_FALSE;
        ELM_MENU_DATA_GET(WIDGET(item), sd);
        EINA_LIST_FOREACH(sd->items, l, eo_item2)
          {
             if (eo_item2 != EO_OBJ(item))
               {
                  ELM_MENU_ITEM_DATA_GET(eo_item2, item2);
                  was_open |= item2->submenu.open;
                  elm_menu_item_selected_set(eo_item2, 0);
               }
          }
        elm_interface_atspi_accessible_event_emit(ELM_INTERFACE_ATSPI_ACCESSIBLE_MIXIN, WIDGET(item), ELM_INTERFACE_ATSPI_SELECTION_EVENT_SELECTION_CHANGED, NULL);
        if (sd->menu_bar && was_open)
          _menu_item_select_cb(item, NULL, NULL, NULL);
     }
   if (_elm_config->atspi_mode)
     elm_interface_atspi_accessible_state_changed_signal_emit(EO_OBJ(item), ELM_ATSPI_STATE_SELECTED, EINA_TRUE);
}

static void
_menu_item_inactivate_cb(void *data,
                         Evas_Object *obj EINA_UNUSED,
                         const char *emission EINA_UNUSED,
                         const char *source EINA_UNUSED)
{
   Elm_Menu_Item_Data *item = data;

   item->selected = 0;
   if (item->submenu.open) _submenu_hide(item);
   if (_elm_config->atspi_mode)
     elm_interface_atspi_accessible_state_changed_signal_emit(EO_OBJ(item), ELM_ATSPI_STATE_SELECTED, EINA_FALSE);
}

static void
_block_menu(void *_sd, const Efl_Event *event EINA_UNUSED)
{
   const Eina_List *l;
   Elm_Object_Item *eo_current;
   Elm_Menu_Data *sd = _sd;
   Eina_List *items = sd->items;
   EINA_LIST_FOREACH(items, l, eo_current)
     {
        ELM_MENU_ITEM_DATA_GET(eo_current, current);
        if (!current->blocked) current->was_enabled = !elm_wdg_item_disabled_get(eo_current);
        current->blocked = EINA_TRUE;
        elm_object_item_disabled_set(eo_current, EINA_TRUE);
     }
}

static void
_unblock_menu(void *_sd, const Efl_Event *event EINA_UNUSED)
{
   const Eina_List *l;
   Elm_Object_Item *eo_current;
   Elm_Menu_Data *sd = _sd;
   Eina_List *items = sd->items;
   EINA_LIST_FOREACH(items, l, eo_current)
     {
        ELM_MENU_ITEM_DATA_GET(eo_current, current);
        elm_object_item_disabled_set(eo_current, !current->was_enabled);
        current->blocked = EINA_FALSE;
     }
}

EOLIAN static void
_elm_menu_efl_gfx_visible_set(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd, Eina_Bool vis)
{
   if (_evas_object_intercept_call(obj, EVAS_OBJECT_INTERCEPT_CB_VISIBLE, 0, vis))
     return;

   efl_gfx_visible_set(efl_super(obj, MY_CLASS), vis);
   if (vis) efl_gfx_visible_set(sd->hv, EINA_TRUE);
}

static void
_item_obj_create(Elm_Menu_Item_Data *item)
{
   VIEW(item) = elm_layout_add(WIDGET(item));
   elm_interface_atspi_accessible_type_set(VIEW(item), ELM_ATSPI_TYPE_SKIPPED);
   evas_object_size_hint_weight_set
     (VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_fill_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
   if (!elm_layout_theme_set(VIEW(item), "menu", "item",
                        elm_widget_style_get(WIDGET(item))))
     CRI("Failed to set layout!");
   else
     {
        elm_layout_signal_callback_add(VIEW(item), "elm,action,click", "*",
                                       _menu_item_select_cb, item);
        elm_layout_signal_callback_add(VIEW(item), "elm,action,activate", "*",
                                       _menu_item_activate_cb, item);
        elm_layout_signal_callback_add(VIEW(item), "elm,action,inactivate", "*",
                                       _menu_item_inactivate_cb,
                                       item);
        evas_object_show(VIEW(item));
     }
}

static void
_item_separator_obj_create(Elm_Menu_Item_Data *item)
{
   VIEW(item) = elm_layout_add(WIDGET(item));
   elm_interface_atspi_accessible_type_set(VIEW(item), ELM_ATSPI_TYPE_SKIPPED);
   evas_object_size_hint_weight_set
     (VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_fill_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
   if (!elm_layout_theme_set(VIEW(item), "menu", "separator",
                             elm_widget_style_get(WIDGET(item))))
     CRI("Failed to set layout!");
   else
     {
        elm_layout_signal_callback_add
           (VIEW(item), "elm,action,activate", "*", _menu_item_activate_cb, item);
        evas_object_show(VIEW(item));
     }
}

static void
_item_submenu_obj_create(Elm_Menu_Item_Data *item)
{
   ELM_MENU_DATA_GET(WIDGET(item), sd);
   Evas_Object *hv, *bx;
   char style[1024];

   item->submenu.location = elm_icon_add(sd->bx);
   elm_interface_atspi_accessible_type_set(item->submenu.location, ELM_ATSPI_TYPE_DISABLED);
   item->submenu.hv = hv = elm_hover_add(sd->bx);
   elm_interface_atspi_accessible_type_set(item->submenu.hv, ELM_ATSPI_TYPE_SKIPPED);
   efl_ui_mirrored_set(hv, EINA_FALSE);
   elm_hover_target_set(hv, item->submenu.location);
   elm_hover_parent_set(hv, sd->parent);

   if (sd->menu_bar && !item->parent)
     {
        snprintf(style, sizeof(style), "main_menu_submenu/%s", elm_widget_style_get(WIDGET(item)));
        elm_object_style_set(hv, style);
        efl_event_callback_add
          (hv, ELM_HOVER_EVENT_DISMISSED, _hover_dismissed_cb, WIDGET(item));
     }
   else
     {
        snprintf(style, sizeof(style), "submenu/%s", elm_widget_style_get(WIDGET(item)));
        elm_object_style_set(hv, style);
     }

   item->submenu.bx = bx = elm_box_add(sd->bx);
   efl_ui_mirrored_set(bx, EINA_FALSE);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_show(bx);
   elm_object_part_content_set
      (hv, elm_hover_best_content_location_get
       (hv, ELM_HOVER_AXIS_VERTICAL), bx);

   if (sd->menu_bar && !item->parent)
     {
        if (!elm_layout_theme_set(VIEW(item), "menu",
                                  "main_menu_submenu",
                                  elm_widget_style_get(WIDGET(item))))
          CRI("Failed to set layout!");
     }
   else
     {
        if (!elm_layout_theme_set(VIEW(item), "menu",
                                  "item_with_submenu",
                                  elm_widget_style_get(WIDGET(item))))
          CRI("Failed to set layout!");
     }

   elm_object_item_text_set(EO_OBJ(item), item->label);

   if (item->icon_str)
     elm_menu_item_icon_name_set(EO_OBJ(item), item->icon_str);

   elm_layout_signal_callback_add(VIEW(item), "elm,action,open", "*",
                                   _submenu_open_cb, item);
   evas_object_event_callback_add
     (VIEW(item), EVAS_CALLBACK_MOVE, _item_move_resize_cb, item);
   evas_object_event_callback_add
     (VIEW(item), EVAS_CALLBACK_RESIZE, _item_move_resize_cb, item);

   evas_object_event_callback_add(bx, EVAS_CALLBACK_RESIZE,
                                  _menu_resize_cb, WIDGET(item));
}

EOLIAN static void
_elm_menu_efl_canvas_group_group_add(Eo *obj, Elm_Menu_Data *priv)
{
   efl_canvas_group_add(efl_super(obj, MY_CLASS));
   elm_widget_sub_object_parent_add(obj);

   elm_widget_can_focus_set(obj, EINA_FALSE);

   priv->location = elm_icon_add(obj);
   elm_interface_atspi_accessible_type_set(priv->location, ELM_ATSPI_TYPE_DISABLED);

   priv->hv = elm_hover_add(obj);
   elm_interface_atspi_accessible_type_set(priv->hv, ELM_ATSPI_TYPE_SKIPPED);
   efl_ui_mirrored_set(priv->hv, EINA_FALSE);

   elm_object_style_set(priv->hv, "menu/default");
   efl_event_callback_add
     (priv->hv, ELM_HOVER_EVENT_DISMISSED, _hover_dismissed_cb, obj);

   priv->bx = elm_box_add(obj);
   elm_interface_atspi_accessible_type_set(priv->bx, ELM_ATSPI_TYPE_SKIPPED);
   efl_ui_mirrored_set(priv->bx, EINA_FALSE);
   evas_object_size_hint_weight_set
     (priv->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

   evas_object_event_callback_add
     (priv->bx, EVAS_CALLBACK_RESIZE, _menu_resize_cb, obj);
}

EOLIAN static void
_elm_menu_efl_canvas_group_group_del(Eo *obj, Elm_Menu_Data *sd)
{
   Elm_Object_Item *eo_item;

   _elm_dbus_menu_unregister(obj);

   if (sd->parent)
     {
        evas_object_event_callback_del_full
           (sd->parent, EVAS_CALLBACK_RESIZE, _parent_resize_cb, obj);
        evas_object_event_callback_del_full
           (sd->parent, EVAS_CALLBACK_DEL, _parent_del_cb, obj);
     }

   EINA_LIST_FREE(sd->items, eo_item)
     _item_del(eo_item);

   evas_object_event_callback_del_full
      (sd->bx, EVAS_CALLBACK_RESIZE, _menu_resize_cb, obj);

   evas_object_del(sd->hv);
   evas_object_del(sd->location);

   efl_canvas_group_del(efl_super(obj, MY_CLASS));
}

void
_elm_menu_menu_bar_hide(Eo *obj)
{
  ELM_MENU_DATA_GET_OR_RETURN(obj, sd);

  evas_object_hide(sd->hv);
  evas_object_hide(obj);
  _menu_hide(obj, NULL, NULL);
}

void
_elm_menu_menu_bar_set(Eo *obj, Eina_Bool menu_bar)
{
   Eina_List *l;
   Elm_Object_Item *eo_item;
   char style[1024];

   ELM_MENU_DATA_GET_OR_RETURN(obj, sd);

   if (menu_bar == sd->menu_bar) return;

   elm_box_horizontal_set(sd->bx, menu_bar);
   elm_box_homogeneous_set(sd->bx, !menu_bar);
   sd->menu_bar = menu_bar;

   if (sd->menu_bar)
     snprintf(style, sizeof(style), "main_menu/%s", elm_widget_style_get(obj));
   else
     snprintf(style, sizeof(style), "menu/%s", elm_widget_style_get(obj));
   elm_object_style_set(sd->hv, style);

   EINA_LIST_FOREACH(sd->items, l, eo_item)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item, item);
        if (!item->submenu.bx) continue;

        if (menu_bar)
          {
             efl_event_callback_add
               (item->submenu.hv, EFL_UI_EVENT_CLICKED, _hover_dismissed_cb, WIDGET(item));
             snprintf(style, sizeof(style), "main_menu_submenu//%s", elm_widget_style_get(obj));
             elm_object_style_set(item->submenu.hv, style);
          }
        else
          {
             efl_event_callback_del(item->submenu.hv, EFL_UI_EVENT_CLICKED, _hover_dismissed_cb, WIDGET(item));
             snprintf(style, sizeof(style), "submenu/%s", elm_widget_style_get(obj));
             elm_object_style_set(item->submenu.hv, style);
          }
     }

   elm_obj_widget_theme_apply(obj);
}

EAPI Evas_Object *
elm_menu_add(Evas_Object *parent)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
   return efl_add(MY_CLASS, parent, efl_canvas_object_legacy_ctor(efl_added));
}

EOLIAN static Efl_Ui_Focus_Manager*
_elm_menu_elm_widget_focus_manager_create(Eo *obj EINA_UNUSED, Elm_Menu_Data *pd EINA_UNUSED, Efl_Ui_Focus_Object *root)
{
   Efl_Ui_Focus_Manager *manager;

   manager = efl_add(EFL_UI_FOCUS_MANAGER_CALC_CLASS, obj,
     efl_ui_focus_manager_root_set(efl_added, root)
   );

   return manager;
}

EOLIAN static Eo *
_elm_menu_efl_object_constructor(Eo *obj, Elm_Menu_Data *sd)
{
   Eo *parent = NULL;
   Efl_Ui_Focus_Manager *manager;

   manager = elm_obj_widget_focus_manager_create(obj, obj);
   efl_composite_attach(obj, manager);
   _efl_ui_focus_manager_redirect_events_add(manager, obj);

   obj = efl_constructor(efl_super(obj, MY_CLASS));
   efl_canvas_object_type_set(obj, MY_CLASS_NAME_LEGACY);
   evas_object_smart_callbacks_descriptions_set(obj, _smart_callbacks);
   parent = efl_parent_get(obj);
   elm_interface_atspi_accessible_role_set(obj, ELM_ATSPI_ROLE_MENU);

   elm_menu_parent_set(obj, parent);
   elm_hover_target_set(sd->hv, sd->location);
   elm_layout_content_set
     (sd->hv, elm_hover_best_content_location_get
       (sd->hv, ELM_HOVER_AXIS_VERTICAL), sd->bx);

   _sizing_eval(obj);
   efl_event_callback_add
     (obj, ELM_MENU_EVENT_ELM_ACTION_BLOCK_MENU, _block_menu, sd);
   efl_event_callback_add
     (obj, ELM_MENU_EVENT_ELM_ACTION_UNBLOCK_MENU, _unblock_menu, sd);

   sd->obj = obj;
   return obj;
}

EOLIAN static void
_elm_menu_efl_object_destructor(Eo *obj, Elm_Menu_Data *sd)
{
   Eina_List *itr, *itr2;
   Elm_Object_Item *eo_item;
   EINA_LIST_FOREACH_SAFE(sd->items, itr, itr2, eo_item)
     elm_wdg_item_del(eo_item);

   efl_destructor(efl_super(obj, MY_CLASS));
}

EAPI void
elm_menu_parent_set(Evas_Object *obj,
                    Evas_Object *parent)
{
   ELM_MENU_CHECK(obj);
   elm_obj_widget_parent_set(obj, parent);
}

EOLIAN static void
_elm_menu_elm_widget_widget_parent_set(Eo *obj, Elm_Menu_Data *sd, Evas_Object *parent)
{
   Eina_List *l, *_l, *_ll, *ll = NULL;
   Elm_Object_Item *eo_item;

   if (sd->parent == parent) return;
   if (sd->parent)
     {
        evas_object_event_callback_del_full
          (sd->parent, EVAS_CALLBACK_RESIZE, _parent_resize_cb, obj);
        evas_object_event_callback_del_full
          (sd->parent, EVAS_CALLBACK_DEL, _parent_del_cb, obj);
     }
   sd->parent = parent;
   if (sd->parent)
     {
        evas_object_event_callback_add
          (sd->parent, EVAS_CALLBACK_RESIZE, _parent_resize_cb, obj);
        evas_object_event_callback_add
          (sd->parent, EVAS_CALLBACK_DEL, _parent_del_cb, obj);
     }
   elm_hover_parent_set(sd->hv, parent);

   ll = eina_list_append(ll, sd->items);
   EINA_LIST_FOREACH(ll, _ll, l)
     {
        EINA_LIST_FOREACH(l, _l, eo_item)
          {
             ELM_MENU_ITEM_DATA_GET(eo_item, item);
             if (item->submenu.hv)
               {
                  elm_hover_parent_set(item->submenu.hv, parent);
                  ll = eina_list_append(ll, item->submenu.items);
               }
          }
     }

   eina_list_free(ll);

   _sizing_eval(obj);
}

EAPI Evas_Object *
elm_menu_parent_get(const Evas_Object *obj)
{
   ELM_MENU_CHECK(obj) NULL;
   return elm_obj_widget_parent_get(obj);
}

EAPI Elm_Widget_Item *
elm_menu_selected_item_get(const Evas_Object *obj)
{
   return efl_ui_menu_selected_item_get(obj);
}

EAPI const Eina_List *
elm_menu_items_get(const Evas_Object *obj)
{
   Eina_List *lst = NULL;
   Eina_Iterator *it;
   void *item_data;

   it = efl_ui_menu_items_get(obj);
   EINA_ITERATOR_FOREACH(it, item_data)
     {
        lst = eina_list_append(lst, item_data);
     }
   eina_iterator_free(it);
   return lst;
}

EAPI Elm_Widget_Item *
elm_menu_first_item_get(const Evas_Object *obj)
{
   return efl_ui_menu_first_item_get(obj);
}

EAPI Elm_Widget_Item *
elm_menu_last_item_get(const Evas_Object *obj)
{
   return efl_ui_menu_last_item_get(obj);
}

EAPI void
elm_menu_item_selected_set(Evas_Object *obj, Eina_Bool selected)
{
   efl_ui_item_selected_set(obj, selected);
}

EAPI Eina_Bool
elm_menu_item_selected_get(const Evas_Object *obj)
{
   return efl_ui_item_selected_get(obj);
}

EAPI Elm_Widget_Item *
elm_menu_item_prev_get(const Evas_Object *obj)
{
   return efl_ui_item_prev_get(obj);
}

EAPI Elm_Widget_Item *
elm_menu_item_next_get(const Evas_Object *obj)
{
   return efl_ui_item_next_get(obj);
}

EOLIAN static Evas_Object*
_elm_menu_elm_widget_widget_parent_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   return sd->parent;
}

EOLIAN static void
_elm_menu_move(Eo *obj, Elm_Menu_Data *sd, Evas_Coord x, Evas_Coord y)
{
   sd->xloc = x;
   sd->yloc = y;
   _sizing_eval(obj);
}

EOLIAN static void
_elm_menu_open(Eo *obj, Elm_Menu_Data *sd EINA_UNUSED)
{
   evas_object_show(obj);
}

EOLIAN static void
_elm_menu_close(Eo *obj, Elm_Menu_Data *sd)
{
   _menu_hide(obj, sd->hv, NULL);
}

EOLIAN static Evas_Object *
_elm_menu_item_object_get(const Eo *eo_it EINA_UNUSED, Elm_Menu_Item_Data *it)
{
   return VIEW(it);
}

static void
_item_clone(Evas_Object *obj,
            Elm_Object_Item *parent,
            Elm_Object_Item *eo_item)
{
   Elm_Object_Item *new_item;
   Elm_Object_Item *subitem;
   Eina_List *iter;

   ELM_MENU_ITEM_DATA_GET(eo_item, item);
   if (item->separator)
     new_item = elm_menu_item_separator_add(obj, parent);
   else
     new_item = elm_menu_item_add(obj,
                                  parent,
                                  item->icon_str,
                                  item->label,
                                  item->func,
                                  WIDGET_ITEM_DATA_GET(EO_OBJ(item)));

   Eina_Bool disabled;
   disabled = elm_wdg_item_disabled_get(eo_item);
   elm_wdg_item_disabled_set(new_item, disabled);

   EINA_LIST_FOREACH(item->submenu.items, iter, subitem)
     _item_clone(obj, new_item, subitem);
}

void
elm_menu_clone(Evas_Object *from_menu,
               Evas_Object *to_menu,
               Elm_Object_Item *parent)
{
   Eina_List *iter;
   Elm_Object_Item *eo_item;

   ELM_MENU_CHECK(from_menu);
   ELM_MENU_CHECK(to_menu);

   ELM_MENU_DATA_GET_OR_RETURN(from_menu, from_sd);

   EINA_LIST_FOREACH(from_sd->items, iter, eo_item)
     _item_clone(to_menu, parent, eo_item);
}

static void
_elm_menu_item_add_helper(Evas_Object *obj,
                          Elm_Menu_Item_Data *parent,
                          Elm_Menu_Item_Data *subitem,
                          Elm_Menu_Data *sd)
{
   if (parent)
     {
        if (!parent->submenu.bx) _item_submenu_obj_create(parent);
        elm_box_pack_end(parent->submenu.bx, VIEW(subitem));
        parent->submenu.items =
          eina_list_append(parent->submenu.items, EO_OBJ(subitem));
        subitem->idx = eina_list_count(parent->submenu.items) - 1;
     }
   else
     {
        elm_box_pack_end(sd->bx, VIEW(subitem));
        sd->items = eina_list_append(sd->items, EO_OBJ(subitem));
        subitem->idx = eina_list_count(sd->items) - 1;
     }

   _sizing_eval(obj);
}

EOLIAN static void
_elm_menu_item_efl_object_destructor(Eo *eo_item, Elm_Menu_Item_Data *item)
{
   ELM_MENU_DATA_GET(WIDGET(item), sd);

   elm_menu_item_subitems_clear(eo_item);
   eina_stringshare_del(item->label);
   eina_stringshare_del(item->icon_str);
   evas_object_del(item->content);
   evas_object_del(item->submenu.hv);
   evas_object_del(item->submenu.location);

   if (item->parent)
     item->parent->submenu.items =
       eina_list_remove(item->parent->submenu.items, eo_item);
   else
     sd->items = eina_list_remove(sd->items, eo_item);

   if (sd->dbus_menu)
     _elm_dbus_menu_item_delete(sd->dbus_menu, item->dbus_idx);

   efl_destructor(efl_super(eo_item, ELM_MENU_ITEM_CLASS));
}

EOLIAN static Eo *
_elm_menu_item_efl_object_constructor(Eo *eo_item, Elm_Menu_Item_Data *item)
{
   eo_item = efl_constructor(efl_super(eo_item, ELM_MENU_ITEM_CLASS));
   item->base = efl_data_scope_get(eo_item, ELM_WIDGET_ITEM_CLASS);

   return eo_item;
}

EOLIAN static Elm_Object_Item*
_elm_menu_item_add(Eo *obj, Elm_Menu_Data *sd, Elm_Object_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
{
   Elm_Object_Item *eo_item;
   Evas_Object *icon_obj;

   icon_obj = elm_icon_add(obj);
   elm_interface_atspi_accessible_type_set(icon_obj, ELM_ATSPI_TYPE_DISABLED);
   if (!icon_obj) return NULL;

   eo_item = efl_add(ELM_MENU_ITEM_CLASS, obj);
   if (!eo_item)
     {
        evas_object_del(icon_obj);
        return NULL;
     }

   ELM_MENU_ITEM_DATA_GET(eo_item, it);

   WIDGET_ITEM_DATA_SET(eo_item, data);
   it->func = func;
   it->parent = efl_data_scope_get(parent, ELM_MENU_ITEM_CLASS);
   it->content = icon_obj;

   _item_obj_create(it);
   efl_canvas_object_is_frame_object_set(VIEW(it), efl_canvas_object_is_frame_object_get(obj));
   efl_canvas_object_is_frame_object_set(icon_obj, efl_canvas_object_is_frame_object_get(obj));
   elm_object_item_text_set(eo_item, label);

   elm_layout_content_set(VIEW(it), "elm.swallow.content",
                          it->content);

   if (icon) elm_menu_item_icon_name_set(eo_item, icon);

   _elm_menu_item_add_helper(obj, it->parent, it, sd);

   if (sd->dbus_menu)
   {
     it->dbus_idx = _elm_dbus_menu_item_add(sd->dbus_menu, eo_item);
     it->dbus_menu = sd->dbus_menu;
   }
   if (_elm_config->atspi_mode)
     {
        elm_interface_atspi_accessible_added(eo_item);
        elm_interface_atspi_accessible_children_changed_added_signal_emit(parent ? parent : obj, eo_item);
     }

   return eo_item;
}

EOLIAN static unsigned int
_elm_menu_item_index_get(const Eo *eo_it EINA_UNUSED, Elm_Menu_Item_Data *it)
{
   return it->idx;
}

EOLIAN static void
_elm_menu_item_icon_name_set(Eo *eo_item EINA_UNUSED,
                             Elm_Menu_Item_Data *item,
                             const char *icon)
{
   char icon_tmp[512];

   EINA_SAFETY_ON_NULL_RETURN(icon);

   if ((icon[0] != '\0') &&
       (snprintf(icon_tmp, sizeof(icon_tmp), "menu/%s", icon) > 0) &&
       (elm_icon_standard_set(item->content, icon_tmp) ||
        elm_icon_standard_set(item->content, icon)))
     {
        eina_stringshare_replace(&item->icon_str, icon);
        elm_layout_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
     }
   else
     elm_layout_signal_emit(VIEW(item), "elm,state,icon,hidden", "elm");

   edje_object_message_signal_process(elm_layout_edje_get(VIEW(item)));
   _sizing_eval(WIDGET(item));
}

EOLIAN static Elm_Object_Item*
_elm_menu_item_separator_add(Eo *obj, Elm_Menu_Data *sd, Elm_Object_Item *eo_p_item)
{
   Elm_Object_Item *eo_subitem;

   ELM_MENU_ITEM_DATA_GET(eo_p_item, p_item);
   /* don't add a separator as the first item */
   if (!sd->items) return NULL;

   /* don't allow adding more than one separator in a row */
   if (eo_p_item)
     {
        if (!p_item->submenu.items) return NULL;
        eo_subitem = eina_list_last(p_item->submenu.items)->data;
     }
   else eo_subitem = eina_list_last(sd->items)->data;

   ELM_MENU_ITEM_DATA_GET(eo_subitem, subitem);
   if (subitem->separator) return NULL;

   eo_subitem = efl_add(ELM_MENU_ITEM_CLASS, obj);
   if (!eo_subitem) return NULL;

   subitem = efl_data_scope_get(eo_subitem, ELM_MENU_ITEM_CLASS);

   subitem->separator = EINA_TRUE;
   _item_separator_obj_create(subitem);
   if (!eo_p_item)
     {
        elm_box_pack_end(sd->bx, VIEW(subitem));
        sd->items = eina_list_append(sd->items, eo_subitem);
     }
   else
     {
        if (!p_item->submenu.bx) _item_submenu_obj_create(p_item);
        elm_box_pack_end(p_item->submenu.bx, VIEW(subitem));
        p_item->submenu.items = eina_list_append
            (p_item->submenu.items, eo_subitem);
     }

   _sizing_eval(obj);

   if (sd->dbus_menu)
     subitem->dbus_idx = _elm_dbus_menu_item_add(sd->dbus_menu,
                                                 eo_subitem);
   return eo_subitem;
}

EOLIAN static const char *
_elm_menu_item_icon_name_get(Eo *eo_item EINA_UNUSED, Elm_Menu_Item_Data *item)
{
   return item->icon_str;
}

EOLIAN static Eina_Bool
_elm_menu_item_is_separator(const Eo *eo_item EINA_UNUSED, Elm_Menu_Item_Data *item)
{
   return item->separator;
}

EOLIAN static const Eina_List *
_elm_menu_item_subitems_get(const Eo *eo_item EINA_UNUSED, Elm_Menu_Item_Data *item)
{
   return item->submenu.items;
}

EOLIAN static void
_elm_menu_item_subitems_clear(Eo *eo_item EINA_UNUSED, Elm_Menu_Item_Data *it)
{
   Elm_Object_Item *sub_it;
   Eina_List *l, *l_next;

   EINA_LIST_FOREACH_SAFE(it->submenu.items,
                          l, l_next, sub_it)
     elm_wdg_item_del(sub_it);
}

EOLIAN static Eina_Iterator*
_elm_menu_efl_ui_menu_items_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   return eina_list_iterator_new(sd->items);
}

EOLIAN static void
_elm_menu_item_efl_ui_item_selected_set(Eo *eo_item EINA_UNUSED,
                            Elm_Menu_Item_Data *item,
                            Eina_Bool selected)
{
   if (selected == item->selected) return;
   item->selected = selected;
   if (selected)
     {
        elm_layout_signal_emit(VIEW(item), "elm,state,selected", "elm");
        _menu_item_activate_cb(item, NULL, NULL, NULL);
     }
   else
     {
        elm_layout_signal_emit(VIEW(item), "elm,state,unselected", "elm");
        _menu_item_inactivate_cb(item, NULL, NULL, NULL);
     }
   edje_object_message_signal_process(elm_layout_edje_get(VIEW(item)));
}

EOLIAN static Eina_Bool
_elm_menu_item_efl_ui_item_selected_get(Eo *eo_item EINA_UNUSED, Elm_Menu_Item_Data *item)
{
   return item->selected;
}

EOLIAN static Elm_Object_Item *
_elm_menu_item_efl_ui_item_prev_get(Eo *eo_item, Elm_Menu_Item_Data *item)
{
   if (item->parent)
     {
        Eina_List *l = eina_list_data_find_list
            (item->parent->submenu.items, eo_item);
        l = eina_list_prev(l);
        if (!l) return NULL;
        return l->data;
     }
   else
     {
        ELM_MENU_DATA_GET(WIDGET(item), sd);
        if (!sd || !sd->items) return NULL;
        Eina_List *l = eina_list_data_find_list(sd->items, eo_item);
        l = eina_list_prev(l);
        if (!l) return NULL;
        return l->data;
     }

   return NULL;
}

EOLIAN static Elm_Object_Item *
_elm_menu_item_efl_ui_item_next_get(Eo *eo_item, Elm_Menu_Item_Data *item)
{
   if (item->parent)
     {
        Eina_List *l =
          eina_list_data_find_list(item->parent->submenu.items, eo_item);
        l = eina_list_next(l);
        if (!l) return NULL;
        return l->data;
     }
   else
     {
        ELM_MENU_DATA_GET(WIDGET(item), sd);
        if (!sd || !sd->items) return NULL;
        Eina_List *l = eina_list_data_find_list(sd->items, eo_item);
        l = eina_list_next(l);
        if (!l) return NULL;
        return l->data;
     }

   return NULL;
}

EOLIAN static Elm_Object_Item*
_elm_menu_efl_ui_menu_first_item_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   return (sd->items ? sd->items->data : NULL);
}

EOLIAN static Elm_Object_Item*
_elm_menu_efl_ui_menu_last_item_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   Eina_List *l = eina_list_last(sd->items);
   return (l ? l->data : NULL);
}

EOLIAN static Elm_Object_Item*
_elm_menu_efl_ui_menu_selected_item_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   Eina_List *l;
   Elm_Object_Item *eo_item;

   EINA_LIST_FOREACH(sd->items, l, eo_item)
     {
        ELM_MENU_ITEM_DATA_GET(eo_item, item);
        if (item->selected) return eo_item;
     }

   return NULL;
}

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

EOLIAN static Eina_List*
_elm_menu_elm_interface_atspi_accessible_children_get(Eo *obj, Elm_Menu_Data *sd)
{
   Eina_List *ret;
   ret = elm_interface_atspi_accessible_children_get(efl_super(obj, ELM_MENU_CLASS));
   return eina_list_merge(eina_list_clone(sd->items), ret);
}

EOLIAN static Eina_List*
_elm_menu_item_elm_interface_atspi_accessible_children_get(Eo *obj EINA_UNUSED, Elm_Menu_Item_Data *sd)
{
   return eina_list_clone(sd->submenu.items);
}

EOLIAN static Elm_Interface_Atspi_Accessible*
_elm_menu_item_elm_interface_atspi_accessible_parent_get(Eo *obj EINA_UNUSED, Elm_Menu_Item_Data *sd)
{
   return sd->parent ? EO_OBJ(sd->parent) : WIDGET(sd);
}

EOLIAN static Elm_Atspi_Role
_elm_menu_item_elm_interface_atspi_accessible_role_get(Eo *obj EINA_UNUSED, Elm_Menu_Item_Data *sd)
{
   return sd->submenu.items ? ELM_ATSPI_ROLE_MENU : ELM_ATSPI_ROLE_MENU_ITEM;
}

EOLIAN static const char*
_elm_menu_item_elm_interface_atspi_accessible_name_get(Eo *obj, Elm_Menu_Item_Data *sd)
{
   const char *ret;
   ret = elm_interface_atspi_accessible_name_get(efl_super(obj, ELM_MENU_ITEM_CLASS));
   if (ret) return ret;
   return sd->label;
}

EOLIAN static Elm_Atspi_State_Set
_elm_menu_item_elm_interface_atspi_accessible_state_set_get(Eo *obj EINA_UNUSED, Elm_Menu_Item_Data *sd)
{
   Elm_Atspi_State_Set ret;
   ret = elm_interface_atspi_accessible_state_set_get(efl_super(obj, ELM_MENU_ITEM_CLASS));

   STATE_TYPE_SET(ret, ELM_ATSPI_STATE_SELECTABLE);

   if (sd->selected)
      STATE_TYPE_SET(ret, ELM_ATSPI_STATE_SELECTED);

   return ret;
}

EOLIAN static int
_elm_menu_item_elm_interface_atspi_selection_selected_children_count_get(Eo *obj EINA_UNUSED, Elm_Menu_Item_Data *sd)
{
   int ret = 0;
   Elm_Object_Item *sobj = NULL;
   Eina_List *l;

   EINA_LIST_FOREACH(sd->submenu.items, l, sobj)
     {
        if (!sobj) continue;
        ELM_MENU_ITEM_DATA_GET(sobj, item);
        if (item && item->selected) ret++;
     }

   return ret;
}

EOLIAN static Eo*
_elm_menu_item_elm_interface_atspi_selection_selected_child_get(Eo *obj EINA_UNUSED, Elm_Menu_Item_Data *sd, int child)
{
   int seq = 0;
   Elm_Object_Item *sobj = NULL;
   Eina_List *l;

   EINA_LIST_FOREACH(sd->submenu.items, l, sobj)
     {
        if (!sobj) continue;
        ELM_MENU_ITEM_DATA_GET(sobj, item);

        if (item && item->selected)
          {
             if (child == seq++)
               break;
          }
     }

   return sobj;
}

EOLIAN static int
_elm_menu_elm_interface_atspi_selection_selected_children_count_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
   Elm_Object_Item *sobj = NULL;
   Eina_List *l;
   int ret = 0;

   EINA_LIST_FOREACH(sd->items, l, sobj)
     {
        ELM_MENU_ITEM_DATA_GET(sobj, item);
        if (item && item->selected) ret++;
     }

   return ret;
}

EOLIAN static Eo*
_elm_menu_elm_interface_atspi_selection_selected_child_get(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd, int child)
{
   int seq = 0;
   Elm_Object_Item *sobj = NULL;
   Eina_List *l;

   EINA_LIST_FOREACH(sd->items, l, sobj)
     {
        if (!sobj) continue;
        ELM_MENU_ITEM_DATA_GET(sobj, item);

        if (item && item->selected)
          {
             if (child == seq++)
               break;
          }
     }

   return sobj;

}

/* Internal EO APIs and hidden overrides */

#define ELM_MENU_EXTRA_OPS \
   EFL_CANVAS_GROUP_ADD_DEL_OPS(elm_menu)

#include "elm_menu_item.eo.c"
#include "elm_menu.eo.c"