aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/elementary/test_popup.c
blob: 3a1671857146cb27311864eb767147495dd651e0 (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
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
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_UI_POPUP_ANCHOR_BETA
#include <Elementary.h>

#define POPUP_POINT_MAX 8

typedef struct
{
   double x;
   double y;
} Evas_Rel_Coord_Point;

static Evas_Object *g_popup = NULL;
static int times = 0;
static Eina_Bool is_popup_scroll;
static Evas_Rel_Coord_Point _popup_point[POPUP_POINT_MAX] =
{
   { 0.01, 0.01 },
   { 0.2, 0.2 },
   { 0.5, 0.5 },
   { 0.99, 0.01 },
   { 0.01, 0.99 },
   { 0.99, 0.99 },
   { 0.0, 0.0 },
   { 1.5, 1.5 }
};

static void
_response_cb(void *data EINA_UNUSED, Evas_Object *obj,
             void *event_info EINA_UNUSED)
{
   evas_object_del(obj);
}

static void
_popup_close_cb(void *data, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   evas_object_del(data);
}

static void
_popup_dismiss_btn_cb(void *data, Evas_Object *obj EINA_UNUSED,
                      void *event_info EINA_UNUSED)
{
   elm_popup_dismiss(data);
}

static void
_popup_align_cb(void *data, Evas_Object *obj EINA_UNUSED,
               void *event_info EINA_UNUSED)
{
   static int k = 0;
   double h = -1, v = -1;

   elm_popup_align_set(data, _popup_point[k].x, _popup_point[k].y);
   elm_popup_align_get(data, &h, &v);

   printf("elm_popup_align_get :: Aligned: %lf %lf\n", h, v);

   k++;
   if (k >= POPUP_POINT_MAX)
     k = 0;
}

static void
_g_popup_response_cb(void *data, Evas_Object *obj EINA_UNUSED,
             void *event_info EINA_UNUSED)
{
   evas_object_hide(data);
}

static void
_restack_block_clicked_cb(void *data EINA_UNUSED, Evas_Object *obj,
                          void *event_info EINA_UNUSED)
{
   // remove restacked image if there is any
   Evas_Object *popup_data = evas_object_data_get(obj, "im");
   if (popup_data) evas_object_del(popup_data);
   evas_object_del(obj);
}

static void
_restack_popup_close_cb(void *data, Evas_Object *obj EINA_UNUSED,
                        void *event_info EINA_UNUSED)
{
   Evas_Object *popup_data = evas_object_data_get(data, "im");
   if (popup_data) evas_object_del(popup_data);
   evas_object_del(data);
}

static void
_block_clicked_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   if (data)
     evas_object_del(data);
   evas_object_del(obj);
}

static void
_item_selected_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                  void *event_info)
{
   printf("popup item selected: %s\n", elm_object_item_text_get(event_info));
}

static void
_list_click(void *data EINA_UNUSED, Evas_Object *obj,
            void *event_info EINA_UNUSED)
{
   Elm_Object_Item *it = elm_list_selected_item_get(obj);
   if (!it) return;
   elm_list_item_selected_set(it, EINA_FALSE);
}

static void
_popup_key_down_cb(void *data EINA_UNUSED, Evas *e EINA_UNUSED,
                   Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Evas_Event_Key_Down *ev = event_info;

   printf("Key: %s\n", ev->keyname);
}

