summaryrefslogtreecommitdiff
path: root/EDK/MiniSetup/TseLite/PopupSel.c
blob: dd81c2014926a0427bf391840d0e39d118def6d2 (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
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
//**                                                             **//
//**         (C)Copyright 2011, American Megatrends, Inc.        **//
//**                                                             **//
//**                     All Rights Reserved.                    **//
//**                                                             **//
//**   5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093  **//
//**                                                             **//
//**                     Phone (770)-246-8600                    **//
//**                                                             **//
//*****************************************************************//
//*****************************************************************//
//*****************************************************************//
// $Archive: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/PopupSel.c $
//
// $Author: Premkumara $
//
// $Revision: 40 $
//
// $Date: 8/28/14 3:09p $
//
//*****************************************************************//
//*****************************************************************//
// Revision History
// ----------------
// $Log: /Alaska/SOURCE/Modules/AMITSE2_0/AMITSE/TseLite/PopupSel.c $
// 
// 40    8/28/14 3:09p Premkumara
// [TAG]	EIP141986
// [Category]	Improvement
// [Description]	Make grayedout control focusable and this feature is
// handled by token TSE_SETUP_GRAYOUT_SELECTABLE
// [Files]	AMITSE.sdl, CommonHelper.c, Frame.c, Label.c, Minisetupext.c,
// Numeric.c, PopupPassword.c, PopupSel.c, PopupString. SubMenu.c
// 
// 39    5/02/14 9:36p Arunsb
// EIP141986 changes reverted.
// 
// 38    5/02/14 10:54a Premkumara
// [TAG]  		EIP141986
// [Category]  	New Feature
// [Description]  	Made Grayed controls to focus-able when token
// TSE_SETUP_GRAYOUT_SELECTABLE
//  is enabled and can't edit the values
// [Files]  		AMITSE.sdl,CommonHelper.c,frame.c,Label.c,minisetupext.h,
// numeric.c,PopupPassword.c,PopupSel.c,PopupString.c,SubMenu.c
// 
// 37    5/01/14 3:45p Premkumara
// [TAG]  		EIP123727
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	Enabling Multiline and in Boot option priorities, Clicking
// on second or third line of the boot item is not selecting boot options
// menu
// [RootCause]  	Proper Condition was not there to check whether Mouse
// Click
// is within the Width and Height of Control or not.
// [Solution]  	Added Proper Condition to check whether Mouse Click
// is within the Width and Height of Control or not.
// [Files]  		Date.c, time.c, frame.c, SubMenu.c, numeric.c,
// PopupString.c, PopupSel.c, ordlistbox.c, PopupPassword.c, UefiAction.c,
// 
// 36    2/11/14 8:37p Arunsb
// Changes reverted for 2.16.1243 label
// 
// 35    12/03/13 1:12p Premkumara
// [TAG]	EIP141986
// [Category]	Improvement
// [Description]	Make grayedout control focusable and this feature is
// handled by token TSE_SETUP_GRAYOUT_SELECTABLE
// [Files]	AMITSE.sdl, CommonHelper.c, Frame.c, Label.c, Minisetupext.c,
// Numeric.c, PopupPassword.c, PopupSel.c, PopupString. SubMenu.c
// 
// 34    10/18/12 6:02a Arunsb
// Updated for 2.16.1235 QA submission
// 
// 17    10/10/12 12:38p Arunsb
// Synched the source for v2.16.1232, backup with Aptio
// 
// 32    9/25/12 11:44a Blaines
// [TAG] - EIP 101903
// [Category] - Defect
// [Synopsis] -  Enabling Multiline in TSE cause a crash when entering in
// TSE
// [Root cause] If SPrint is called with a string that exceeds the
// buffersize, overflow occurs and exception happens. 
// [Solution] Call Sprint using only the printable length copy of the
// original string.
// [Files] - Popupsel.c
// [Function] - PopupSelGetControlHeight 
// 
// 31    9/18/12 5:08a Arunsb
// [TAG]  		EIP95139
// [Category]  	Bug Fix
// [Severity]  	Normal
// [RootCause]  	BootOrder and DriverOrder cases are not handled preoperly
// in _PopupSelGetSelection() function
// [Files]  		PopupSel.c
// 
// 30    9/17/12 6:20a Rajashakerg
// Updated EIP changes for 2.16 release.
// 
// 28    9/06/12 1:02a Rajashakerg
// [TAG]  		EIP91410 
// [Category]  	Improvement
// [Description]  	TSE_MULTILINE_CONTROLS=1 makes one of option with max
// string looks not good.
// [Files]  		PopupSel.c, COmmonHelper.c, AMITSE.sdl
// 
// 27    2/01/12 8:05p Blaines
// [TAG] - EIP 81631 
// [Category]- Sighting
// [Synopsis]- In some SAS cards,  HII Adapter Settings screen is not
// wrapping the text correctly
// [Solution] - Use the proper control width calculation to determine
// control height in PopupSelGetControlHeight.
// The string length calculation used to determine control height in
// SubMenuGetControlHeight needs to be consistent with the same in
// SubMenuDraw.  
// 	
// [Files]
// Submenu.c, PopupSel.c,
// 
// 26    2/01/12 3:33a Arunsb
// [TAG]  		EIP81603 
// [Category]  	Improvement
// [Description]  	If any option is not obtained then default option is
// used
// [Files]  		PopupSel.c
// 
// 25    1/31/12 7:04p Blaines
// [TAG] - EIP 81631 
// [Category]- Sighting
// [Synopsis]- In some SAS cards,  HII Adapter Settings screen is not
// wrapping the text correctly
// [Solution] - Allow max space when creating controls in the functions
// FrameAddControl, FrameDraw.
// Allow max space for computing height in PopupSelGetControlHeight,
// TextGetControlHeight PopupSelDraw, TextDraw.  
// 	
// [Files]
// Text.c, PopupSel.c, frame.c
// 
// 24    1/18/12 6:37a Rajashakerg
// [TAG]  		EIP79949 
// [Category]  	Bug Fix
// [Severity]  	Normal
// [Symptom]  	Text srting is not wrapped in "Advanced -> Super IO config.
// -> Floppy disk controller config. -> Change settings" option when
// TSE_MULTILINE_CONTROLS token enabled.
// [RootCause]  	The calculation was not proper to show maximum string in
// the left control area for popupsel control.
// [Solution]  	Adjusted the cordinates to show maximum string in control
// left area
// [Files]  		PopupSel.c
// 
// 23    1/05/12 12:27a Rajashakerg
// [TAG]  		EIP69104 
// [Category]  	Improvement
// [Description]  	Not to destroy the controls if it is NULL
// [Files]  		control.c, edit.c, Label.c, memo.c, menu.c, ordlistbox.c,
// popup.c, PopupString.c, SubMenu.c, Text.c,PopupSel.c.
// 
// 22    12/07/11 8:18a Rajashakerg
// [TAG]  		EIP75118 
// [Category]  	Improvement
// [Description]  	xtractConfig() fail since BrowserCallback() cannot find
// the variable to process
// [Files]  		FormBrowser2.c, FormBrowser2.h, HiiCallback.c,
// Uefi21Wapper.c, PopupSel.c
// 
// 21    12/05/11 7:05p Blaines
// [TAG] - EIP 77040 
// [Category]- Sighting
// [Synopsis]- Setup: Boot Option Priority list items truncated, until you
// move within the tab.
// [Solution] - In the function PopupSelGetControlHeight, call the
// function _PopupSelGetSelection to get the current selection before
// computing the control height. 
// 	
// [Files]
// PopupSel.c
// 
// 20    11/30/11 1:33p Premkumara
// [TAG]  		EIP75352
// [Category]  	Improvement
// [Description]  	Suppress the warnings from static code analyzer
// [Files]  		Boot.c, bbs.c, TseAdvanced.c, Special.c, Variable.c,
// TseLiteHelper.c, PopupSel.c, AddBootOption.c, Hii.c, FormBrowser2.c
// 
// 19    11/21/11 11:12a Premkumara
// [TAG]  		EIP72610
// [Category]  	Improvement
// [Description]  	Moving TSE_MULTILINE_CONTROLS to Binary
// [Files]  		AMITSE-CommonHelper.c, AMITSE.sdl, 
// TSELITE-UefiAction.c, TseLite.sdl, Time.h, Text.c,
// SubMenu.c, ResetButton.c, PopupString.c, PopupSel.h, PopupSel.c, 
// PopupPassword.c, OrderListBox.c, Numeric.c, Label.c, Frame.c, Edit.c, 
// Date.h, Date.c, 
// LEGACY-Legacy.c,
// BOOTONLY- Minisetup.h
// 
// 18    11/14/11 6:55p Blaines
// [TAG] - EIP 75486 
// [Category]- Function Request
// [Synopsis]- Support grayout condition for readonly controls.
// [Description] - Display readonly controls as grayout, non-selectable.
// [Files]
// AMITSE.sdl, CommonHelper.c, Minisetupext.h, stylecommon.c, Legacy.c,
// date.c, edit.c, label.c, memo.c, menu.c,, numeric.c, ordlistbox.c,
// PopupPassword.c, 
// PopupSel.c, PopupString.c, ResetButton.c, SubMenu.c, Text.c, Time.c,
// UefiAction.c, ctrlcond.c,   
// 
// 17    11/13/11 1:05p Arunsb
// [TAG]  		EIP70421
// [Category]  	New Feature
// [Description]  	Support for driver order in TSE
// [Files]  		AMITSE.SDL, CommonHelper.c, setup.ini, uefisetup.ini,
// boot.c,
// minisetup.h, bbs.c, special.c, special.h, tseadvanced.c,
// addbootoption.c,
// callback.c, minisetupext.c, minisetupext.h, popupsel.c, popupsel.h,
// TseLitehelper.c, variable.c, Uefi21Wapper.c, AMIVfr.h, boot.h,
// TseElink.h, variable.h, 
// setup.h, Boot.vfr and Setup.uni
// 
// 16    10/20/11 12:03p Madhans
// Check in comment corrected.
// 
// 15    9/19/11 11:50a Blaines
// [TAG]  		EIP 68920
// [Category]  	Defect
// [Symptom]  	SOME SAS controller card HII menus hang when selecting "Clear
// Configuration" when DEBUG_MODE=0
// [RootCause]  	Menu is not re-initialize from SetupData after dynamic
// page update. 
// PopupSelGetControlHeight() causes an assert if popupSel has an item
// with an invalid string token.  
// 		
// [Solution]	Due to dynamic updates, SetupData (most current data) is
// given priority when re-initializing menu. 
// Check for invalid string token in PopupSelGetControlHeight.		
// 
// [Files Changed]
// - Menu.c, Popupsel.c
// 
// 14    8/26/11 2:10p Blaines
// [TAG]  		EIP 67487
// [Category]  	Defect
// [Symptom]  	TSE_MULTILINE_CONTROLS does not work for all control types
// [RootCause]  	The controls (PopupSel,  PopupString) ONLY check for
// string wrapping in the label value (control prompt) when calling the
// methods GetControlHeight and Draw. 
// [Solution]	The controls (PopupSel,  PopupString) should check for
// string wrapping in the label (control prompt) and the control's value
// when calling the methods GetControlHeight and Draw. For Dynamic pages,
// adjust the width calculation for Submenu in the function
// GetControlHeight.
// [Files]  		PopupSel.c, PopupString.c, Submenu.c
// 
// 13    3/28/11 11:40p Madhans
// [TAG]  		EIP50878
// [Category]  	Improvement
// [Description]  	Support to move the Control With Boot Order Change.
// [Files]  		AMITSE.sdl
// commonoem.c
// minisetup.h
// popupsel.c
// 
// 12    3/21/11 12:40a Rajashakerg
// [TAG]  		EIP53480
// [Category]  	Improvement
// [Description]  	FormBrowser extended actions support
// [Files]  		callback.c, minisetupext.c, minisetupext.h, numeric.c,
// PopupSel.c, PopupString.c, SubMenu.c, TseLiteCommon.c, UefiAction.c,
// Hiicallback.c, TseUefiHii.h, Uefi21Wapper.c, HiiCallback.c
// 
// 11    3/09/11 7:23p Madhans
// [TAG]  		EIP48615  
// [Category]  	Improvement
// [Description]  	To support UEFI 2.1 RefreshOp. Based in Refersh Rate
// Controls are refershed periodically.
// [Files]  		minisetupext.h
// SubMenu.h
// SubMenu.c
// Memo.c
// Memo.h
// numeric.c
// numeric.h
// time.c
// Date.c
// PopupSel.c
// PopupSel.h
// PopupString.c
// PopupString.h
// ordlistbox.c
// minisetupext.c
// UefiAction.c
// hii.h
// Uefi20wapper.c
// hiicallback.c
// Parse.c
// tseuefihii.h
// Uefi21wapper.c
// 
// 10    12/02/10 6:08p Madhans
// [TAG] - EIP49562    
// [Category]- Improvment.
// [Severity]- Mordarate
// [Symptom]- Need to support UEFI 2.2 requirements related to Calling
// Formcallback with 
// EFI_BROWSER_ACTION_CHANGING and EFI_BROWSER_ACTION_CHANGED action.
// [Solution]- Implemented the support.
// [Files] - submenu.c, numeric.c, popupsel.c, popupString.c,
// uefi20\hii.h, uefi20\uefi20wrapper.c
// uefi21\hiicalback.c, uefi21\tseuefihii.h
// 
// 9     12/02/10 2:34p Madhans
// [TAG] - EIP 48169  
// [Category]- Enhancement
// [Severity]- Mordarate
// [Symptom]- Code Cleanup and Compiler Warning need to resolved.
// [Rootcause] Warnings reported when we build AMI higher Warning level.
// [Solution]- 1. Fix the warnings and do the code cleanup. 
//             2. Introduce proper checks.
//             3. change the popupSel.c to not change the Option/variable
// cache to default or first option
//                when the variable cache is not matching with any of
// option.
// [Files] - commonoem.c bbs.c boot.c hiistring.c resource.c
// popuppassword.c popupsel.c
//           expression.c hii.c parse.c
// 
// 8     6/17/10 2:59p Madhans
// Dynamic parsing support in TSE.
// 
// 7     4/16/10 5:13p Madhans
// Changes for Tse 2.02. Please see Changelog.log for more details.
// 
// 6     3/26/10 5:06p Madhans
// EIP 36704 : Fix for Making sure to make the Variable to NULL after it
// is Freed up.
// 
// 5     2/19/10 1:04p Madhans
// Updated for TSE 2.01. Refer Changelog.log for File change history.
// 
// 11    2/19/10 8:18a Mallikarjunanv
// updated year in copyright message
// 
// 10    2/17/10 7:03p Madhans
// To suppor readonly control
// 
// 9     2/15/10 10:15p Madhans
// To avoid warnings
// 
// 8     2/04/10 11:17p Madhans
// Mouse support related code optimized
// 
// 7     1/09/10 6:57a Mallikarjunanv
// Updated TSE2.01 Release sources with coding standards
// 
// 6     9/15/09 9:48a Sudhirv
// updated the Add Del Boot Option support
// 
// 5     8/13/09 1:20p Blaines
// EIP #24980 Fix to properly display right area text
// 
// 4     8/13/09 7:40a Mallikarjunanv
// eip:24971 - supporting tse features without tse sources
// 
// 3     6/23/09 6:52p Blaines
// Coding standard update, 
// Remove spaces from file header to allow proper chm function list
// creation.
// 
// 2     6/12/09 7:44p Presannar
// Initial implementation of coding standards for AMITSE2.0
// 
// 1     6/04/09 8:05p Madhans
// 
// 1     4/28/09 11:06p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 4     4/28/09 9:40p Madhans
// Tse 2.0 Code complete Checkin.
// 
// 3     3/31/09 4:12p Madhans
// TSE Lite Special control support
// 
// 2     1/30/09 6:06p Madhans
// Function headers added. 
// 
// 1     12/18/08 7:59p Madhans
// Intial version of TSE Lite sources
//*****************************************************************//
//*****************************************************************//

//<AMI_FHDR_START>
//----------------------------------------------------------------------------
//
// Name:		PopupSel.c
//
// Description:	This file contains code to handle Popup selections
//
//----------------------------------------------------------------------------
//<AMI_FHDR_END>

#include "minisetup.h"

BOOLEAN OneofMultilineDisable(POPUPSEL_DATA *popupSel);
VOID _PopupSelGetSelection( POPUPSEL_DATA *popupSel );
static BOOLEAN bSelectionChanged = FALSE;

extern EFI_STATUS _FrameScroll( FRAME_DATA *frame, BOOLEAN bScrollUp );
extern UINT16 _gHDOrderPageID;
extern UINT16 _gCDOrderPageID;
extern UINT16 _gFDOrderPageID;
extern UINT16 _gNetOrderPageID;
extern UINT16 _gBevOrderPageID;

POPUPSEL_METHODS gPopupSel =
{
	PopupSelCreate,
	PopupSelDestroy,
	PopupSelInitialize,
	PopupSelDraw,
	PopupSelHandleAction,
	PopupSelSetCallback,
	PopupSelSetFocus,
	PopupSelSetPosition,
	PopupSelSetDimensions,
	PopupSelSetAttributes,
    PopupSelGetControlHeight
};

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelCreate
//
// Description:	this function uses the create function of control
//					and creates the Popup Selected
//
// Input:	POPUPSEL_DATA **object
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelCreate( POPUPSEL_DATA **object )
{
	EFI_STATUS Status = EFI_OUT_OF_RESOURCES;

	if ( *object == NULL )
	{
		*object = EfiLibAllocateZeroPool( sizeof(POPUPSEL_DATA) );

		if ( *object == NULL )
			return Status;
	}

	Status = gControl.Create( object );
	if ( ! EFI_ERROR(Status) )
		(*object)->Methods = &gPopupSel;

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelDestroy
//
// Description:	this function uses the destroy function of control
//					and destroys the Popup Selected
//
// Input:	POPUPSEL_DATA *popupSel, BOOLEAN freeMem
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelDestroy( POPUPSEL_DATA *popupSel, BOOLEAN freeMem )
{
	if(NULL == popupSel)
	  return EFI_SUCCESS;

	gControl.Destroy( popupSel, FALSE );

	if ( popupSel->ListBoxCtrl )
		gListBox.Destroy( popupSel->ListBoxCtrl, TRUE );

	popupSel->ListBoxCtrl = NULL;

	if( freeMem )
	{
		MemFreePointer( (VOID **)&(popupSel->PtrTokens) );
		MemFreePointer( (VOID **)&popupSel );

	}
	return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelInitialize
//
// Description:	this function uses the initialize function of control
//					and initializes the Popup Selected
//
// Input:	POPUPSEL_DATA *popupSel, VOID *data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelInitialize( POPUPSEL_DATA *popupSel, VOID *data )
{
	EFI_STATUS Status = EFI_UNSUPPORTED;
	UINT16 Index = 0;
	UINT16 *OptionList=NULL;
	UINT64 *ValueList=NULL;


	Status = gControl.Initialize( popupSel, data );
	if (EFI_ERROR(Status))
		return Status;

	popupSel->PopupSelHandle = popupSel->ControlData.ControlHandle;
	popupSel->Title = UefiGetPromptField(popupSel->ControlData.ControlPtr);

	// add extra initialization here...
	Status = UefiGetOneOfOptions(&popupSel->ControlData,&popupSel->PopupSelHandle,
			&OptionList, &ValueList, &popupSel->ItemCount,&popupSel->bInteractive,&popupSel->CallBackKey);

	if (EFI_ERROR(Status))
		return Status;

	popupSel->Interval = (UINT8)(popupSel->ControlData.ControlFlags.ControlRefresh);

	if( popupSel->PtrTokens != NULL )
      MemFreePointer( (VOID **)&(popupSel->PtrTokens));
	popupSel->PtrTokens = EfiLibAllocatePool( popupSel->ItemCount * sizeof(PTRTOKENS) );
	if ( popupSel->PtrTokens == NULL )
		Status = EFI_OUT_OF_RESOURCES;
	else
	{
		for( Index = 0; Index < popupSel->ItemCount; Index++ )
		{
			popupSel->PtrTokens[Index].Option = OptionList[Index];
			popupSel->PtrTokens[Index].Value = ValueList[Index];
		}

	    MemFreePointer( (VOID **)&(OptionList));
	    MemFreePointer( (VOID **)&(ValueList));

		if(popupSel->ControlData.ControlFlags.ControlInteractive)
	    {
			popupSel->bInteractive = TRUE;
			popupSel->CallBackKey = popupSel->ControlData.ControlKey;
		}

	    // boundary overflow  check

		popupSel->ListBoxCtrl = NULL;
		popupSel->ListBoxEnd = FALSE;
		popupSel->LabelMargin = (UINT8)gControlLeftMargin;

		// We dont have to do Get selection here it is done before we draw a page
		//_PopupSelGetSelection( popupSel );

		SetControlColorsHook(&(popupSel->BGColor), &(popupSel->FGColor), NULL, NULL ,&(popupSel->SelBGColor), &(popupSel->SelFGColor),
			                    NULL , &(popupSel->NSelFGColor),NULL,&(popupSel->LabelFGColor) ,
								&(popupSel->NSelLabelFGColor),NULL ,NULL,NULL, NULL );
	
	}

	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelDraw
//
// Description:	function to draw the specific popup window
//
// Input:	POPUPSEL_DATA *popupSel
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelDraw( POPUPSEL_DATA *popupSel )
{
	CHAR16 *text=NULL,*text1=NULL;
	UINTN i=0,Len=0;
	EFI_STATUS Status = EFI_SUCCESS;
	UINT16 Index = 0, TempHeight=0;
	UINT16 *OptionList=NULL;
	UINT64 *ValueList=NULL;
	
	UINT16 tmpHeight=0;

	UINT8 ColorNSel = popupSel->NSelFGColor;
	UINT8 ColorLabel = (popupSel->ControlFocus) ? popupSel->LabelFGColor : popupSel->NSelLabelFGColor ;

	if(  popupSel->ListBoxCtrl != NULL)
	{
		gListBox.Draw( popupSel->ListBoxCtrl );
	}
	else
	{
		// check conditional ptr if necessary
        //EIP 75486 Support grayout condition for readonly controls
		//if( popupSel->ControlData.ControlConditionalPtr != 0x0)
		//{
			switch( CheckControlCondition( &popupSel->ControlData ) )
			{
				case COND_NONE:
					break;
				case COND_GRAYOUT:
					Status = EFI_WARN_WRITE_FAILURE;
					ColorNSel =  ColorLabel = CONTROL_GRAYOUT_COLOR;
					break;
				default:
					return EFI_UNSUPPORTED;
					break;
			}
		//}
		// If not Special
		if(TseLiteIsSpecialOptionList((CONTROL_DATA *)popupSel) != TRUE)
		{
			Status = UefiGetOneOfOptions(&popupSel->ControlData,&popupSel->PopupSelHandle,
					&OptionList, &ValueList, &popupSel->ItemCount,NULL,NULL);
			if (EFI_ERROR(Status))
				return Status;
			for( Index = 0; Index < popupSel->ItemCount; Index++ )
			{
				popupSel->PtrTokens[Index].Option = OptionList[Index];
				popupSel->PtrTokens[Index].Value = ValueList[Index];
			}
			MemFreePointer( (VOID **)&(OptionList));
			MemFreePointer( (VOID **)&(ValueList));
		}

		_PopupSelGetSelection( popupSel );
		text1 = HiiGetString( popupSel->ControlData.ControlHandle, popupSel->Title );
		if ( text1 != NULL )
		{
			//Eip TSE_MULTILINE_CONTROLS moved to binary
			if(popupSel->Height>1 && IsTSEMultilineControlSupported())
			{	
				DrawMultiLineStringWithAttribute( (UINTN)popupSel->Left, (UINTN) popupSel->Top, 
						(UINTN)(popupSel->LabelMargin - popupSel->Left),(UINTN) popupSel->Height,
						text1, popupSel->BGColor |  ColorLabel );
			}
			else
			{
	            // boundary overflow  check
				if((TestPrintLength( text1) / (NG_SIZE))> (UINTN)(popupSel->LabelMargin - popupSel->Left  ))
					text1[HiiFindStrPrintBoundary(text1 ,(UINTN)(popupSel->LabelMargin - popupSel->Left  ))] = L'\0';
	
				DrawStringWithAttribute( popupSel->Left , popupSel->Top, (CHAR16*)text1, 
						popupSel->BGColor |  ColorLabel  );

			}
			MemFreePointer( (VOID **)&text1 );
		}

		/*EfiStrCpy(text, L"[");
		DrawStringWithAttribute( popupSel->Left + popupSel->LabelMargin , popupSel->Top, (CHAR16*)text, 
				(UINT8)( (popupSel->ControlFocus) ? 
						 popupSel->SelBGColor  | popupSel->SelFGColor : 
						  popupSel->BGColor  | ColorNSel ));
*/
	
        text1 = HiiGetString( popupSel->PopupSelHandle, popupSel->PtrTokens[popupSel->Sel].Option);
		//EIP-72610 TSE_MULTILINE_CONTROLS moved to binary
		if(popupSel->Height>1 && OneofMultilineDisable(popupSel))
		{
			TempHeight = popupSel->Height;
			popupSel->Height = 1;
		}
		
		if(popupSel->Height>1 && IsTSEMultilineControlSupported())
		{
			Len = TestPrintLength( text1 ) / (NG_SIZE);
			text = EfiLibAllocateZeroPool( (Len+3)*2 ); 
			SPrint( text,(UINTN)( (Len+3)*2 )/*(popupSel->Width - popupSel->Left - popupSel->LabelMargin +2)*/, L"[%s]", text1 );
			MemFreePointer( (VOID **)&text1 );	

			text1 = StringWrapText( (CHAR16*)text, (popupSel->Width - popupSel->LabelMargin ), &tmpHeight );

			if(tmpHeight == 1)
				DrawStringWithAttribute( popupSel->Left + popupSel->LabelMargin  , popupSel->Top, (CHAR16*)text, 
				(UINT8)( (popupSel->ControlFocus) ? popupSel->SelBGColor  | popupSel->SelFGColor : popupSel->BGColor  | ColorNSel   ));
			else
				DrawMultiLineStringWithAttribute( (UINTN)popupSel->Left + (UINTN)popupSel->LabelMargin, (UINTN) popupSel->Top,
												(UINTN)(popupSel->Width - popupSel->LabelMargin ),(UINTN)&tmpHeight/*popupSel->Height*/, (CHAR16*)text,
												(UINT8)( (popupSel->ControlFocus)? popupSel->SelBGColor  | popupSel->SelFGColor : 
												popupSel->BGColor  | ColorNSel   ));
			
			MemFreePointer( (VOID **)&text1 );

        }
		else
		{

    		if(!text1)
    			text1 = EfiLibAllocateZeroPool(2);
    
    		//MemSet( text, sizeof(text), 0 );
    		Len = TestPrintLength( text1 ) / (NG_SIZE);
    		// XXX: may be broken for wide character languages !!!
    		if ( Len /*StringDisplayLen( text1 )*/ > /*19*/(UINTN)(popupSel->Width + popupSel->Left - popupSel->LabelMargin -4)/*gControlRightAreaWidth*/ ) //EIP 79949 : Adjusted the cordinates to show maximum string in control left area
    		EfiStrCpy(&text1[HiiFindStrPrintBoundary(text1 ,(UINTN)(popupSel->Width + popupSel->Left - popupSel->LabelMargin /*gControlRightAreaWidth*/-7/*16*/))],L"..." );        
    
    
            text = EfiLibAllocateZeroPool( (Len+3)*2 ); 
    		SPrint( text,(UINTN)( (Len+3)*2 )/*(popupSel->Width - popupSel->Left - popupSel->LabelMargin +2)*/, L"[%s]", text1 );
    		MemFreePointer( (VOID **)&text1 );
    		DrawStringWithAttribute( popupSel->Left + popupSel->LabelMargin  , popupSel->Top, (CHAR16*)text, 
    				(UINT8)( (popupSel->ControlFocus) ? 
    						 popupSel->SelBGColor  | popupSel->SelFGColor : 
    						  popupSel->BGColor  | ColorNSel   ));

        }
		
		if((TempHeight > 0) && OneofMultilineDisable(popupSel))
		{
			 popupSel->Height = TempHeight;
		}
  		i=TestPrintLength(text) / (NG_SIZE);
        MemFreePointer( (VOID **)&text );
		/*EfiStrCpy(text, L"]");
		DrawStringWithAttribute( popupSel->Left + popupSel->LabelMargin +i +1, popupSel->Top, (CHAR16*)text, 
				(UINT8)( (popupSel->ControlFocus) ? 
						 popupSel->SelBGColor  | popupSel->SelFGColor : 
						  popupSel->BGColor  | ColorNSel ));
*/
        // erase extra spaces if neccessary
		for(;(UINT16)(popupSel->Left + popupSel->LabelMargin + i) <= (popupSel->Width-1);i++)
			DrawStringWithAttribute( popupSel->Left + popupSel->LabelMargin +i, popupSel->Top, L" ", 
						 popupSel->BGColor  |  ColorNSel );

		FlushLines( popupSel->Top, popupSel->Top+popupSel->Height );
	}

	return Status;

}
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelSetCallback
//
// Description:	Function to handle the PopupString actions
//
// Input:		POPUPSEL_DATA *popupSel, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie 
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelSetCallback( POPUPSEL_DATA *popupSel, OBJECT_DATA *container, OBJECT_CALLBACK callback, VOID *cookie )
{
	return gControl.SetCallback( popupSel, container, callback, cookie );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	DoBootDelBootOption
//
// Description:	Function to delete the boot option
//
// Input:		POPUPSEL_DATA *
//
// Output:		BOOLEAN
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN DoBootDelBootOption (POPUPSEL_DATA *popupSel)
{
    if( popupSel->ControlData.ControlVariable == VARIABLE_ID_DEL_BOOT_OPTION )
    {
        //delete selected option
        BootDelBootOption( (UINT16) popupSel->PtrTokens[popupSel->Sel].Value );

        //Complete redraw
        gApp->CompleteRedraw = TRUE;

        //Variable should not be set so return
        return 1;
    }
	return 0;
}

//EIP70421 & 70422  Support for driver order
//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	DoDriverDelDriverOption
//
// Description:	Function to delete the driver option
//
// Input:		POPUPSEL_DATA *
//
// Output:		BOOLEAN
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
BOOLEAN DoDriverDelDriverOption(POPUPSEL_DATA * popupSel)
{
    if (VARIABLE_ID_DEL_DRIVER_OPTION == popupSel->ControlData.ControlVariable)
    {
        //delete selected option
       	DriverDelDriverOption ((UINT16) popupSel->PtrTokens[popupSel->Sel].Value);

        //Complete redraw
        gApp->CompleteRedraw = TRUE;

        //Variable should not be set so return
        return 1;
    }
	return 0;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	DoPopupSelCallBack
//
// Description:	Callback function of the PopupSel
//
// Input:	POPUPSEL_DATA *popupSel
//
// Output:	void
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID DoPopupSelCallBack(POPUPSEL_DATA **popupSel)
{
//#if SETUP_SUPPORT_ADD_BOOT_OPTION
	if( TseDoBootDelBootOption(*popupSel) )
		return;
//#endif

	if( TseDoDriverDelDriverOption(*popupSel) )			//EIP70421 & 70422  Support for driver order
		return;

    if ( (*popupSel)->Cookie != NULL )
	{
        VOID *ifrData = (VOID *)(*popupSel)->ControlData.ControlPtr;
		CALLBACK_VARIABLE *callbackData = (CALLBACK_VARIABLE *)(*popupSel)->Cookie;

		callbackData->Variable = (*popupSel)->ControlData.ControlVariable;
		callbackData->Offset = UefiGetQuestionOffset(ifrData);
		callbackData->Length = UefiGetWidth(ifrData);
		callbackData->Data = (VOID*)&((*popupSel)->PtrTokens[(*popupSel)->Sel].Value);
	}
	// To support UEFI 2.1.C spec to Not to update the control when Callback fails.
	UefiPreControlUpdate(&((*popupSel)->ControlData));
	(*popupSel)->Callback( (*popupSel)->Container, (*popupSel), (*popupSel)->Cookie );

    if((*popupSel)->bInteractive)
    {   
        EFI_STATUS Status;
		VOID * Handle=(*popupSel)->ControlData.ControlHandle;
		UINT16 Key = (*popupSel)->CallBackKey;
		CONTROL_DATA *Control;

		Status = CallFormCallBack(&((*popupSel)->ControlData),(*popupSel)->CallBackKey,0, AMI_CALLBACK_CONTROL_UPDATE);//EIP-53480: Updated the action to AMI_CALLBACK_CONTROL_UPDATE
		Control = GetUpdatedControlData((CONTROL_DATA*)(*popupSel),(*popupSel)->ControlData.ControlType,Handle,Key);

	
		if(Control == NULL){ // Control deleted ?
			*popupSel = NULL;
             return;
        }
		if(Control != (CONTROL_DATA*)(*popupSel))
			*popupSel = (POPUPSEL_DATA*)Control; //control Updated
    }
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	_PopupSelHandleActionKey
//
// Description:	function to handle the PopupSel Action keys
//
// Input:	POPUPSEL_DATA *popupSel, AMI_EFI_KEY_DATA key
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS _PopupSelHandleActionKeyMouse(POPUPSEL_DATA *popupSel, ACTION_DATA *Data)
{
	EFI_STATUS Status = EFI_UNSUPPORTED;
    CONTROL_ACTION Action=ControlActionUnknown;
	AMI_EFI_KEY_DATA key=Data->Input.Data.AmiKey;

	if(Data->Input.Type == ACTION_TYPE_MOUSE)
	{
		//EIP-123727 check whether MouseTop is within the Height and Width of PopupSel or not
		if((Data->Input.Data.MouseInfo.Top >= (UINT32)popupSel->Top) && (Data->Input.Data.MouseInfo.Top < (UINT32)(popupSel->Top+popupSel->Height)) &&
		   (Data->Input.Data.MouseInfo.Left >= (UINT32)popupSel->Left) && (Data->Input.Data.MouseInfo.Left < (UINT32)(popupSel->Left+popupSel->Width))
		)
		{
			Action = MapControlMouseActionHook(&Data->Input.Data.MouseInfo);
		}
			
	}

	if(Data->Input.Type == ACTION_TYPE_KEY)
 	   Action = MapControlKeysHook(key);

    switch(Action)
    {
        case ControlActionDecreament:
			//Handle special case for boot order & Legacy dev order
			if (
				(VARIABLE_ID_BOOT_ORDER == popupSel->ControlData.ControlVariable) ||
				(VARIABLE_ID_BBS_ORDER == popupSel->ControlData.ControlVariable) ||
				(VARIABLE_ID_DRIVER_ORDER == popupSel->ControlData.ControlVariable)			//EIP70421 & 70422  Support for driver order
				)
			{
				RearrangeBootDriverOrderVariable (popupSel, FALSE);
			}
            else if( ( CheckForAddDelBootOption() ) && 
					 (popupSel->ControlData.ControlVariable == VARIABLE_ID_DEL_BOOT_OPTION ) )
            {
            }
			else
			{
				if ( popupSel->Sel > 0 )
					popupSel->Sel--;
				else
					popupSel->Sel = popupSel->ItemCount - 1;
				DoPopupSelCallBack(&popupSel);
                if(popupSel == NULL)
                    return EFI_SUCCESS;
			}
			Status = EFI_SUCCESS;
        break;

        case ControlActionIncreament:
			//Handle special case for boot order & Legacy dev order
			if (
				(VARIABLE_ID_BOOT_ORDER == popupSel->ControlData.ControlVariable) ||
				(VARIABLE_ID_BBS_ORDER == popupSel->ControlData.ControlVariable) ||
				(VARIABLE_ID_DRIVER_ORDER == popupSel->ControlData.ControlVariable)			//EIP70421 & 70422  Support for driver order
				)
			{
				RearrangeBootDriverOrderVariable (popupSel, TRUE);
			}
            else if( ( CheckForAddDelBootOption() ) && 
					 (popupSel->ControlData.ControlVariable == VARIABLE_ID_DEL_BOOT_OPTION ) )
            {
            }
			else
			{
				if ( popupSel->Sel < (UINTN)(popupSel->ItemCount - 1) )
					popupSel->Sel++;
				else
					popupSel->Sel = 0;
				DoPopupSelCallBack(&popupSel);
                if(popupSel == NULL)
                    return EFI_SUCCESS;
			}
			Status = EFI_SUCCESS;
        break;

        case ControlActionSelect:
			if ( gListBox.Create( &(popupSel->ListBoxCtrl) ) == EFI_SUCCESS )
			{
				popupSel->ControlActive = TRUE;
				gListBox.Initialize( popupSel->ListBoxCtrl, &(popupSel->ControlData) );
				if(TseLiteIsSpecialOptionList((CONTROL_DATA *)popupSel) == TRUE)
				{
					UINT16 TempLength=0, i;
					//Need fix the ListBox options
					for( i = 0 ; i < popupSel->ItemCount; i++ )
					{
						popupSel->ListBoxCtrl->PtrTokens[i] = popupSel->PtrTokens[i].Option;
						TempLength = (UINT16)HiiMyGetStringLength( popupSel->ListBoxCtrl->ListHandle, popupSel->ListBoxCtrl->PtrTokens[i] );
						TempLength+=5; // to included barders
						if ( TempLength > popupSel->ListBoxCtrl->Width )
							popupSel->ListBoxCtrl->Width = TempLength;
					}

				}
		
				if(popupSel->ListBoxCtrl->Width > (UINT16)(gMaxCols-5))
					popupSel->ListBoxCtrl->Width = (UINT16)(gMaxCols-5);
				popupSel->ListBoxCtrl->Sel = popupSel->Sel;
				gListBox.SetCallback(popupSel->ListBoxCtrl, popupSel,  _PopupSelCallback, NULL);
				
				MouseStop();

				gListBox.Draw( popupSel->ListBoxCtrl );

				MouseRefresh();
			} 
			Status = EFI_SUCCESS; 
        break;

        default:
        break;
    }
    return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelHandleAction
//
// Description:	function to handle the PopupSel Actions
//
// Input:	POPUPSEL_DATA *popupSel, ACTION_DATA *Data
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelHandleAction( POPUPSEL_DATA *popupSel, ACTION_DATA *Data)
{
	EFI_STATUS Status = EFI_UNSUPPORTED;
    UINT8 u8ChkResult;

	if ( Data->Input.Type == ACTION_TYPE_TIMER )
	{
		// List box is active don't refresh
		if ( popupSel->ListBoxCtrl != NULL )
			return Status;

		if (popupSel->Interval == 0)
			return Status;

		if(IsActiveControlPresent(gApp->PageList[gApp->CurrentPage]))
			return Status;
		
		if ( --(popupSel->Interval) == 0 )
		{
			// initialize the interval
			popupSel->Interval = (UINT8)(popupSel->ControlData.ControlFlags.ControlRefresh);
			return UefiRefershQuestionValueNvRAM(&(popupSel->ControlData));
		}
		else
			return Status;
	}

    u8ChkResult = CheckControlCondition( &popupSel->ControlData );
	 
    //Not to perform action for control when token TSE_SETUP_GRAYOUT_SELECTABLE is enable to set focus for GrayoutIf control
    if ( IsGrayoutSelectable() && (COND_GRAYOUT == u8ChkResult) ) {
        return EFI_UNSUPPORTED;
    }

    if(popupSel->ControlData.ControlFlags.ControlReadOnly)
		return EFI_UNSUPPORTED;

	if(!popupSel->ControlFocus)
		return Status;

    if ( popupSel->ListBoxCtrl != NULL )
    {
    	Status = gListBox.HandleAction(popupSel->ListBoxCtrl,Data);
    	if ( popupSel->ListBoxEnd )
    	{
            if(bSelectionChanged)
            {
                if(popupSel->Sel != popupSel->ListBoxCtrl->Sel)
                {
                    popupSel->Sel = popupSel->ListBoxCtrl->Sel;
           			DoPopupSelCallBack(&popupSel);
                    if(popupSel == NULL)
                        return EFI_SUCCESS;

                }
                bSelectionChanged = FALSE;
            }
    
    		gListBox.Destroy(popupSel->ListBoxCtrl,TRUE);
    		popupSel->ListBoxCtrl = NULL;
    		popupSel->ListBoxEnd = FALSE;
    		popupSel->ControlActive = FALSE;
    	}
    }
    else
    {
        if((Data->Input.Type == ACTION_TYPE_KEY) || (Data->Input.Type == ACTION_TYPE_MOUSE))
        {
            return _PopupSelHandleActionKeyMouse(popupSel, Data);
		}
	}
	return Status;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelSetFocus
//
// Description:	Function to set focus
//
// Input:		POPUPSEL_DATA *popupSel, BOOLEAN focus
//
// Output:		Status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelSetFocus(POPUPSEL_DATA *popupSel, BOOLEAN focus)
{
	UINT8 u8ChkResult;
	
	if(focus != FALSE)
	{
		u8ChkResult = CheckControlCondition( &popupSel->ControlData );
        
		//Setting focus to control which has no condtion and token TSE_SETUP_GRAYOUT_SELECTABLE is enable to make GrayoutIf control to focus and selectable
		if (	((u8ChkResult != COND_NONE) && (u8ChkResult != COND_GRAYOUT)) ||
				(!IsGrayoutSelectable() && (u8ChkResult == COND_GRAYOUT))
			){
			return EFI_UNSUPPORTED;
		}
	}

	if( !(popupSel->ControlFocus && focus) )
		popupSel->ControlFocus = focus;

	return EFI_SUCCESS;
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelSetPosition
//
// Description:	Function to set position.
//
// Input:		POPUPSEL_DATA *popupSel, UINT16 Left, UINT16 Top
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelSetPosition(POPUPSEL_DATA *popupSel, UINT16 Left, UINT16 Top )
{
	return gControl.SetPosition( popupSel, Left, Top );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelSetDimensions
//
// Description:	Function to set dimension.
//
// Input:		POPUPSEL_DATA *popupSel, UINT16 Width, UINT16 Height
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelSetDimensions(POPUPSEL_DATA *popupSel, UINT16 Width, UINT16 Height )
{
	return gControl.SetDimensions( popupSel, Width, Height );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelSetAttributes
//
// Description:	Function to set attributes.
//
// Input:		POPUPSEL_DATA *popupSel, UINT8 FGColor, UINT8 BGColor
//
// Output:		STATUS
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelSetAttributes(POPUPSEL_DATA *popupSel, UINT8 FGColor, UINT8 BGColor )
{
	return gControl.SetAttributes( popupSel, FGColor, BGColor );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	_PopupSelCallback
//
// Description:	PopupSel callback function.
//
// Input:		POPUPSEL_DATA *container, CONTROL_DATA *popupSel, VOID *cookie
//
// Output:		VOID
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID _PopupSelCallback( POPUPSEL_DATA *container, CONTROL_DATA *popupSel, VOID *cookie )
{
	container->ListBoxEnd = TRUE;
	if ( cookie != NULL )
    {
        bSelectionChanged = TRUE;
    }
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelHandleAction
//
// Description:	function to handle the PopupSel set and get operations
//
// Input:	POPUPSEL_DATA *popupSel
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID _PopupSelGetSelection( POPUPSEL_DATA *popupSel )
{
	VOID *temp;
	VOID *ifrData = popupSel->ControlData.ControlPtr;
	int i=0;
	EFI_STATUS Status = EFI_SUCCESS;
	
	popupSel->Sel = 0;
	temp = EfiLibAllocateZeroPool( 8 * 2 );
	if ( temp == NULL )
		return;

	if ( VarGetValue( popupSel->ControlData.ControlVariable, UefiGetQuestionOffset(ifrData), UefiGetWidth(ifrData), temp ) == EFI_SUCCESS )
	{
		while( i< popupSel->ItemCount)
		{
			if(popupSel->PtrTokens[i].Value == *(UINT64 *)temp)
			{
				popupSel->Sel = (UINT16)i;
		        break;
			}
			i++;
		}
		if( i == popupSel->ItemCount)
		{
			//EIP92783 Boot order and driver order are special controls, so TSE is forming the one of with the current boot/driver options.
			//So no need of checking error case.
			if ( (VARIABLE_ID_BOOT_ORDER == popupSel->ControlData.ControlVariable) || (VARIABLE_ID_DRIVER_ORDER == popupSel->ControlData.ControlVariable) )
			{												
				popupSel->Sel = 0;
			}
			else
			{
			// The data does not correspond to the available selections
				if(popupSel->ControlData.ControlDataWidth != 0)					//Uncommented for EIP81603 One-of forced to new value but new value not passed to RouteConfig
				{
					//Try to set selection to the default option
					 VarGetDefaults( popupSel->ControlData.ControlVariable, 
											   UefiGetQuestionOffset(popupSel->ControlData.ControlPtr),
											   popupSel->ControlData.ControlDataWidth, temp );
	
					 i=0;
	     			while( i< popupSel->ItemCount)
					{
	               if(popupSel->PtrTokens[i].Value == *(UINT16 *)temp)
						{
	                  popupSel->Sel = (UINT16)i;
							Status = VarSetValue( popupSel->ControlData.ControlVariable, 
										UefiGetQuestionOffset(popupSel->ControlData.ControlPtr),
							     		(UefiGetWidth(popupSel->ControlData.ControlPtr) > sizeof(UINT16) )?sizeof(UINT16):UefiGetWidth(popupSel->ControlData.ControlPtr),
										temp );
							break;
						}
						i++;
					}
				}
				if( (i == popupSel->ItemCount) || (EFI_ERROR(Status)) )
				{
					//Try to set selection to the option with smallest value
					UINT16 TempoptIndex = 0; //holds index of option with smalleset value
					i = 0;
					while (i< popupSel->ItemCount)			//Trying for least option
					{
						if (popupSel->PtrTokens [i].Value < popupSel->PtrTokens [TempoptIndex].Value)
						{
							TempoptIndex = (UINT16)i;
						}
						i++;
					}
					popupSel->Sel = (UINT16)TempoptIndex; // if nothing else works, revert to the option with smallest value
					Status = VarSetValue (popupSel->ControlData.ControlVariable, 
						UefiGetQuestionOffset (popupSel->ControlData.ControlPtr),
						(UefiGetWidth (popupSel->ControlData.ControlPtr) > sizeof (UINT16)) ? sizeof (UINT16) : UefiGetWidth (popupSel->ControlData.ControlPtr),
						&(popupSel->PtrTokens[TempoptIndex].Value) );
				}
				// either case (found default, reverted to first value)we have changed the variable so notify application
			}
		}
	}
	MemFreePointer( (VOID **)&temp );
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	RearrangeBootDriverOrderVariable
//
// Description:	Function to rearrange the boot/driver order variables
//
// Input:	POPUPSEL_DATA *popupSel, UINT8 bIncrease
//
// Output:	void
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID RearrangeBootDriverOrderVariable (POPUPSEL_DATA *popupSel, UINT8 bIncrease)
{
    UINTN optionNumber,size;
    UINT16 newOption, *optionList = NULL;
    VOID *ifrData = popupSel->ControlData.ControlPtr;
    FRAME_DATA *MainFrame = NULL ;
	UINTN OptionCount = 0;

    MainFrame = gApp->PageList[gApp->CurrentPage]->FrameList[StyleFrameIndexOf(MAIN_FRAME)];
    //Find newOption
    if (
		(VARIABLE_ID_BOOT_ORDER == popupSel->ControlData.ControlVariable) ||
		(VARIABLE_ID_DRIVER_ORDER == popupSel->ControlData.ControlVariable)		//EIP70421 & 70422  Support for driver order
		 )
    {
		(VARIABLE_ID_BOOT_ORDER == popupSel->ControlData.ControlVariable) ? (OptionCount = gBootOptionCount) : (OptionCount = gDriverOptionCount);
        optionNumber = UefiGetQuestionOffset (ifrData) / sizeof(UINT16);
        size = 0;
        optionList = (UINT16 *)VarGetVariable (popupSel->ControlData.ControlVariable, &size);
		//EIP-75352 Suppress the warnings from static code analyzer
        if (NULL == optionList){
            return;
        }

        if(optionList[optionNumber] == DISABLED_BOOT_OPTION)
            newOption = DISABLED_BOOT_OPTION;
        else
        {
            if(bIncrease)
            {
                if(0 == optionNumber)
                {
                    //MAY CHANGE: cant increase priority further
                    newOption = optionList [optionNumber];
                }
                else
                {
                    newOption = optionList [optionNumber - 1];
                    //EIP:50878
                    if (IsUpdateBootOrderCursor ())
                        _FrameScroll (MainFrame, TRUE);
                }
            }
            else
            {
                if ( (optionNumber+1) >= OptionCount )
                {
                    //MAY CHANGE: cant decrease priority further
                    newOption = optionList [optionNumber];
                }
                else if ( DISABLED_BOOT_OPTION == optionList[optionNumber+1] )
                {
                    //MAY CHANGE: cant decrease priority further
                    newOption = optionList [optionNumber];
                }
                else
                {
                    newOption = optionList [optionNumber + 1];
                    //EIP:50878
                    if (IsUpdateBootOrderCursor ())
                        _FrameScroll ( MainFrame, FALSE);
                }
            }
        }

        //Free Optionlist
        MemFreePointer((VOID **) &optionList);
    }
//#if TSE_CSM_SUPPORT
    else if(popupSel->ControlData.ControlVariable == VARIABLE_ID_BBS_ORDER)
    {
		CsmRearrangeBBSOrderVariable(popupSel, bIncrease, &newOption);
    }
//#endif //TSE_CSM_SUPPORT

    //Call callback to the container to record this change in gVariableList(cached copy)
	if ( popupSel->Cookie != NULL )
	{
		CALLBACK_VARIABLE *callbackData = (CALLBACK_VARIABLE *)popupSel->Cookie;

		callbackData->Variable = popupSel->ControlData.ControlVariable;
		callbackData->Offset = UefiGetQuestionOffset(ifrData);
		callbackData->Length = UefiGetWidth(ifrData);
		callbackData->Data = (VOID *)&newOption;
		
		popupSel->Callback( popupSel->Container, popupSel, popupSel->Cookie );
	}
}

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	RearrangeBBSOrderVariable
//
// Description:	Function to reorder the BBS order variable
//
// Input:	POPUPSEL_DATA *popupSel, UINT8 bIncrease,UINT16 *newOption
//
// Output:	void
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID RearrangeBBSOrderVariable(POPUPSEL_DATA *popupSel, UINT8 bIncrease,UINT16 *newOption)
{
    UINTN optionNumber,size;
    UINT16 *optionList = NULL;
    VOID *ifrData = popupSel->ControlData.ControlPtr;
    UINT8 *pDevOrder;
    UINT16 count = 0;
    UINTN offset = UefiGetQuestionOffset(ifrData);
    FRAME_DATA *MainFrame = NULL ;
    MainFrame = gApp->PageList[gApp->CurrentPage]->FrameList[StyleFrameIndexOf(MAIN_FRAME)];

    size = 0;
    pDevOrder = VarGetVariable( VARIABLE_ID_BBS_ORDER, &size );

    offset -= (sizeof(UINT32) + sizeof(UINT16));

    count = gCurrLegacyBootData->LegacyDevCount;
    offset -= gCurrLegacyBootData->LegacyEntryOffset;
    optionList = (UINT16 *)(pDevOrder + gCurrLegacyBootData->LegacyEntryOffset + sizeof(UINT32) + sizeof(UINT16));

    optionNumber = offset / sizeof(UINT16);

    if(optionList[optionNumber] == DISABLED_BOOT_OPTION)
        *newOption = DISABLED_BOOT_OPTION;
    else
    {
        if(bIncrease)
        {
            if(0 == optionNumber)
            {
                //MAY CHANGE: cant increase priority further
                *newOption = optionList[optionNumber];
            }
            else
            {
                *newOption = optionList[optionNumber - 1];
                //EIP:50878
                if(IsUpdateBootOrderCursor())
                    _FrameScroll( MainFrame, TRUE);
            }
            
        }
        else
        {
            if( (optionNumber+1) >= count )
            {
                //MAY CHANGE: cant decrease priority further
                *newOption = optionList[optionNumber];
            }
            else if( DISABLED_BOOT_OPTION == optionList[optionNumber+1] )
            {
                //MAY CHANGE: cant decrease priority further
                *newOption = optionList[optionNumber];
            }
            else
            {
                *newOption = optionList[optionNumber + 1];
                //EIP:50878
                if(IsUpdateBootOrderCursor())
                    _FrameScroll( MainFrame, FALSE);
            }
        }
    }
    //Free Order
    MemFreePointer((VOID **) &pDevOrder);
}

//EIP81603 Starts
//<AMI_PHDR_START>
//----------------------------------------------------------------------------------------------------------------------
// Procedure:		_GetPopUpSelectionFromVariable
//
// Description:	Fucntion to return the current selection based on the variable. If not matched with variable value
//						Selection will be 0	
//
// Input:			POPUPSEL_DATA *
//
// Output:			VOID
//
//-----------------------------------------------------------------------------------------------------------------------
//<AMI_PHDR_END>
VOID _GetPopUpSelectionFromVariable (POPUPSEL_DATA *popupSel)
{
	VOID *temp;
	VOID *ifrData = popupSel->ControlData.ControlPtr;
	int i = 0;
	
	popupSel->Sel = 0;
	temp = EfiLibAllocateZeroPool (8 * 2);
   if (NULL == temp)
		return;
	
	if (VarGetValue (popupSel->ControlData.ControlVariable, UefiGetQuestionOffset (ifrData), UefiGetWidth (ifrData), temp) == EFI_SUCCESS)
	{
		while (i< popupSel->ItemCount)
		{
			if (popupSel->PtrTokens [i].Value == *(UINT64 *)temp)
			{
				popupSel->Sel = (UINT16)i;
				break;
			}
			i++;
		}
	}
}
//EIP81603 Ends

//<AMI_PHDR_START>
//----------------------------------------------------------------------------
// Procedure:	PopupSelGetControlHeight
//
// Description:	function to get the height of the label
//
// Input:	POPUPSEL_DATA *popupSel,Frame, UINT16 *height
//
// Output:	status
//
//----------------------------------------------------------------------------
//<AMI_PHDR_END>
EFI_STATUS PopupSelGetControlHeight(POPUPSEL_DATA *popupSel,VOID * frame, UINT16 *height)
{
	//EIP-72610 TSE_MULTILINE_CONTROLS moved to binary
	if(IsTSEMultilineControlSupported())
	{
		CHAR16 *text=NULL, *text1=NULL, *newtext=NULL ;
		UINT16 Width ;
		UINT16 tmpHeight=0;
		UINTN Len=0;
	
		UINT16 Index = 0;
		UINT16 *OptionList=NULL;
		UINT64 *ValueList=NULL;
		EFI_STATUS Status = EFI_UNSUPPORTED;
	
		
	    if(TseLiteIsSpecialOptionList((CONTROL_DATA *)popupSel) != TRUE)
		{
			Status = UefiGetOneOfOptions(&popupSel->ControlData,&popupSel->PopupSelHandle,
					&OptionList, &ValueList, &popupSel->ItemCount,NULL,NULL);
			if (EFI_ERROR(Status))
				return Status;
			for( Index = 0; Index < popupSel->ItemCount; Index++ )
			{
				popupSel->PtrTokens[Index].Option = OptionList[Index];
				popupSel->PtrTokens[Index].Value = ValueList[Index];
			}
			MemFreePointer( (VOID **)&(OptionList));
			MemFreePointer( (VOID **)&(ValueList));
		}

		Width = (UINT16)(popupSel->LabelMargin - (((FRAME_DATA*)frame)->FrameData.Left + (UINT8)gLabelLeftMargin));
	
		*height = 1 ;

//        _PopupSelGetSelection( popupSel );					//EIP81603 One-of forced to new value but new value not passed to RouteConfig
		_GetPopUpSelectionFromVariable (popupSel);			//In _PopupSelGetSelection fnc, boot manager variable behaving wrongly so introduced _GetPopUpSelectionFromVariable fnc 
																			//to read simply value from variable and set the option and not setting any value to variable
	
		text1 = HiiGetString( popupSel->PopupSelHandle, popupSel->PtrTokens[popupSel->Sel].Option);
	
		//EIP 68920: Check for invalid string token    
	    if (text1 != NULL)
	    {
	        //Len = TestPrintLength( text1 ) / (NG_SIZE);
			Len = (3 + (TestPrintLength( text1 ) / (NG_SIZE))) * sizeof(CHAR16);
			
		    text = EfiLibAllocateZeroPool(Len); 
			newtext = EfiLibAllocateZeroPool(Len);

			if ( text == NULL || newtext == NULL)
		    	return EFI_OUT_OF_RESOURCES;

			MemCpy(newtext, text1, Len);	
			
			SPrint( text,(UINTN)( Len ), L"[%s]", newtext );
		    
			MemFreePointer( (VOID **)&text1 );
			MemFreePointer( (VOID **)&newtext );		
	
		    text1 = StringWrapText( (CHAR16*)text, (UINT16)(((FRAME_DATA *)frame)->FrameData.Width - gLabelLeftMargin - 2 - popupSel->LabelMargin), &tmpHeight );
		    MemFreePointer( (VOID **)&text1 );	
				
		    *height = tmpHeight;
	
		    MemFreePointer( (VOID **)&text );
	    }
	    
	    text = HiiGetString( popupSel->ControlData.ControlHandle, popupSel->Title ) ;
	
	    if(text == NULL)
	        return EFI_OUT_OF_RESOURCES;
	    
		text1 = StringWrapText(text, Width, &tmpHeight );
		
		if ((tmpHeight >= 1) && ( OneofMultilineDisable(popupSel)))
		{
			*height = tmpHeight;
		}
		else if(tmpHeight > *height)
			*height = tmpHeight;
	
		(*height) = (*height) ? (*height):1;
		    
		MemFreePointer( (VOID **)&text );
	    MemFreePointer( (VOID **)&text1 );
	}
	
	else
	{
		*height = 1;
	}
	return EFI_SUCCESS;
}
BOOLEAN TseSuppressOneofMultilineSupport(VOID);
BOOLEAN OneofMultilineDisable(POPUPSEL_DATA *popupSel)
{
	if((UefiIsOneOfControl(popupSel->ControlData.ControlPtr))&&(TseSuppressOneofMultilineSupport()))
	{
		return TRUE;
	}	
	
	return FALSE;
}
//**********************************************************************
//**********************************************************************
//**                                                                  **
//**        (C)Copyright 1985-2011, American Megatrends, Inc.         **
//**                                                                  **
//**                       All Rights Reserved.                       **
//**                                                                  **
//**     5555 Oakbrook Pkwy, Building 200,Norcross, Georgia 30093     **
//**                                                                  **
//**                       Phone: (770)-246-8600                      **
//**                                                                  **
//**********************************************************************
//**********************************************************************