static void
_popup_center_text_cb(void *data, Evas_Object *obj EINA_UNUSED,
                      void *event_info EINA_UNUSED)
{
   Evas_Object *popup;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_text_set(popup, "This Popup has content area and "
                       "timeout value is 3 seconds");
   elm_popup_timeout_set(popup, 3.0);
   evas_object_smart_callback_add(popup, "dismissed", _response_cb, popup);
   evas_object_event_callback_add(popup, EVAS_CALLBACK_KEY_DOWN,
                                  _popup_key_down_cb, NULL);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_text_1button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                              void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_text_set(popup, "This Popup has content area and "
                       "action area set, action area has one button Close");

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Close");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_title_text_1button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                    void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);

   // popup text
   elm_object_text_set(popup, "This Popup has title area, content area and "
                       "action area set, action area has one button Close");
   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Close");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_title_text_block_clicked_event_cb(void *data,
                                                Evas_Object *obj EINA_UNUSED,
                                                void *event_info EINA_UNUSED)
{
   Evas_Object *popup;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   evas_object_smart_callback_add(popup, "block,clicked", _block_clicked_cb,
                                  NULL);

   // popup text
   elm_object_text_set(popup, "This Popup has title area and content area. "
                       "When clicked on blocked event region, popup gets "
                       "deleted");
   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_title_text_block_clicked_event_with_parent_cb(void *data,
                                                            Evas_Object *obj EINA_UNUSED,
                                                            void *event_info EINA_UNUSED)
{
   Evas_Object *bg, *popup;

   bg = elm_bg_add(data);
   elm_bg_color_set(bg, 255, 0, 0);
   evas_object_resize(bg, 350, 200);
   evas_object_move(bg, 100, 100);
   evas_object_show(bg);

   popup = elm_popup_add(bg);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   evas_object_smart_callback_add(popup, "block,clicked",
                                  _block_clicked_cb, bg);

   // popup text
   elm_object_text_set(popup, "This Popup has title area and content area. "
                       "Its blocked event region is a small rectangle. "
                       "When clicked on blocked event region, popup gets "
                       "deleted");
   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_bottom_title_text_3button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                    void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *icon, *btn1, *btn2, *btn3;
   char buf[256];

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_popup_orient_set(popup, ELM_POPUP_ORIENT_BOTTOM);

   // popup text
   elm_object_text_set(popup, "This Popup has title area, content area and "
                       "action area set with content being character wrapped. "
                       "action area has three buttons OK, Cancel and Close");
   elm_popup_content_text_wrap_type_set(popup, ELM_WRAP_CHAR);

   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup title icon
   icon = elm_icon_add(popup);
   snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
            elm_app_data_dir_get());
   elm_image_file_set(icon, buf, NULL);
   elm_object_part_content_set(popup, "title,icon", icon);

   // popup buttons
   btn1 = elm_button_add(popup);
   elm_object_text_set(btn1, "OK");
   elm_object_part_content_set(popup, "button1", btn1);
   evas_object_smart_callback_add(btn1, "clicked", _popup_close_cb, popup);

   btn2 = elm_button_add(popup);
   elm_object_text_set(btn2, "Cancel");
   elm_object_part_content_set(popup, "button2", btn2);
   evas_object_smart_callback_add(btn2, "clicked", _popup_close_cb, popup);

   btn3 = elm_button_add(popup);
   elm_object_text_set(btn3, "Close");
   elm_object_part_content_set(popup, "button3", btn3);
   evas_object_smart_callback_add(btn3, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_title_content_3button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                       void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *icon, *btn, *btn1, *btn2, *btn3;
   char buf[256];

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);

   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup content
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Content");
   icon = elm_icon_add(btn);
   snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
            elm_app_data_dir_get());
   elm_image_file_set(icon, buf, NULL);
   elm_object_content_set(btn, icon);
   elm_object_content_set(popup, btn);

   // popup buttons
   btn1 = elm_button_add(popup);
   elm_object_text_set(btn1, "OK");
   elm_object_part_content_set(popup, "button1", btn1);
   evas_object_smart_callback_add(btn1, "clicked", _popup_close_cb, popup);

   btn2 = elm_button_add(popup);
   elm_object_text_set(btn2, "Cancel");
   elm_object_part_content_set(popup, "button2", btn2);
   evas_object_smart_callback_add(btn2, "clicked", _popup_close_cb, popup);

   btn3 = elm_button_add(popup);
   elm_object_text_set(btn3, "Close");
   elm_object_part_content_set(popup, "button3", btn3);
   evas_object_smart_callback_add(btn3, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_item_focused_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *it = event_info;

   printf("item,focused:%p\n", it);
}

static void
_item_unfocused_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
   Elm_Object_Item *it = event_info;

   printf("item,unfocused:%p\n", it);
}

static void
_popup_center_title_item_3button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                    void *event_info EINA_UNUSED)
{
   char buf[256];
   unsigned int i;
   Evas_Object *popup, *icon1, *btn1, *btn2, *btn3;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);

   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup items
   icon1 = elm_icon_add(popup);
   snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
            elm_app_data_dir_get());
   elm_image_file_set(icon1, buf, NULL);
   for (i = 0; i < 20; i++)
     {
        snprintf(buf, sizeof(buf), "Item%u", i+1);
        if (i == 3)
          elm_popup_item_append(popup, buf, icon1, _item_selected_cb, NULL);
        else
          elm_popup_item_append(popup, buf, NULL, _item_selected_cb, NULL);
     }

   // popup buttons
   btn1 = elm_button_add(popup);
   elm_object_text_set(btn1, "OK");
   elm_object_part_content_set(popup, "button1", btn1);
   evas_object_smart_callback_add(btn1, "clicked", _popup_close_cb, popup);

   btn2 = elm_button_add(popup);
   elm_object_text_set(btn2, "Cancel");
   elm_object_part_content_set(popup, "button2", btn2);
   evas_object_smart_callback_add(btn2, "clicked", _popup_close_cb, popup);

   btn3 = elm_button_add(popup);
   elm_object_text_set(btn3, "Close");
   elm_object_part_content_set(popup, "button3", btn3);
   evas_object_smart_callback_add(btn3, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
   evas_object_smart_callback_add(popup, "item,focused", _item_focused_cb, NULL);
   evas_object_smart_callback_add(popup, "item,unfocused", _item_unfocused_cb, NULL);
}

static void
_restack_btn_clicked(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Evas_Object *im;
   char buf[PATH_MAX];
   void *popup_data;

   popup_data = evas_object_data_get(data, "im");
   if (popup_data) return;

   im = evas_object_image_filled_add(evas_object_evas_get(obj));
   snprintf(buf, sizeof(buf), "%s/images/%s",
            elm_app_data_dir_get(), "twofish.jpg");
   evas_object_image_file_set(im, buf, NULL);
   evas_object_move(im, 40, 40);
   evas_object_resize(im, 320, 320);
   evas_object_show(im);
   evas_object_data_set((Evas_Object *)data, "im", im);

   evas_object_raise((Evas_Object *)data);
}

static void
_popup_center_title_text_2button_restack_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                    void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn, *btn2;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   evas_object_smart_callback_add(popup, "block,clicked",
                                  _restack_block_clicked_cb, NULL);

   // popup text
   elm_object_text_set(popup, "When you click the 'Restack' button, "
                       "an image will be located under this popup");
   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Restack");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _restack_btn_clicked, popup);

   btn2 = elm_button_add(popup);
   elm_object_text_set(btn2, "Close");
   elm_object_part_content_set(popup, "button2", btn2);
   evas_object_smart_callback_add(btn2, "clicked",
                                  _restack_popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_text_1button_hide_show_cb(void *data, Evas_Object *obj EINA_UNUSED,
                              void *event_info EINA_UNUSED)
{
   Evas_Object *btn;
   char str[128];

   times++;
   if (g_popup)
     {
        sprintf(str, "You have checked this popup %d times.", times);
        elm_object_text_set(g_popup, str);
        evas_object_show(g_popup);
        return;
     }

   g_popup = elm_popup_add(data);
   elm_popup_scrollable_set(g_popup, is_popup_scroll);
   elm_object_text_set(g_popup, "Hide this popup by using the button."
                       "When you click list item again, you can see this popup.");

   // popup buttons
   btn = elm_button_add(g_popup);
   elm_object_text_set(btn, "Hide");
   elm_object_part_content_set(g_popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _g_popup_response_cb, g_popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(g_popup);
}

static void
_toggle_button_cb(void *data,
                  Evas_Object *obj,
                  void *event_info EINA_UNUSED)
{
   Evas_Object *btn = data;
   char buf[] = "button0";
   int i;

   i = (int)(uintptr_t)evas_object_data_get(btn, "index");

   buf[6] = '0' + i + 1;
   if (evas_object_visible_get(btn))
     {
        elm_object_part_content_unset(obj, buf);
        evas_object_hide(btn);
     }
   else
     elm_object_part_content_set(obj, buf, btn);
}

static void
_popup_center_text_3button_add_remove_button_cb(void *data,
                                                Evas_Object *obj EINA_UNUSED,
                                                void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btns[3];

   char buf[256];
   int i;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);

   // popup title
   elm_object_part_text_set(popup, "title,text",
                            "Click the item to toggle button");

   // popup buttons
   for (i = 0; i < 3; ++i)
     {
        snprintf(buf, sizeof(buf), "Btn #%d", i + 1);
        btns[i] = elm_button_add(popup);
        evas_object_data_set(btns[i], "index", (void*)(uintptr_t)i);
        elm_object_text_set(btns[i], buf);

        elm_popup_item_append(popup, buf, NULL, _toggle_button_cb, btns[i]);

        snprintf(buf, sizeof(buf), "button%d", i + 1);
        elm_object_part_content_set(popup, buf, btns[i]);
        evas_object_smart_callback_add(btns[i], "clicked",
                                       _popup_close_cb, popup);
     }

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_transparent_cb(void *data, Evas_Object *obj EINA_UNUSED,
                      void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_style_set(popup, "transparent");
   elm_object_text_set(popup, "This Popup has transparent background");

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Close");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_transparent_align_cb(void *data, Evas_Object *obj EINA_UNUSED,
                            void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn, *btn1;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_style_set(popup, "transparent");
   elm_object_text_set(popup, "This Popup has transparent background");

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Move");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_align_cb, popup);

   btn1 = elm_button_add(popup);
   elm_object_text_set(btn1, "Close");
   elm_object_part_content_set(popup, "button2", btn1);
   evas_object_smart_callback_add(btn1, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_list_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   evas_object_del(data);
}

char *
gl_popup_text_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
{
   char buf[256];
   snprintf(buf, sizeof(buf), "Item # %i", (int)(uintptr_t)data);
   return strdup(buf);
}

static void
_delete_btn_clicked(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   elm_object_content_set(data, NULL);
}

static void
_popup_center_title_list_content_2button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                            void *event_info EINA_UNUSED)
{
   Evas_Object *popup, *list;
   Evas_Object *btn;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_part_text_set(popup, "title,text", "Title");

   // list as a popup content
   list = elm_list_add(popup);
   elm_list_mode_set(list, ELM_LIST_EXPAND);
   elm_list_item_append(list, "List Item #1", NULL, NULL, _list_cb, popup);
   elm_list_item_append(list, "List Item #2", NULL, NULL, _list_cb, popup);
   elm_list_item_append(list, "List Item #3", NULL, NULL, _list_cb, popup);
   elm_object_content_set(popup, list);

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "OK");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);

   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Delete");
   elm_object_part_content_set(popup, "button2", btn);
   evas_object_smart_callback_add(btn, "clicked", _delete_btn_clicked, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_center_title_genlist_content_1button_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                            void *event_info EINA_UNUSED)
{
   Evas_Object *popup, *genlist;
   Evas_Object *btn;
   int i;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_part_text_set(popup, "title,text", "Title");

   Elm_Genlist_Item_Class *itc1 = elm_genlist_item_class_new();
   itc1->item_style = "default";
   itc1->func.text_get = gl_popup_text_get;
   itc1->func.content_get = NULL;
   itc1->func.state_get = NULL;
   itc1->func.del = NULL;

   // genlist as a popup content
   genlist = elm_genlist_add(popup);
   elm_genlist_mode_set(genlist, ELM_LIST_EXPAND);
   elm_scroller_content_min_limit(genlist, EINA_FALSE, EINA_TRUE);

   for (i = 0; i < 10; i++)
     {
        elm_genlist_item_append(genlist,
                                itc1,
                                (void *)(uintptr_t)i/* item data */,
                                NULL/* parent */,
                                ELM_GENLIST_ITEM_NONE,
                                NULL,
                                NULL);
     }
   elm_genlist_item_class_free(itc1);
   elm_object_content_set(popup, genlist);

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "OK");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_subpopup_cb(void *data, Evas_Object *obj EINA_UNUSED,
             void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn, *btnclose;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);
   elm_object_style_set(popup, "subpopup");
   elm_object_part_text_set(popup, "title,text", "Title");

   // button as a popup content
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "content");
   elm_object_content_set(popup, btn);

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "OK");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);

   //popup-base close button
   btnclose = elm_button_add(popup);
   //TODO: write a X style button theme
   elm_object_text_set(btnclose, "x");
   elm_object_part_content_set(popup, "elm.swallow.closebtn", btnclose);
   evas_object_smart_callback_add(btnclose, "clicked", _popup_close_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_popup_content_only_cb(void *data, Evas_Object *obj EINA_UNUSED,
                       void *event_info EINA_UNUSED)
{
   Evas_Object *popup, *bx, *hbx, *lbl, *btn;
   Evas_Object *win = data;

   popup = elm_popup_add(win);
   elm_popup_scrollable_set(popup, is_popup_scroll);

   bx = elm_box_add(popup);
   evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(bx, EVAS_HINT_FILL, 0.0);
   elm_object_content_set(popup, bx);

   lbl = elm_label_add(popup);
   elm_object_text_set(lbl,
                       "<align=center>This popup contains content area only.<br>"
                       "The buttons below are the part of content area, not action area");
   evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, 0.0);
   elm_box_pack_end(bx, lbl);
   evas_object_show(lbl);

   hbx = elm_box_add(bx);
   elm_box_horizontal_set(hbx, EINA_TRUE);
   evas_object_size_hint_weight_set(hbx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(hbx, EVAS_HINT_FILL, 0.0);
   elm_box_pack_end(bx, hbx);
   evas_object_show(hbx);

   btn = elm_button_add(hbx);
   elm_object_text_set(btn, "Save");
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);
   elm_box_pack_end(hbx, btn);
   evas_object_show(btn);

   btn = elm_button_add(hbx);
   elm_object_text_set(btn, "Discard");
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);
   elm_box_pack_end(hbx, btn);
   evas_object_show(btn);

   btn = elm_button_add(hbx);
   elm_object_text_set(btn, "Cancel");
   evas_object_smart_callback_add(btn, "clicked", _popup_close_cb, popup);
   elm_box_pack_end(hbx, btn);
   evas_object_show(btn);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
   elm_object_focus_set(btn, EINA_TRUE);
}

static void
_popup_center_title_text_1button_hide_effect_cb(void *data, Evas_Object *obj EINA_UNUSED,
                                                void *event_info EINA_UNUSED)
{
   Evas_Object *popup;
   Evas_Object *btn;

   popup = elm_popup_add(data);
   elm_popup_scrollable_set(popup, is_popup_scroll);

   // popup text
   elm_object_text_set(popup, "This Popup has title area, content area and "
                       "action area set, action area has one button Close");
   // popup title
   elm_object_part_text_set(popup, "title,text", "Title");

   // popup buttons
   btn = elm_button_add(popup);
   elm_object_text_set(btn, "Close");
   elm_object_part_content_set(popup, "button1", btn);
   evas_object_smart_callback_add(popup, "dismissed", _response_cb, NULL);
   evas_object_smart_callback_add(btn, "clicked", _popup_dismiss_btn_cb, popup);

   // popup show should be called after adding all the contents and the buttons
   // of popup to set the focus into popup's contents correctly.
   evas_object_show(popup);
}

static void
_focus_changed_cb(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   Eina_Bool check = elm_check_state_get(obj);
   elm_win_focus_highlight_enabled_set(data, check);
   elm_win_focus_highlight_animate_set(data, check);
}

static void
_popup_scroll_cb(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   is_popup_scroll = elm_check_state_get(obj);
}

void
test_popup(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
           void *event_info EINA_UNUSED)
{
   Evas_Object *win, *box, *list, *check;

   win = elm_win_util_standard_add("popup", "Popup");
   elm_win_autodel_set(win, EINA_TRUE);

   box = elm_box_add(win);
   evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, box);
   evas_object_show(box);

   list = elm_list_add(box);
   evas_object_size_hint_weight_set(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(box, list);
   elm_list_mode_set(list, ELM_LIST_LIMIT);
   evas_object_smart_callback_add(list, "selected", _list_click, NULL);

   elm_list_item_append(list, "popup-center-text", NULL, NULL,
                        _popup_center_text_cb, win);
   elm_list_item_append(list, "popup-center-text + 1 button", NULL, NULL,
                        _popup_center_text_1button_cb, win);
   elm_list_item_append(list, "popup-center-title + text + 1 button", NULL,
                        NULL, _popup_center_title_text_1button_cb, win);

   elm_list_item_append(list,
                        "popup-center-title + text (block,clicked handling)",
                        NULL, NULL,
                        _popup_center_title_text_block_clicked_event_cb, win);
   elm_list_item_append(list,
                        "popup-center-title + text (block,clicked handling with parent)",
                        NULL, NULL,
                        _popup_center_title_text_block_clicked_event_with_parent_cb, win);
   elm_list_item_append(list, "popup-bottom-title-icon + text + 3 buttons", NULL,
                        NULL, _popup_bottom_title_text_3button_cb, win);
   elm_list_item_append(list, "popup-center-title + content + 3 buttons", NULL,
                        NULL, _popup_center_title_content_3button_cb, win);
   elm_list_item_append(list, "popup-center-title + items + 3 buttons", NULL,
                        NULL, _popup_center_title_item_3button_cb, win);
   elm_list_item_append(list, "popup-center-title + text + 2 buttons (check restacking)", NULL, NULL,
                        _popup_center_title_text_2button_restack_cb, win);
   elm_list_item_append(list, "popup-center-text + 1 button (check hide, show)", NULL, NULL,
                        _popup_center_text_1button_hide_show_cb, win);
   elm_list_item_append(list, "popup-center-text + 3 button (check add, remove buttons)", NULL, NULL,
                        _popup_center_text_3button_add_remove_button_cb, win);
   elm_list_item_append(list, "popup-transparent", NULL, NULL,
                        _popup_transparent_cb, win);
   elm_list_item_append(list, "popup-transparent-align", NULL, NULL,
                        _popup_transparent_align_cb, win);
   elm_list_item_append(list, "popup-center-title + list content + 2 button (with delete content)",
                        NULL, NULL, _popup_center_title_list_content_2button_cb,
                        win);
   elm_list_item_append(list, "popup-center-title + genlist content + 1 button",
                        NULL, NULL, _popup_center_title_genlist_content_1button_cb,
                        win);
   elm_list_item_append(list, "subpopup + X button",
                        NULL, NULL, _subpopup_cb,
                        win);
   elm_list_item_append(list, "popup with content only",
                        NULL, NULL, _popup_content_only_cb,
                        win);
   elm_list_item_append(list, "popup-center-title + text + 1 button + hide effect", NULL,
                        NULL, _popup_center_title_text_1button_hide_effect_cb, win);
   elm_list_go(list);
   evas_object_show(list);

   check = elm_check_add(box);
   elm_object_text_set(check, "Enable Focus Highlight");
   evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
   evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(box, check);
   evas_object_show(check);
   evas_object_smart_callback_add(check, "changed", _focus_changed_cb, win);

   check = elm_check_add(box);
   elm_object_text_set(check, "Enable popup scroll");
   evas_object_size_hint_weight_set(check, EVAS_HINT_EXPAND, 0.0);
   evas_object_size_hint_align_set(check, EVAS_HINT_FILL, EVAS_HINT_FILL);
   elm_box_pack_end(box, check);
   evas_object_show(check);
   evas_object_smart_callback_add(check, "changed", _popup_scroll_cb, NULL);

   if (elm_config_popup_scrollable_get())
     {
        elm_check_state_set(check, EINA_TRUE);
        is_popup_scroll = EINA_TRUE;
     }

   evas_object_resize(win, 480, 400);
   evas_object_show(win);
}

typedef struct
{
   Evas_Object *win;
   Evas_Object *panel_win;
   Evas_Object *efl_ui_popup;
   Evas_Object *button;
} efl_ui_popup_data;

static void
_bg_clicked(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                      void *event_info EINA_UNUSED)
{
   printf("Popup's background is clicked.\n");
}

static void
_timeout_cb(void *data EINA_UNUSED, const Efl_Event *ev EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   p_data->efl_ui_popup = NULL;
   printf("Popup times out and it is deleted.\n");
}

static void
_delete_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (p_data->efl_ui_popup)
     {
        evas_object_del(p_data->efl_ui_popup);
        p_data->efl_ui_popup = NULL;
        return;
     }
   printf("Efl.Ui.Popup is not exist.\n");
}

static Evas_Object*
_create_popup(efl_ui_popup_data *p_data)
{
   if (!p_data->win) return NULL;
   if (p_data->efl_ui_popup)
     {
        printf("Efl.Ui.Popup is already created.\n");
        evas_object_show(p_data->efl_ui_popup);
        return p_data->efl_ui_popup;
     }

   Evas_Object *efl_ui_popup = efl_add(EFL_UI_POPUP_CLASS, p_data->win);

   evas_object_smart_callback_add(efl_ui_popup, "bg,clicked", _bg_clicked, NULL);
   efl_event_callback_add(efl_ui_popup, EFL_UI_POPUP_EVENT_TIMEOUT, _timeout_cb, p_data);
   evas_object_resize(efl_ui_popup, 160, 160);
   evas_object_show(efl_ui_popup);

   Evas_Object *btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Efl.Ui.Popup");
   evas_object_show(btn);

   efl_content_set(efl_ui_popup, btn);

   return efl_ui_popup;
}

static void
_create_cb(void *data, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   p_data->efl_ui_popup = _create_popup(p_data);
}

static void
_bg_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   static int k = 0;
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   if (k == 0)
     {
        char buf[PATH_MAX];
        snprintf(buf, sizeof(buf), "%s/images/sky_01.jpg", elm_app_data_dir_get());
        efl_ui_popup_bg_set(p_data->efl_ui_popup, buf, NULL);
        elm_object_text_set(obj, "Bg UnSet");
     }
   else
     {
        efl_ui_popup_bg_set(p_data->efl_ui_popup, NULL, NULL);
        elm_object_text_set(obj, "Bg Set");
     }
   k = !k;
}

static void
_repeat_event_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   if (!efl_ui_popup_bg_repeat_events_get(p_data->efl_ui_popup))
     {
        efl_ui_popup_bg_repeat_events_set(p_data->efl_ui_popup, EINA_TRUE);
        elm_object_text_set(obj, "Repeat Event UnSet");
     }
   else
     {
        efl_ui_popup_bg_repeat_events_set(p_data->efl_ui_popup, EINA_FALSE);
        elm_object_text_set(obj, "Repeat Event Set");
     }
}

static void
_repeat_test_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   printf("Repeat Test Button is Clicked.\n");
}

static void
_dummy_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   if (!evas_object_visible_get(p_data->button))
     {
        evas_object_show(p_data->button);
        elm_object_text_set(obj, "Hide Dummy Button");
     }
   else
     {
        evas_object_hide(p_data->button);
        elm_object_text_set(obj, "Show Dummy Button");
     }
}

static void
_center_align_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   efl_ui_popup_align_set(p_data->efl_ui_popup, EFL_UI_POPUP_ALIGN_CENTER);
}

static void
_left_align_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   efl_ui_popup_align_set(p_data->efl_ui_popup, EFL_UI_POPUP_ALIGN_LEFT);
}

static void
_right_align_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   efl_ui_popup_align_set(p_data->efl_ui_popup, EFL_UI_POPUP_ALIGN_RIGHT);
}

static void
_top_align_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   efl_ui_popup_align_set(p_data->efl_ui_popup, EFL_UI_POPUP_ALIGN_TOP);
}

static void
_bottom_align_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   efl_ui_popup_align_set(p_data->efl_ui_popup, EFL_UI_POPUP_ALIGN_BOTTOM);
}

static void
_position_set_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   evas_object_move(p_data->efl_ui_popup, 0, 0);
}

static void
_timeout_set_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   if (!p_data->efl_ui_popup) return;
   efl_ui_popup_timeout_set(p_data->efl_ui_popup, 3);
   printf("timemout is set to 3 seconds\n");
}

static void
_win_del(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   evas_object_del(p_data->panel_win);
   free(p_data);
   printf("window is deleted\n");
}

static void
_panel_win_del(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = data;
   evas_object_del(p_data->win);
   free(p_data);
   printf("window is deleted\n");
}

void
test_efl_ui_popup(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = (efl_ui_popup_data*)calloc(1, sizeof(efl_ui_popup_data));

   Evas_Object *win, *panel_win;

   win = elm_win_util_standard_add("Efl UI Popup", "Efl UI Popup");
   elm_win_autodel_set(win, EINA_TRUE);
   evas_object_smart_callback_add(win, "delete,request", _win_del, p_data);

   evas_object_resize(win, 500, 500);
   evas_object_show(win);

   panel_win = elm_win_util_standard_add("Efl UI Popup Panel", "Efl UI Popup Panel");
   elm_win_autodel_set(panel_win, EINA_TRUE);
   evas_object_smart_callback_add(panel_win, "delete,request", _panel_win_del, p_data);

   evas_object_resize(panel_win, 300, 500);
   evas_object_show(panel_win);

   Evas_Object *repeat_test_btn;
   repeat_test_btn = elm_button_add(win);
   evas_object_move(repeat_test_btn, 0, 0);
   evas_object_resize(repeat_test_btn, 100, 100);
   elm_object_text_set(repeat_test_btn, "Repeat Event Test");
   evas_object_smart_callback_add(repeat_test_btn, "clicked", _repeat_test_cb, NULL);
   evas_object_hide(repeat_test_btn);

   p_data->win = win;
   p_data->panel_win = panel_win;
   p_data->button = repeat_test_btn;
   p_data->efl_ui_popup = _create_popup(p_data);

   Evas_Object *create_btn;
   create_btn = elm_button_add(panel_win);
   elm_object_text_set(create_btn, "Create Popup");
   evas_object_move(create_btn, 0, 0);
   evas_object_resize(create_btn, 150, 50);
   evas_object_show(create_btn);
   evas_object_smart_callback_add(create_btn, "clicked", _create_cb, p_data);

   Evas_Object *delete_btn;
   delete_btn = elm_button_add(panel_win);
   elm_object_text_set(delete_btn, "Delete Popup");
   evas_object_move(delete_btn, 150, 0);
   evas_object_resize(delete_btn, 150, 50);
   evas_object_show(delete_btn);
   evas_object_smart_callback_add(delete_btn, "clicked", _delete_cb, p_data);

   Evas_Object *repeat_event_btn;
   repeat_event_btn = elm_button_add(panel_win);
   elm_object_text_set(repeat_event_btn, "Repeat Event Set");
   evas_object_move(repeat_event_btn, 0, 50);
   evas_object_resize(repeat_event_btn, 150, 50);
   evas_object_show(repeat_event_btn);
   evas_object_smart_callback_add(repeat_event_btn, "clicked", _repeat_event_cb, p_data);

   Evas_Object *dummy_btn;
   dummy_btn = elm_button_add(panel_win);
   elm_object_text_set(dummy_btn, "Show Dummy Button");
   evas_object_move(dummy_btn, 150, 50);
   evas_object_resize(dummy_btn, 150, 50);
   evas_object_show(dummy_btn);
   evas_object_smart_callback_add(dummy_btn, "clicked", _dummy_cb, p_data);

   Evas_Object *bg_btn;
   bg_btn = elm_button_add(panel_win);
   evas_object_move(bg_btn, 0, 100);
   evas_object_resize(bg_btn, 150, 50);
   elm_object_text_set(bg_btn, "Bg Set");
   evas_object_show(bg_btn);
   evas_object_smart_callback_add(bg_btn, "clicked", _bg_cb, p_data);

   Evas_Object *timeout_btn;
   timeout_btn = elm_button_add(panel_win);
   elm_object_text_set(timeout_btn, "Timeout Set");
   evas_object_move(timeout_btn, 150, 100);
   evas_object_resize(timeout_btn, 150, 50);
   evas_object_show(timeout_btn);
   evas_object_smart_callback_add(timeout_btn, "clicked", _timeout_set_cb, p_data);

   Evas_Object *center_btn;
   center_btn = elm_button_add(panel_win);
   elm_object_text_set(center_btn, "Center Align");
   evas_object_move(center_btn, 0, 150);
   evas_object_resize(center_btn, 150, 50);
   evas_object_show(center_btn);
   evas_object_smart_callback_add(center_btn, "clicked", _center_align_cb, p_data);

   Evas_Object *top_btn;
   top_btn = elm_button_add(panel_win);
   elm_object_text_set(top_btn, "Top Align");
   evas_object_move(top_btn, 150, 150);
   evas_object_resize(top_btn, 150, 50);
   evas_object_show(top_btn);
   evas_object_smart_callback_add(top_btn, "clicked", _top_align_cb, p_data);

   Evas_Object *left_btn;
   left_btn = elm_button_add(panel_win);
   elm_object_text_set(left_btn, "Left Align");
   evas_object_move(left_btn, 0, 200);
   evas_object_resize(left_btn, 150, 50);
   evas_object_show(left_btn);
   evas_object_smart_callback_add(left_btn, "clicked", _left_align_cb, p_data);

   Evas_Object *right_btn;
   right_btn = elm_button_add(panel_win);
   elm_object_text_set(right_btn, "Right Align");
   evas_object_move(right_btn, 150, 200);
   evas_object_resize(right_btn, 150, 50);
   evas_object_show(right_btn);
   evas_object_smart_callback_add(right_btn, "clicked", _right_align_cb, p_data);

   Evas_Object *bottom_btn;
   bottom_btn = elm_button_add(panel_win);
   elm_object_text_set(bottom_btn, "Bottom Align");
   evas_object_move(bottom_btn, 0, 250);
   evas_object_resize(bottom_btn, 150, 50);
   evas_object_show(bottom_btn);
   evas_object_smart_callback_add(bottom_btn, "clicked", _bottom_align_cb, p_data);

   Evas_Object *position_btn;
   position_btn = elm_button_add(panel_win);
   elm_object_text_set(position_btn, "Position Set (x:0, y:0)");
   evas_object_move(position_btn, 150, 250);
   evas_object_resize(position_btn, 150, 50);
   evas_object_show(position_btn);
   evas_object_smart_callback_add(position_btn, "clicked", _position_set_cb, p_data);
}

static void
efl_ui_popup_alert_clicked_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
   Efl_Ui_Popup_Alert_Clicked_Event *event = ev->info;

   if (event->button_type == EFL_UI_POPUP_ALERT_BUTTON_POSITIVE)
     printf("Positive Button is clicked\n");
   else if(event->button_type == EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE)
     printf("Negative Button is clicked\n");
   else if(event->button_type == EFL_UI_POPUP_ALERT_BUTTON_USER)
     printf("User Button is clicked\n");
}

void
test_efl_ui_popup_alert(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win;
   char buf[PATH_MAX];

   win = elm_win_util_standard_add("Efl UI Popup Alert", "Efl UI Popup Alert");
   elm_win_autodel_set(win, EINA_TRUE);

   evas_object_resize(win, 320, 320);
   evas_object_show(win);

   Evas_Object *efl_ui_popup= efl_add(EFL_UI_POPUP_ALERT_CLASS, win);

   efl_text_set(efl_part(efl_ui_popup, "title"), "title");

   evas_object_resize(efl_ui_popup, 160, 160);
   evas_object_show(efl_ui_popup);

   Evas_Object *layout = elm_layout_add(efl_ui_popup);
   snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
   elm_layout_file_set(layout, buf, "efl_ui_popup_scroll_content");
   evas_object_show(layout);

   efl_content_set(efl_ui_popup, layout);
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_POSITIVE, "Yes");
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE, "No");
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_USER, "Cancel");

   efl_event_callback_add(efl_ui_popup, EFL_UI_POPUP_ALERT_EVENT_CLICKED, efl_ui_popup_alert_clicked_cb, NULL);
}

void
test_efl_ui_popup_alert_scroll(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win;
   char buf[PATH_MAX];

   win = elm_win_util_standard_add("Efl UI Popup Alert Scroll", "Efl UI Popup Alert Scroll");
   elm_win_autodel_set(win, EINA_TRUE);

   evas_object_resize(win, 320, 320);
   evas_object_show(win);

   Evas_Object *efl_ui_popup= efl_add(EFL_UI_POPUP_ALERT_SCROLL_CLASS, win);

   efl_text_set(efl_part(efl_ui_popup, "title"), "title");

   evas_object_resize(efl_ui_popup, 160, 160);
   evas_object_show(efl_ui_popup);

   Evas_Object *layout = elm_layout_add(efl_ui_popup);
   snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
   elm_layout_file_set(layout, buf, "efl_ui_popup_scroll_content");
   evas_object_show(layout);

   efl_content_set(efl_ui_popup, layout);

   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_POSITIVE, "Yes");
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE, "No");
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_USER, "Cancel");

   efl_ui_popup_alert_scroll_expandable_set(efl_ui_popup, EINA_TRUE, EINA_TRUE);
   efl_gfx_size_hint_max_set(efl_ui_popup, EINA_SIZE2D(300, 180));

   efl_event_callback_add(efl_ui_popup, EFL_UI_POPUP_ALERT_EVENT_CLICKED, efl_ui_popup_alert_clicked_cb, NULL);
}

void
test_efl_ui_popup_alert_text(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   Evas_Object *win;

   win = elm_win_util_standard_add("Efl UI Popup Alert Text", "Efl UI Popup Alert Text");
   elm_win_autodel_set(win, EINA_TRUE);

   evas_object_resize(win, 320, 320);
   evas_object_show(win);

   Evas_Object *efl_ui_popup= efl_add(EFL_UI_POPUP_ALERT_TEXT_CLASS, win);

   efl_text_set(efl_part(efl_ui_popup, "title"), "title");

   evas_object_resize(efl_ui_popup, 160, 160);
   evas_object_show(efl_ui_popup);

   efl_text_set(efl_ui_popup,
                "This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup"
                "This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup"
                "This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup This is Text Popup");

   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_POSITIVE, "Yes");
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_NEGATIVE, "No");
   efl_ui_popup_alert_button_set(efl_ui_popup, EFL_UI_POPUP_ALERT_BUTTON_USER, "Cancel");

   efl_ui_popup_alert_text_expandable_set(efl_ui_popup, EINA_TRUE);
   efl_gfx_size_hint_max_set(efl_ui_popup, EINA_SIZE2D(100, 180));

   efl_event_callback_add(efl_ui_popup, EFL_UI_POPUP_ALERT_EVENT_CLICKED, efl_ui_popup_alert_clicked_cb, NULL);
}

static void
_anchor_set_cb(void *data, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_anchor_set(data, obj);
}

static void
_anchor_unset_cb(void *data, Evas_Object *obj EINA_UNUSED,
                void *event_info EINA_UNUSED)
{
   efl_ui_popup_anchor_set(data, NULL);
}

void
test_efl_ui_popup_anchor(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
   efl_ui_popup_data *p_data = (efl_ui_popup_data*)calloc(1, sizeof(efl_ui_popup_data));

   Evas_Object *win, *layout, *tbl, *btn;
   char buf[PATH_MAX];

   win = elm_win_util_standard_add("Efl UI Popup Anchor", "Efl UI Popup Anchor");
   elm_win_autodel_set(win, EINA_TRUE);
   evas_object_smart_callback_add(win, "delete,request", _win_del, p_data);

   evas_object_resize(win, 500, 500);
   evas_object_show(win);

   layout = elm_layout_add(win);
   snprintf(buf, sizeof(buf), "%s/objects/test.edj", elm_app_data_dir_get());
   elm_layout_file_set(layout, buf, "efl_ui_popup_anchor_layout");
   evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, layout);
   evas_object_show(layout);

   Evas_Object *efl_ui_popup= efl_add(EFL_UI_POPUP_ANCHOR_CLASS, win);

   efl_ui_popup_bg_repeat_events_set(efl_ui_popup, EINA_TRUE);

   //Default align priority order is top, left, right, bottom, center.
   efl_ui_popup_anchor_align_priority_set(efl_ui_popup, EFL_UI_POPUP_ALIGN_TOP,
                                          EFL_UI_POPUP_ALIGN_BOTTOM,
                                          EFL_UI_POPUP_ALIGN_LEFT,
                                          EFL_UI_POPUP_ALIGN_RIGHT,
                                          EFL_UI_POPUP_ALIGN_CENTER);

   evas_object_move(efl_ui_popup, 80, 80);
   evas_object_resize(efl_ui_popup, 160, 120);
   evas_object_show(efl_ui_popup);

   p_data->win = win;
   p_data->efl_ui_popup = efl_ui_popup;

   for (int i = 0; i < 6; i++)
     {
        btn = elm_button_add(win);
        elm_object_text_set(btn, "anchor");
        evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_smart_callback_add(btn, "clicked", _anchor_set_cb, efl_ui_popup);

        snprintf(buf, sizeof(buf), "anchor%d", i+1);
        elm_object_part_content_set(layout, buf, btn);
     }

   btn = elm_button_add(win);
   elm_object_text_set(btn, "anchor none");
   evas_object_size_hint_weight_set(btn, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_smart_callback_add(btn, "clicked", _anchor_unset_cb, efl_ui_popup);
   elm_object_part_content_set(layout, "anchor_none", btn);

   tbl = elm_table_add(efl_ui_popup);
   evas_object_size_hint_weight_set(tbl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   evas_object_size_hint_align_set(tbl, EVAS_HINT_FILL, EVAS_HINT_FILL);

   btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Center Align");
   evas_object_size_hint_min_set(btn, 70, 35);
   evas_object_smart_callback_add(btn, "clicked", _center_align_cb, p_data);
   elm_table_pack(tbl, btn, 0, 0, 1, 1);
   evas_object_show(btn);

   btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Left Align");
   evas_object_size_hint_min_set(btn, 70, 35);
   evas_object_smart_callback_add(btn, "clicked", _left_align_cb, p_data);
   elm_table_pack(tbl, btn, 1, 0, 1, 1);
   evas_object_show(btn);

   btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Right Align");
   evas_object_size_hint_min_set(btn, 70, 35);
   evas_object_smart_callback_add(btn, "clicked", _right_align_cb, p_data);
   elm_table_pack(tbl, btn, 2, 0, 1, 1);
   evas_object_show(btn);

   btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Top Align");
   evas_object_size_hint_min_set(btn, 70, 35);
   evas_object_smart_callback_add(btn, "clicked", _top_align_cb, p_data);
   elm_table_pack(tbl, btn, 0, 1, 1, 1);
   evas_object_show(btn);

   btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Bottom Align");
   evas_object_size_hint_min_set(btn, 70, 35);
   evas_object_smart_callback_add(btn, "clicked", _bottom_align_cb, p_data);
   elm_table_pack(tbl, btn, 1, 1, 1, 1);
   evas_object_show(btn);

   btn = elm_button_add(efl_ui_popup);
   elm_object_text_set(btn, "Position Set");
   evas_object_size_hint_min_set(btn, 70, 35);
   evas_object_smart_callback_add(btn, "clicked", _position_set_cb, p_data);
   elm_table_pack(tbl, btn, 2, 1, 1, 1);
   evas_object_show(btn);

   efl_content_set(efl_ui_popup, tbl);
}