ProcessOptions.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617
  1. /** @file
  2. Implementation for handling the User Interface option processing.
  3. Copyright (c) 2004 - 2020, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "FormDisplay.h"
  7. #define MAX_TIME_OUT_LEN 0x10
  8. /**
  9. Concatenate a narrow string to another string.
  10. @param Destination The destination string.
  11. @param DestMax The Max length of destination string.
  12. @param Source The source string. The string to be concatenated.
  13. to the end of Destination.
  14. **/
  15. VOID
  16. NewStrCat (
  17. IN OUT CHAR16 *Destination,
  18. IN UINTN DestMax,
  19. IN CHAR16 *Source
  20. )
  21. {
  22. UINTN Length;
  23. for (Length = 0; Destination[Length] != 0; Length++) {
  24. }
  25. //
  26. // We now have the length of the original string
  27. // We can safely assume for now that we are concatenating a narrow value to this string.
  28. // For instance, the string is "XYZ" and cat'ing ">"
  29. // If this assumption changes, we need to make this routine a bit more complex
  30. //
  31. Destination[Length] = NARROW_CHAR;
  32. Length++;
  33. StrCpyS (Destination + Length, DestMax - Length, Source);
  34. }
  35. /**
  36. Get UINT64 type value.
  37. @param Value Input Hii value.
  38. @retval UINT64 Return the UINT64 type value.
  39. **/
  40. UINT64
  41. HiiValueToUINT64 (
  42. IN EFI_HII_VALUE *Value
  43. )
  44. {
  45. UINT64 RetVal;
  46. RetVal = 0;
  47. switch (Value->Type) {
  48. case EFI_IFR_TYPE_NUM_SIZE_8:
  49. RetVal = Value->Value.u8;
  50. break;
  51. case EFI_IFR_TYPE_NUM_SIZE_16:
  52. RetVal = Value->Value.u16;
  53. break;
  54. case EFI_IFR_TYPE_NUM_SIZE_32:
  55. RetVal = Value->Value.u32;
  56. break;
  57. case EFI_IFR_TYPE_BOOLEAN:
  58. RetVal = Value->Value.b;
  59. break;
  60. case EFI_IFR_TYPE_DATE:
  61. RetVal = *(UINT64 *)&Value->Value.date;
  62. break;
  63. case EFI_IFR_TYPE_TIME:
  64. RetVal = (*(UINT64 *)&Value->Value.time) & 0xffffff;
  65. break;
  66. default:
  67. RetVal = Value->Value.u64;
  68. break;
  69. }
  70. return RetVal;
  71. }
  72. /**
  73. Check whether this value type can be transfer to EFI_IFR_TYPE_BUFFER type.
  74. EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to
  75. EFI_IFR_TYPE_BUFFER when do the value compare.
  76. @param Value Expression value to compare on.
  77. @retval TRUE This value type can be transter to EFI_IFR_TYPE_BUFFER type.
  78. @retval FALSE This value type can't be transter to EFI_IFR_TYPE_BUFFER type.
  79. **/
  80. BOOLEAN
  81. IsTypeInBuffer (
  82. IN EFI_HII_VALUE *Value
  83. )
  84. {
  85. switch (Value->Type) {
  86. case EFI_IFR_TYPE_BUFFER:
  87. case EFI_IFR_TYPE_DATE:
  88. case EFI_IFR_TYPE_TIME:
  89. case EFI_IFR_TYPE_REF:
  90. return TRUE;
  91. default:
  92. return FALSE;
  93. }
  94. }
  95. /**
  96. Check whether this value type can be transfer to EFI_IFR_TYPE_UINT64
  97. @param Value Expression value to compare on.
  98. @retval TRUE This value type can be transter to EFI_IFR_TYPE_BUFFER type.
  99. @retval FALSE This value type can't be transter to EFI_IFR_TYPE_BUFFER type.
  100. **/
  101. BOOLEAN
  102. IsTypeInUINT64 (
  103. IN EFI_HII_VALUE *Value
  104. )
  105. {
  106. switch (Value->Type) {
  107. case EFI_IFR_TYPE_NUM_SIZE_8:
  108. case EFI_IFR_TYPE_NUM_SIZE_16:
  109. case EFI_IFR_TYPE_NUM_SIZE_32:
  110. case EFI_IFR_TYPE_NUM_SIZE_64:
  111. case EFI_IFR_TYPE_BOOLEAN:
  112. return TRUE;
  113. default:
  114. return FALSE;
  115. }
  116. }
  117. /**
  118. Return the buffer length and buffer pointer for this value.
  119. EFI_IFR_TYPE_REF, EFI_IFR_TYPE_DATE and EFI_IFR_TYPE_TIME are converted to
  120. EFI_IFR_TYPE_BUFFER when do the value compare.
  121. @param Value Expression value to compare on.
  122. @param Buf Return the buffer pointer.
  123. @param BufLen Return the buffer length.
  124. **/
  125. VOID
  126. GetBufAndLenForValue (
  127. IN EFI_HII_VALUE *Value,
  128. OUT UINT8 **Buf,
  129. OUT UINT16 *BufLen
  130. )
  131. {
  132. switch (Value->Type) {
  133. case EFI_IFR_TYPE_BUFFER:
  134. *Buf = Value->Buffer;
  135. *BufLen = Value->BufferLen;
  136. break;
  137. case EFI_IFR_TYPE_DATE:
  138. *Buf = (UINT8 *)(&Value->Value.date);
  139. *BufLen = (UINT16)sizeof (EFI_HII_DATE);
  140. break;
  141. case EFI_IFR_TYPE_TIME:
  142. *Buf = (UINT8 *)(&Value->Value.time);
  143. *BufLen = (UINT16)sizeof (EFI_HII_TIME);
  144. break;
  145. case EFI_IFR_TYPE_REF:
  146. *Buf = (UINT8 *)(&Value->Value.ref);
  147. *BufLen = (UINT16)sizeof (EFI_HII_REF);
  148. break;
  149. default:
  150. *Buf = NULL;
  151. *BufLen = 0;
  152. }
  153. }
  154. /**
  155. Compare two Hii value.
  156. @param Value1 Expression value to compare on left-hand.
  157. @param Value2 Expression value to compare on right-hand.
  158. @param Result Return value after compare.
  159. retval 0 Two operators equal.
  160. return Positive value if Value1 is greater than Value2.
  161. retval Negative value if Value1 is less than Value2.
  162. @param HiiHandle Only required for string compare.
  163. @retval other Could not perform compare on two values.
  164. @retval EFI_SUCCESS Compare the value success.
  165. **/
  166. EFI_STATUS
  167. CompareHiiValue (
  168. IN EFI_HII_VALUE *Value1,
  169. IN EFI_HII_VALUE *Value2,
  170. OUT INTN *Result,
  171. IN EFI_HII_HANDLE HiiHandle OPTIONAL
  172. )
  173. {
  174. INT64 Temp64;
  175. CHAR16 *Str1;
  176. CHAR16 *Str2;
  177. UINTN Len;
  178. UINT8 *Buf1;
  179. UINT16 Buf1Len;
  180. UINT8 *Buf2;
  181. UINT16 Buf2Len;
  182. if ((Value1->Type == EFI_IFR_TYPE_STRING) && (Value2->Type == EFI_IFR_TYPE_STRING)) {
  183. if ((Value1->Value.string == 0) || (Value2->Value.string == 0)) {
  184. //
  185. // StringId 0 is reserved
  186. //
  187. return EFI_INVALID_PARAMETER;
  188. }
  189. if (Value1->Value.string == Value2->Value.string) {
  190. *Result = 0;
  191. return EFI_SUCCESS;
  192. }
  193. Str1 = GetToken (Value1->Value.string, HiiHandle);
  194. if (Str1 == NULL) {
  195. //
  196. // String not found
  197. //
  198. return EFI_NOT_FOUND;
  199. }
  200. Str2 = GetToken (Value2->Value.string, HiiHandle);
  201. if (Str2 == NULL) {
  202. FreePool (Str1);
  203. return EFI_NOT_FOUND;
  204. }
  205. *Result = StrCmp (Str1, Str2);
  206. FreePool (Str1);
  207. FreePool (Str2);
  208. return EFI_SUCCESS;
  209. }
  210. //
  211. // Take types(date, time, ref, buffer) as buffer
  212. //
  213. if (IsTypeInBuffer (Value1) && IsTypeInBuffer (Value2)) {
  214. GetBufAndLenForValue (Value1, &Buf1, &Buf1Len);
  215. GetBufAndLenForValue (Value2, &Buf2, &Buf2Len);
  216. Len = Buf1Len > Buf2Len ? Buf2Len : Buf1Len;
  217. *Result = CompareMem (Buf1, Buf2, Len);
  218. if ((*Result == 0) && (Buf1Len != Buf2Len)) {
  219. //
  220. // In this case, means base on samll number buffer, the data is same
  221. // So which value has more data, which value is bigger.
  222. //
  223. *Result = Buf1Len > Buf2Len ? 1 : -1;
  224. }
  225. return EFI_SUCCESS;
  226. }
  227. //
  228. // Take remain types(integer, boolean, date/time) as integer
  229. //
  230. if (IsTypeInUINT64 (Value1) && IsTypeInUINT64 (Value2)) {
  231. Temp64 = HiiValueToUINT64 (Value1) - HiiValueToUINT64 (Value2);
  232. if (Temp64 > 0) {
  233. *Result = 1;
  234. } else if (Temp64 < 0) {
  235. *Result = -1;
  236. } else {
  237. *Result = 0;
  238. }
  239. return EFI_SUCCESS;
  240. }
  241. return EFI_UNSUPPORTED;
  242. }
  243. /**
  244. Search an Option of a Question by its value.
  245. @param Question The Question
  246. @param OptionValue Value for Option to be searched.
  247. @retval Pointer Pointer to the found Option.
  248. @retval NULL Option not found.
  249. **/
  250. DISPLAY_QUESTION_OPTION *
  251. ValueToOption (
  252. IN FORM_DISPLAY_ENGINE_STATEMENT *Question,
  253. IN EFI_HII_VALUE *OptionValue
  254. )
  255. {
  256. LIST_ENTRY *Link;
  257. DISPLAY_QUESTION_OPTION *Option;
  258. INTN Result;
  259. EFI_HII_VALUE Value;
  260. Link = GetFirstNode (&Question->OptionListHead);
  261. while (!IsNull (&Question->OptionListHead, Link)) {
  262. Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  263. ZeroMem (&Value, sizeof (EFI_HII_VALUE));
  264. Value.Type = Option->OptionOpCode->Type;
  265. CopyMem (&Value.Value, &Option->OptionOpCode->Value, Option->OptionOpCode->Header.Length - OFFSET_OF (EFI_IFR_ONE_OF_OPTION, Value));
  266. if ((CompareHiiValue (&Value, OptionValue, &Result, NULL) == EFI_SUCCESS) && (Result == 0)) {
  267. return Option;
  268. }
  269. Link = GetNextNode (&Question->OptionListHead, Link);
  270. }
  271. return NULL;
  272. }
  273. /**
  274. Return data element in an Array by its Index.
  275. @param Array The data array.
  276. @param Type Type of the data in this array.
  277. @param Index Zero based index for data in this array.
  278. @retval Value The data to be returned
  279. **/
  280. UINT64
  281. GetArrayData (
  282. IN VOID *Array,
  283. IN UINT8 Type,
  284. IN UINTN Index
  285. )
  286. {
  287. UINT64 Data;
  288. ASSERT (Array != NULL);
  289. Data = 0;
  290. switch (Type) {
  291. case EFI_IFR_TYPE_NUM_SIZE_8:
  292. Data = (UINT64)*(((UINT8 *)Array) + Index);
  293. break;
  294. case EFI_IFR_TYPE_NUM_SIZE_16:
  295. Data = (UINT64)*(((UINT16 *)Array) + Index);
  296. break;
  297. case EFI_IFR_TYPE_NUM_SIZE_32:
  298. Data = (UINT64)*(((UINT32 *)Array) + Index);
  299. break;
  300. case EFI_IFR_TYPE_NUM_SIZE_64:
  301. Data = (UINT64)*(((UINT64 *)Array) + Index);
  302. break;
  303. default:
  304. break;
  305. }
  306. return Data;
  307. }
  308. /**
  309. Set value of a data element in an Array by its Index.
  310. @param Array The data array.
  311. @param Type Type of the data in this array.
  312. @param Index Zero based index for data in this array.
  313. @param Value The value to be set.
  314. **/
  315. VOID
  316. SetArrayData (
  317. IN VOID *Array,
  318. IN UINT8 Type,
  319. IN UINTN Index,
  320. IN UINT64 Value
  321. )
  322. {
  323. ASSERT (Array != NULL);
  324. switch (Type) {
  325. case EFI_IFR_TYPE_NUM_SIZE_8:
  326. *(((UINT8 *)Array) + Index) = (UINT8)Value;
  327. break;
  328. case EFI_IFR_TYPE_NUM_SIZE_16:
  329. *(((UINT16 *)Array) + Index) = (UINT16)Value;
  330. break;
  331. case EFI_IFR_TYPE_NUM_SIZE_32:
  332. *(((UINT32 *)Array) + Index) = (UINT32)Value;
  333. break;
  334. case EFI_IFR_TYPE_NUM_SIZE_64:
  335. *(((UINT64 *)Array) + Index) = (UINT64)Value;
  336. break;
  337. default:
  338. break;
  339. }
  340. }
  341. /**
  342. Check whether this value already in the array, if yes, return the index.
  343. @param Array The data array.
  344. @param Type Type of the data in this array.
  345. @param Value The value to be find.
  346. @param Index The index in the array which has same value with Value.
  347. @retval TRUE Found the value in the array.
  348. @retval FALSE Not found the value.
  349. **/
  350. BOOLEAN
  351. FindArrayData (
  352. IN VOID *Array,
  353. IN UINT8 Type,
  354. IN UINT64 Value,
  355. OUT UINTN *Index OPTIONAL
  356. )
  357. {
  358. UINTN Count;
  359. UINT64 TmpValue;
  360. UINT64 ValueComp;
  361. ASSERT (Array != NULL);
  362. Count = 0;
  363. TmpValue = 0;
  364. switch (Type) {
  365. case EFI_IFR_TYPE_NUM_SIZE_8:
  366. ValueComp = (UINT8)Value;
  367. break;
  368. case EFI_IFR_TYPE_NUM_SIZE_16:
  369. ValueComp = (UINT16)Value;
  370. break;
  371. case EFI_IFR_TYPE_NUM_SIZE_32:
  372. ValueComp = (UINT32)Value;
  373. break;
  374. case EFI_IFR_TYPE_NUM_SIZE_64:
  375. ValueComp = (UINT64)Value;
  376. break;
  377. default:
  378. ValueComp = 0;
  379. break;
  380. }
  381. while ((TmpValue = GetArrayData (Array, Type, Count)) != 0) {
  382. if (ValueComp == TmpValue) {
  383. if (Index != NULL) {
  384. *Index = Count;
  385. }
  386. return TRUE;
  387. }
  388. Count++;
  389. }
  390. return FALSE;
  391. }
  392. /**
  393. Print Question Value according to it's storage width and display attributes.
  394. @param Question The Question to be printed.
  395. @param FormattedNumber Buffer for output string.
  396. @param BufferSize The FormattedNumber buffer size in bytes.
  397. @retval EFI_SUCCESS Print success.
  398. @retval EFI_BUFFER_TOO_SMALL Buffer size is not enough for formatted number.
  399. **/
  400. EFI_STATUS
  401. PrintFormattedNumber (
  402. IN FORM_DISPLAY_ENGINE_STATEMENT *Question,
  403. IN OUT CHAR16 *FormattedNumber,
  404. IN UINTN BufferSize
  405. )
  406. {
  407. INT64 Value;
  408. CHAR16 *Format;
  409. EFI_HII_VALUE *QuestionValue;
  410. EFI_IFR_NUMERIC *NumericOp;
  411. if (BufferSize < (21 * sizeof (CHAR16))) {
  412. return EFI_BUFFER_TOO_SMALL;
  413. }
  414. QuestionValue = &Question->CurrentValue;
  415. NumericOp = (EFI_IFR_NUMERIC *)Question->OpCode;
  416. Value = (INT64)QuestionValue->Value.u64;
  417. switch (NumericOp->Flags & EFI_IFR_DISPLAY) {
  418. case EFI_IFR_DISPLAY_INT_DEC:
  419. switch (QuestionValue->Type) {
  420. case EFI_IFR_NUMERIC_SIZE_1:
  421. Value = (INT64)((INT8)QuestionValue->Value.u8);
  422. break;
  423. case EFI_IFR_NUMERIC_SIZE_2:
  424. Value = (INT64)((INT16)QuestionValue->Value.u16);
  425. break;
  426. case EFI_IFR_NUMERIC_SIZE_4:
  427. Value = (INT64)((INT32)QuestionValue->Value.u32);
  428. break;
  429. case EFI_IFR_NUMERIC_SIZE_8:
  430. default:
  431. break;
  432. }
  433. if (Value < 0) {
  434. Value = -Value;
  435. Format = L"-%ld";
  436. } else {
  437. Format = L"%ld";
  438. }
  439. break;
  440. case EFI_IFR_DISPLAY_UINT_DEC:
  441. Format = L"%ld";
  442. break;
  443. case EFI_IFR_DISPLAY_UINT_HEX:
  444. Format = L"%lx";
  445. break;
  446. default:
  447. return EFI_UNSUPPORTED;
  448. }
  449. UnicodeSPrint (FormattedNumber, BufferSize, Format, Value);
  450. return EFI_SUCCESS;
  451. }
  452. /**
  453. Draw a pop up windows based on the dimension, number of lines and
  454. strings specified.
  455. @param RequestedWidth The width of the pop-up.
  456. @param NumberOfLines The number of lines.
  457. @param Marker The variable argument list for the list of string to be printed.
  458. **/
  459. VOID
  460. CreateSharedPopUp (
  461. IN UINTN RequestedWidth,
  462. IN UINTN NumberOfLines,
  463. IN VA_LIST Marker
  464. )
  465. {
  466. UINTN Index;
  467. UINTN Count;
  468. CHAR16 Character;
  469. UINTN Start;
  470. UINTN End;
  471. UINTN Top;
  472. UINTN Bottom;
  473. CHAR16 *String;
  474. UINTN DimensionsWidth;
  475. UINTN DimensionsHeight;
  476. DimensionsWidth = gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn;
  477. DimensionsHeight = gStatementDimensions.BottomRow - gStatementDimensions.TopRow;
  478. gST->ConOut->SetAttribute (gST->ConOut, GetPopupColor ());
  479. if ((RequestedWidth + 2) > DimensionsWidth) {
  480. RequestedWidth = DimensionsWidth - 2;
  481. }
  482. //
  483. // Subtract the PopUp width from total Columns, allow for one space extra on
  484. // each end plus a border.
  485. //
  486. Start = (DimensionsWidth - RequestedWidth - 2) / 2 + gStatementDimensions.LeftColumn + 1;
  487. End = Start + RequestedWidth + 1;
  488. Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + gStatementDimensions.TopRow - 1;
  489. Bottom = Top + NumberOfLines + 2;
  490. Character = BOXDRAW_DOWN_RIGHT;
  491. PrintCharAt (Start, Top, Character);
  492. Character = BOXDRAW_HORIZONTAL;
  493. for (Index = Start; Index + 2 < End; Index++) {
  494. PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
  495. }
  496. Character = BOXDRAW_DOWN_LEFT;
  497. PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
  498. Character = BOXDRAW_VERTICAL;
  499. Count = 0;
  500. for (Index = Top; Index + 2 < Bottom; Index++, Count++) {
  501. String = VA_ARG (Marker, CHAR16 *);
  502. //
  503. // This will clear the background of the line - we never know who might have been
  504. // here before us. This differs from the next clear in that it used the non-reverse
  505. // video for normal printing.
  506. //
  507. if (GetStringWidth (String) / 2 > 1) {
  508. ClearLines (Start, End, Index + 1, Index + 1, GetPopupColor ());
  509. }
  510. //
  511. // Passing in a space results in the assumption that this is where typing will occur
  512. //
  513. if (String[0] == L' ') {
  514. ClearLines (Start + 1, End - 1, Index + 1, Index + 1, GetPopupInverseColor ());
  515. }
  516. //
  517. // Passing in a NULL results in a blank space
  518. //
  519. if (String[0] == CHAR_NULL) {
  520. ClearLines (Start, End, Index + 1, Index + 1, GetPopupColor ());
  521. }
  522. PrintStringAt (
  523. ((DimensionsWidth - GetStringWidth (String) / 2) / 2) + gStatementDimensions.LeftColumn + 1,
  524. Index + 1,
  525. String
  526. );
  527. gST->ConOut->SetAttribute (gST->ConOut, GetPopupColor ());
  528. PrintCharAt (Start, Index + 1, Character);
  529. PrintCharAt (End - 1, Index + 1, Character);
  530. }
  531. Character = BOXDRAW_UP_RIGHT;
  532. PrintCharAt (Start, Bottom - 1, Character);
  533. Character = BOXDRAW_HORIZONTAL;
  534. for (Index = Start; Index + 2 < End; Index++) {
  535. PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
  536. }
  537. Character = BOXDRAW_UP_LEFT;
  538. PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
  539. }
  540. /**
  541. Draw a pop up windows based on the dimension, number of lines and
  542. strings specified.
  543. @param RequestedWidth The width of the pop-up.
  544. @param NumberOfLines The number of lines.
  545. @param ... A series of text strings that displayed in the pop-up.
  546. **/
  547. VOID
  548. EFIAPI
  549. CreateMultiStringPopUp (
  550. IN UINTN RequestedWidth,
  551. IN UINTN NumberOfLines,
  552. ...
  553. )
  554. {
  555. VA_LIST Marker;
  556. VA_START (Marker, NumberOfLines);
  557. CreateSharedPopUp (RequestedWidth, NumberOfLines, Marker);
  558. VA_END (Marker);
  559. }
  560. /**
  561. Process nothing.
  562. @param Event The Event need to be process
  563. @param Context The context of the event.
  564. **/
  565. VOID
  566. EFIAPI
  567. EmptyEventProcess (
  568. IN EFI_EVENT Event,
  569. IN VOID *Context
  570. )
  571. {
  572. }
  573. /**
  574. Process for the refresh interval statement.
  575. @param Event The Event need to be process
  576. @param Context The context of the event.
  577. **/
  578. VOID
  579. EFIAPI
  580. RefreshTimeOutProcess (
  581. IN EFI_EVENT Event,
  582. IN VOID *Context
  583. )
  584. {
  585. WARNING_IF_CONTEXT *EventInfo;
  586. CHAR16 TimeOutString[MAX_TIME_OUT_LEN];
  587. EventInfo = (WARNING_IF_CONTEXT *)Context;
  588. if (*(EventInfo->TimeOut) == 0) {
  589. gBS->CloseEvent (Event);
  590. gBS->SignalEvent (EventInfo->SyncEvent);
  591. return;
  592. }
  593. UnicodeSPrint (TimeOutString, MAX_TIME_OUT_LEN, L"%d", *(EventInfo->TimeOut));
  594. CreateDialog (NULL, gEmptyString, EventInfo->ErrorInfo, gPressEnter, gEmptyString, TimeOutString, NULL);
  595. *(EventInfo->TimeOut) -= 1;
  596. }
  597. /**
  598. Display error message for invalid password.
  599. **/
  600. VOID
  601. PasswordInvalid (
  602. VOID
  603. )
  604. {
  605. EFI_INPUT_KEY Key;
  606. //
  607. // Invalid password, prompt error message
  608. //
  609. do {
  610. CreateDialog (&Key, gEmptyString, gPassowordInvalid, gPressEnter, gEmptyString, NULL);
  611. } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
  612. }
  613. /**
  614. Process password op code.
  615. @param MenuOption The menu for current password op code.
  616. @retval EFI_SUCCESS Question Option process success.
  617. @retval Other Question Option process fail.
  618. **/
  619. EFI_STATUS
  620. PasswordProcess (
  621. IN UI_MENU_OPTION *MenuOption
  622. )
  623. {
  624. CHAR16 *StringPtr;
  625. CHAR16 *TempString;
  626. UINTN Maximum;
  627. EFI_STATUS Status;
  628. EFI_IFR_PASSWORD *PasswordInfo;
  629. FORM_DISPLAY_ENGINE_STATEMENT *Question;
  630. EFI_INPUT_KEY Key;
  631. Question = MenuOption->ThisTag;
  632. PasswordInfo = (EFI_IFR_PASSWORD *)Question->OpCode;
  633. Maximum = PasswordInfo->MaxSize;
  634. Status = EFI_SUCCESS;
  635. StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));
  636. ASSERT (StringPtr);
  637. //
  638. // Use a NULL password to test whether old password is required
  639. //
  640. *StringPtr = 0;
  641. Status = Question->PasswordCheck (gFormData, Question, StringPtr);
  642. if ((Status == EFI_NOT_AVAILABLE_YET) || (Status == EFI_UNSUPPORTED)) {
  643. //
  644. // Password can't be set now.
  645. //
  646. if (Status == EFI_UNSUPPORTED) {
  647. do {
  648. CreateDialog (&Key, gEmptyString, gPasswordUnsupported, gPressEnter, gEmptyString, NULL);
  649. } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
  650. }
  651. FreePool (StringPtr);
  652. return EFI_SUCCESS;
  653. }
  654. if (EFI_ERROR (Status)) {
  655. //
  656. // Old password exist, ask user for the old password
  657. //
  658. Status = ReadString (MenuOption, gPromptForPassword, StringPtr);
  659. if (EFI_ERROR (Status)) {
  660. ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));
  661. FreePool (StringPtr);
  662. return Status;
  663. }
  664. //
  665. // Check user input old password
  666. //
  667. Status = Question->PasswordCheck (gFormData, Question, StringPtr);
  668. if (EFI_ERROR (Status)) {
  669. if (Status == EFI_NOT_READY) {
  670. //
  671. // Typed in old password incorrect
  672. //
  673. PasswordInvalid ();
  674. } else {
  675. Status = EFI_SUCCESS;
  676. }
  677. ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));
  678. FreePool (StringPtr);
  679. return Status;
  680. }
  681. }
  682. //
  683. // Ask for new password
  684. //
  685. ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));
  686. Status = ReadString (MenuOption, gPromptForNewPassword, StringPtr);
  687. if (EFI_ERROR (Status)) {
  688. //
  689. // Reset state machine for password
  690. //
  691. Question->PasswordCheck (gFormData, Question, NULL);
  692. ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));
  693. FreePool (StringPtr);
  694. return Status;
  695. }
  696. //
  697. // Confirm new password
  698. //
  699. TempString = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));
  700. ASSERT (TempString);
  701. Status = ReadString (MenuOption, gConfirmPassword, TempString);
  702. if (EFI_ERROR (Status)) {
  703. //
  704. // Reset state machine for password
  705. //
  706. Question->PasswordCheck (gFormData, Question, NULL);
  707. ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));
  708. ZeroMem (TempString, (Maximum + 1) * sizeof (CHAR16));
  709. FreePool (StringPtr);
  710. FreePool (TempString);
  711. return Status;
  712. }
  713. //
  714. // Compare two typed-in new passwords
  715. //
  716. if (StrCmp (StringPtr, TempString) == 0) {
  717. gUserInput->InputValue.Buffer = AllocateCopyPool (Question->CurrentValue.BufferLen, StringPtr);
  718. gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;
  719. gUserInput->InputValue.Type = Question->CurrentValue.Type;
  720. gUserInput->InputValue.Value.string = HiiSetString (gFormData->HiiHandle, gUserInput->InputValue.Value.string, StringPtr, NULL);
  721. Status = EFI_SUCCESS;
  722. } else {
  723. //
  724. // Reset state machine for password
  725. //
  726. Question->PasswordCheck (gFormData, Question, NULL);
  727. //
  728. // Two password mismatch, prompt error message
  729. //
  730. do {
  731. CreateDialog (&Key, gEmptyString, gConfirmError, gPressEnter, gEmptyString, NULL);
  732. } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
  733. Status = EFI_INVALID_PARAMETER;
  734. }
  735. ZeroMem (TempString, (Maximum + 1) * sizeof (CHAR16));
  736. ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));
  737. FreePool (TempString);
  738. FreePool (StringPtr);
  739. return Status;
  740. }
  741. /**
  742. Print some debug message about mismatched menu info.
  743. @param MenuOption The MenuOption for this Question.
  744. **/
  745. VOID
  746. PrintMismatchMenuInfo (
  747. IN UI_MENU_OPTION *MenuOption
  748. )
  749. {
  750. CHAR16 *FormTitleStr;
  751. CHAR16 *FormSetTitleStr;
  752. CHAR16 *OneOfOptionStr;
  753. CHAR16 *QuestionName;
  754. LIST_ENTRY *Link;
  755. FORM_DISPLAY_ENGINE_STATEMENT *Question;
  756. EFI_IFR_ORDERED_LIST *OrderList;
  757. UINT8 Index;
  758. EFI_HII_VALUE HiiValue;
  759. EFI_HII_VALUE *QuestionValue;
  760. DISPLAY_QUESTION_OPTION *Option;
  761. UINT8 *ValueArray;
  762. UINT8 ValueType;
  763. EFI_IFR_FORM_SET *FormsetBuffer;
  764. UINTN FormsetBufferSize;
  765. Question = MenuOption->ThisTag;
  766. if (!EFI_ERROR (HiiGetFormSetFromHiiHandle (gFormData->HiiHandle, &FormsetBuffer, &FormsetBufferSize))) {
  767. FormSetTitleStr = GetToken (FormsetBuffer->FormSetTitle, gFormData->HiiHandle);
  768. FormTitleStr = GetToken (gFormData->FormTitle, gFormData->HiiHandle);
  769. DEBUG ((DEBUG_ERROR, "\n[%a]: Mismatch Formset : Formset Guid = %g, FormSet title = %s\n", gEfiCallerBaseName, &gFormData->FormSetGuid, FormSetTitleStr));
  770. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Form : FormId = %d, Form title = %s.\n", gEfiCallerBaseName, gFormData->FormId, FormTitleStr));
  771. }
  772. if (Question->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) {
  773. QuestionName = GetToken (((EFI_IFR_ORDERED_LIST *)MenuOption->ThisTag->OpCode)->Question.Header.Prompt, gFormData->HiiHandle);
  774. Link = GetFirstNode (&Question->OptionListHead);
  775. Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  776. ValueType = Option->OptionOpCode->Type;
  777. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Error : OrderedList value in the array doesn't match with option value.\n", gEfiCallerBaseName));
  778. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OrderedList: Name = %s.\n", gEfiCallerBaseName, QuestionName));
  779. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OrderedList: OrderedList array value :\n", gEfiCallerBaseName));
  780. OrderList = (EFI_IFR_ORDERED_LIST *)Question->OpCode;
  781. for (Index = 0; Index < OrderList->MaxContainers; Index++) {
  782. ValueArray = Question->CurrentValue.Buffer;
  783. HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);
  784. DEBUG ((DEBUG_ERROR, " Value[%d] =%ld.\n", Index, HiiValue.Value.u64));
  785. }
  786. } else if (Question->OpCode->OpCode == EFI_IFR_ONE_OF_OP) {
  787. QuestionName = GetToken (((EFI_IFR_ONE_OF *)MenuOption->ThisTag->OpCode)->Question.Header.Prompt, gFormData->HiiHandle);
  788. QuestionValue = &Question->CurrentValue;
  789. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch Error : OneOf value doesn't match with option value.\n", gEfiCallerBaseName));
  790. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OneOf : Name = %s.\n", gEfiCallerBaseName, QuestionName));
  791. switch (QuestionValue->Type) {
  792. case EFI_IFR_TYPE_NUM_SIZE_64:
  793. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OneOf : OneOf value = %ld.\n", gEfiCallerBaseName, QuestionValue->Value.u64));
  794. break;
  795. case EFI_IFR_TYPE_NUM_SIZE_32:
  796. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OneOf : OneOf value = %d.\n", gEfiCallerBaseName, QuestionValue->Value.u32));
  797. break;
  798. case EFI_IFR_TYPE_NUM_SIZE_16:
  799. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OneOf : OneOf value = %d.\n", gEfiCallerBaseName, QuestionValue->Value.u16));
  800. break;
  801. case EFI_IFR_TYPE_NUM_SIZE_8:
  802. DEBUG ((DEBUG_ERROR, "[%a]: Mismatch OneOf : OneOf value = %d.\n", gEfiCallerBaseName, QuestionValue->Value.u8));
  803. break;
  804. default:
  805. ASSERT (FALSE);
  806. break;
  807. }
  808. }
  809. Index = 0;
  810. Link = GetFirstNode (&Question->OptionListHead);
  811. while (!IsNull (&Question->OptionListHead, Link)) {
  812. Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  813. OneOfOptionStr = GetToken (Option->OptionOpCode->Option, gFormData->HiiHandle);
  814. switch (Option->OptionOpCode->Type) {
  815. case EFI_IFR_TYPE_NUM_SIZE_64:
  816. DEBUG ((DEBUG_ERROR, "[%a]: Option %d : Option Value = %ld, Option Name = %s.\n", gEfiCallerBaseName, Index, Option->OptionOpCode->Value.u64, OneOfOptionStr));
  817. break;
  818. case EFI_IFR_TYPE_NUM_SIZE_32:
  819. DEBUG ((DEBUG_ERROR, "[%a]: Option %d : Option Value = %d, Option Name = %s.\n", gEfiCallerBaseName, Index, Option->OptionOpCode->Value.u32, OneOfOptionStr));
  820. break;
  821. case EFI_IFR_TYPE_NUM_SIZE_16:
  822. DEBUG ((DEBUG_ERROR, "[%a]: Option %d : Option Value = %d, Option Name = %s.\n", gEfiCallerBaseName, Index, Option->OptionOpCode->Value.u16, OneOfOptionStr));
  823. break;
  824. case EFI_IFR_TYPE_NUM_SIZE_8:
  825. DEBUG ((DEBUG_ERROR, "[%a]: Option %d : Option Value = %d, Option Name = %s.\n", gEfiCallerBaseName, Index, Option->OptionOpCode->Value.u8, OneOfOptionStr));
  826. break;
  827. default:
  828. ASSERT (FALSE);
  829. break;
  830. }
  831. Link = GetNextNode (&Question->OptionListHead, Link);
  832. Index++;
  833. }
  834. }
  835. /**
  836. Process a Question's Option (whether selected or un-selected).
  837. @param MenuOption The MenuOption for this Question.
  838. @param Selected TRUE: if Question is selected.
  839. @param OptionString Pointer of the Option String to be displayed.
  840. @param SkipErrorValue Whether need to return when value without option for it.
  841. @retval EFI_SUCCESS Question Option process success.
  842. @retval Other Question Option process fail.
  843. **/
  844. EFI_STATUS
  845. ProcessOptions (
  846. IN UI_MENU_OPTION *MenuOption,
  847. IN BOOLEAN Selected,
  848. OUT CHAR16 **OptionString,
  849. IN BOOLEAN SkipErrorValue
  850. )
  851. {
  852. EFI_STATUS Status;
  853. CHAR16 *StringPtr;
  854. UINTN Index;
  855. FORM_DISPLAY_ENGINE_STATEMENT *Question;
  856. CHAR16 FormattedNumber[21];
  857. UINT16 Number;
  858. CHAR16 Character[2];
  859. EFI_INPUT_KEY Key;
  860. UINTN BufferSize;
  861. DISPLAY_QUESTION_OPTION *OneOfOption;
  862. LIST_ENTRY *Link;
  863. EFI_HII_VALUE HiiValue;
  864. EFI_HII_VALUE *QuestionValue;
  865. DISPLAY_QUESTION_OPTION *Option;
  866. UINTN Index2;
  867. UINT8 *ValueArray;
  868. UINT8 ValueType;
  869. EFI_IFR_ORDERED_LIST *OrderList;
  870. BOOLEAN ValueInvalid;
  871. UINTN MaxLen;
  872. Status = EFI_SUCCESS;
  873. StringPtr = NULL;
  874. Character[1] = L'\0';
  875. *OptionString = NULL;
  876. ValueInvalid = FALSE;
  877. ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));
  878. BufferSize = (gOptionBlockWidth + 1) * 2 * gStatementDimensions.BottomRow;
  879. Question = MenuOption->ThisTag;
  880. QuestionValue = &Question->CurrentValue;
  881. switch (Question->OpCode->OpCode) {
  882. case EFI_IFR_ORDERED_LIST_OP:
  883. //
  884. // Check whether there are Options of this OrderedList
  885. //
  886. if (IsListEmpty (&Question->OptionListHead)) {
  887. break;
  888. }
  889. OrderList = (EFI_IFR_ORDERED_LIST *)Question->OpCode;
  890. Link = GetFirstNode (&Question->OptionListHead);
  891. OneOfOption = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  892. ValueType = OneOfOption->OptionOpCode->Type;
  893. ValueArray = Question->CurrentValue.Buffer;
  894. if (Selected) {
  895. //
  896. // Go ask for input
  897. //
  898. Status = GetSelectionInputPopUp (MenuOption);
  899. } else {
  900. //
  901. // We now know how many strings we will have, so we can allocate the
  902. // space required for the array or strings.
  903. //
  904. MaxLen = OrderList->MaxContainers * BufferSize / sizeof (CHAR16);
  905. *OptionString = AllocateZeroPool (MaxLen * sizeof (CHAR16));
  906. ASSERT (*OptionString);
  907. HiiValue.Type = ValueType;
  908. HiiValue.Value.u64 = 0;
  909. for (Index = 0; Index < OrderList->MaxContainers; Index++) {
  910. HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);
  911. if (HiiValue.Value.u64 == 0) {
  912. //
  913. // Values for the options in ordered lists should never be a 0
  914. //
  915. break;
  916. }
  917. OneOfOption = ValueToOption (Question, &HiiValue);
  918. if (OneOfOption == NULL) {
  919. //
  920. // Print debug msg for the mistach menu.
  921. //
  922. PrintMismatchMenuInfo (MenuOption);
  923. if (SkipErrorValue) {
  924. //
  925. // Just try to get the option string, skip the value which not has option.
  926. //
  927. continue;
  928. }
  929. //
  930. // Show error message
  931. //
  932. do {
  933. CreateDialog (&Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString, NULL);
  934. } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
  935. //
  936. // The initial value of the orderedlist is invalid, force to be valid value
  937. // Exit current DisplayForm with new value.
  938. //
  939. gUserInput->SelectedStatement = Question;
  940. gMisMatch = TRUE;
  941. ValueArray = AllocateZeroPool (Question->CurrentValue.BufferLen);
  942. ASSERT (ValueArray != NULL);
  943. gUserInput->InputValue.Buffer = ValueArray;
  944. gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;
  945. gUserInput->InputValue.Type = Question->CurrentValue.Type;
  946. Link = GetFirstNode (&Question->OptionListHead);
  947. Index2 = 0;
  948. while (!IsNull (&Question->OptionListHead, Link) && Index2 < OrderList->MaxContainers) {
  949. Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  950. Link = GetNextNode (&Question->OptionListHead, Link);
  951. SetArrayData (ValueArray, ValueType, Index2, Option->OptionOpCode->Value.u64);
  952. Index2++;
  953. }
  954. SetArrayData (ValueArray, ValueType, Index2, 0);
  955. FreePool (*OptionString);
  956. *OptionString = NULL;
  957. return EFI_NOT_FOUND;
  958. }
  959. Character[0] = LEFT_ONEOF_DELIMITER;
  960. NewStrCat (OptionString[0], MaxLen, Character);
  961. StringPtr = GetToken (OneOfOption->OptionOpCode->Option, gFormData->HiiHandle);
  962. ASSERT (StringPtr != NULL);
  963. NewStrCat (OptionString[0], MaxLen, StringPtr);
  964. Character[0] = RIGHT_ONEOF_DELIMITER;
  965. NewStrCat (OptionString[0], MaxLen, Character);
  966. Character[0] = CHAR_CARRIAGE_RETURN;
  967. NewStrCat (OptionString[0], MaxLen, Character);
  968. FreePool (StringPtr);
  969. }
  970. //
  971. // If valid option more than the max container, skip these options.
  972. //
  973. if (Index >= OrderList->MaxContainers) {
  974. break;
  975. }
  976. //
  977. // Search the other options, try to find the one not in the container.
  978. //
  979. Link = GetFirstNode (&Question->OptionListHead);
  980. while (!IsNull (&Question->OptionListHead, Link)) {
  981. OneOfOption = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  982. Link = GetNextNode (&Question->OptionListHead, Link);
  983. if (FindArrayData (ValueArray, ValueType, OneOfOption->OptionOpCode->Value.u64, NULL)) {
  984. continue;
  985. }
  986. //
  987. // Print debug msg for the mistach menu.
  988. //
  989. PrintMismatchMenuInfo (MenuOption);
  990. if (SkipErrorValue) {
  991. //
  992. // Not report error, just get the correct option string info.
  993. //
  994. Character[0] = LEFT_ONEOF_DELIMITER;
  995. NewStrCat (OptionString[0], MaxLen, Character);
  996. StringPtr = GetToken (OneOfOption->OptionOpCode->Option, gFormData->HiiHandle);
  997. ASSERT (StringPtr != NULL);
  998. NewStrCat (OptionString[0], MaxLen, StringPtr);
  999. Character[0] = RIGHT_ONEOF_DELIMITER;
  1000. NewStrCat (OptionString[0], MaxLen, Character);
  1001. Character[0] = CHAR_CARRIAGE_RETURN;
  1002. NewStrCat (OptionString[0], MaxLen, Character);
  1003. FreePool (StringPtr);
  1004. continue;
  1005. }
  1006. if (!ValueInvalid) {
  1007. ValueInvalid = TRUE;
  1008. //
  1009. // Show error message
  1010. //
  1011. do {
  1012. CreateDialog (&Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString, NULL);
  1013. } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
  1014. //
  1015. // The initial value of the orderedlist is invalid, force to be valid value
  1016. // Exit current DisplayForm with new value.
  1017. //
  1018. gUserInput->SelectedStatement = Question;
  1019. gMisMatch = TRUE;
  1020. ValueArray = AllocateCopyPool (Question->CurrentValue.BufferLen, Question->CurrentValue.Buffer);
  1021. ASSERT (ValueArray != NULL);
  1022. gUserInput->InputValue.Buffer = ValueArray;
  1023. gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;
  1024. gUserInput->InputValue.Type = Question->CurrentValue.Type;
  1025. }
  1026. SetArrayData (ValueArray, ValueType, Index++, OneOfOption->OptionOpCode->Value.u64);
  1027. }
  1028. if (ValueInvalid) {
  1029. FreePool (*OptionString);
  1030. *OptionString = NULL;
  1031. return EFI_NOT_FOUND;
  1032. }
  1033. }
  1034. break;
  1035. case EFI_IFR_ONE_OF_OP:
  1036. //
  1037. // Check whether there are Options of this OneOf
  1038. //
  1039. if (IsListEmpty (&Question->OptionListHead)) {
  1040. break;
  1041. }
  1042. if (Selected) {
  1043. //
  1044. // Go ask for input
  1045. //
  1046. Status = GetSelectionInputPopUp (MenuOption);
  1047. } else {
  1048. MaxLen = BufferSize / sizeof (CHAR16);
  1049. *OptionString = AllocateZeroPool (BufferSize);
  1050. ASSERT (*OptionString);
  1051. OneOfOption = ValueToOption (Question, QuestionValue);
  1052. if (OneOfOption == NULL) {
  1053. //
  1054. // Print debug msg for the mistach menu.
  1055. //
  1056. PrintMismatchMenuInfo (MenuOption);
  1057. if (SkipErrorValue) {
  1058. //
  1059. // Not report error, just get the correct option string info.
  1060. //
  1061. Link = GetFirstNode (&Question->OptionListHead);
  1062. OneOfOption = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  1063. } else {
  1064. //
  1065. // Show error message
  1066. //
  1067. do {
  1068. CreateDialog (&Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString, NULL);
  1069. } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
  1070. //
  1071. // Force the Question value to be valid
  1072. // Exit current DisplayForm with new value.
  1073. //
  1074. Link = GetFirstNode (&Question->OptionListHead);
  1075. Option = DISPLAY_QUESTION_OPTION_FROM_LINK (Link);
  1076. gUserInput->InputValue.Type = Option->OptionOpCode->Type;
  1077. switch (gUserInput->InputValue.Type) {
  1078. case EFI_IFR_TYPE_NUM_SIZE_8:
  1079. gUserInput->InputValue.Value.u8 = Option->OptionOpCode->Value.u8;
  1080. break;
  1081. case EFI_IFR_TYPE_NUM_SIZE_16:
  1082. CopyMem (&gUserInput->InputValue.Value.u16, &Option->OptionOpCode->Value.u16, sizeof (UINT16));
  1083. break;
  1084. case EFI_IFR_TYPE_NUM_SIZE_32:
  1085. CopyMem (&gUserInput->InputValue.Value.u32, &Option->OptionOpCode->Value.u32, sizeof (UINT32));
  1086. break;
  1087. case EFI_IFR_TYPE_NUM_SIZE_64:
  1088. CopyMem (&gUserInput->InputValue.Value.u64, &Option->OptionOpCode->Value.u64, sizeof (UINT64));
  1089. break;
  1090. default:
  1091. ASSERT (FALSE);
  1092. break;
  1093. }
  1094. gUserInput->SelectedStatement = Question;
  1095. gMisMatch = TRUE;
  1096. FreePool (*OptionString);
  1097. *OptionString = NULL;
  1098. return EFI_NOT_FOUND;
  1099. }
  1100. }
  1101. Character[0] = LEFT_ONEOF_DELIMITER;
  1102. NewStrCat (OptionString[0], MaxLen, Character);
  1103. StringPtr = GetToken (OneOfOption->OptionOpCode->Option, gFormData->HiiHandle);
  1104. ASSERT (StringPtr != NULL);
  1105. NewStrCat (OptionString[0], MaxLen, StringPtr);
  1106. Character[0] = RIGHT_ONEOF_DELIMITER;
  1107. NewStrCat (OptionString[0], MaxLen, Character);
  1108. FreePool (StringPtr);
  1109. }
  1110. break;
  1111. case EFI_IFR_CHECKBOX_OP:
  1112. if (Selected) {
  1113. //
  1114. // Since this is a BOOLEAN operation, flip it upon selection
  1115. //
  1116. gUserInput->InputValue.Type = QuestionValue->Type;
  1117. gUserInput->InputValue.Value.b = (BOOLEAN)(QuestionValue->Value.b ? FALSE : TRUE);
  1118. //
  1119. // Perform inconsistent check
  1120. //
  1121. return EFI_SUCCESS;
  1122. } else {
  1123. *OptionString = AllocateZeroPool (BufferSize);
  1124. ASSERT (*OptionString);
  1125. *OptionString[0] = LEFT_CHECKBOX_DELIMITER;
  1126. if (QuestionValue->Value.b) {
  1127. *(OptionString[0] + 1) = CHECK_ON;
  1128. } else {
  1129. *(OptionString[0] + 1) = CHECK_OFF;
  1130. }
  1131. *(OptionString[0] + 2) = RIGHT_CHECKBOX_DELIMITER;
  1132. }
  1133. break;
  1134. case EFI_IFR_NUMERIC_OP:
  1135. if (Selected) {
  1136. //
  1137. // Go ask for input
  1138. //
  1139. Status = GetNumericInput (MenuOption);
  1140. } else {
  1141. *OptionString = AllocateZeroPool (BufferSize);
  1142. ASSERT (*OptionString);
  1143. *OptionString[0] = LEFT_NUMERIC_DELIMITER;
  1144. //
  1145. // Formatted print
  1146. //
  1147. PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16));
  1148. Number = (UINT16)GetStringWidth (FormattedNumber);
  1149. CopyMem (OptionString[0] + 1, FormattedNumber, Number);
  1150. *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;
  1151. }
  1152. break;
  1153. case EFI_IFR_DATE_OP:
  1154. if (Selected) {
  1155. //
  1156. // This is similar to numerics
  1157. //
  1158. Status = GetNumericInput (MenuOption);
  1159. } else {
  1160. *OptionString = AllocateZeroPool (BufferSize);
  1161. ASSERT (*OptionString);
  1162. switch (MenuOption->Sequence) {
  1163. case 0:
  1164. *OptionString[0] = LEFT_NUMERIC_DELIMITER;
  1165. if (QuestionValue->Value.date.Month == 0xff) {
  1166. UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"??");
  1167. } else {
  1168. UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Month);
  1169. }
  1170. *(OptionString[0] + 3) = DATE_SEPARATOR;
  1171. break;
  1172. case 1:
  1173. SetUnicodeMem (OptionString[0], 4, L' ');
  1174. if (QuestionValue->Value.date.Day == 0xff) {
  1175. UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"??");
  1176. } else {
  1177. UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Day);
  1178. }
  1179. *(OptionString[0] + 6) = DATE_SEPARATOR;
  1180. break;
  1181. case 2:
  1182. SetUnicodeMem (OptionString[0], 7, L' ');
  1183. if (QuestionValue->Value.date.Year == 0xff) {
  1184. UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"????");
  1185. } else {
  1186. UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%04d", QuestionValue->Value.date.Year);
  1187. }
  1188. *(OptionString[0] + 11) = RIGHT_NUMERIC_DELIMITER;
  1189. break;
  1190. }
  1191. }
  1192. break;
  1193. case EFI_IFR_TIME_OP:
  1194. if (Selected) {
  1195. //
  1196. // This is similar to numerics
  1197. //
  1198. Status = GetNumericInput (MenuOption);
  1199. } else {
  1200. *OptionString = AllocateZeroPool (BufferSize);
  1201. ASSERT (*OptionString);
  1202. switch (MenuOption->Sequence) {
  1203. case 0:
  1204. *OptionString[0] = LEFT_NUMERIC_DELIMITER;
  1205. if (QuestionValue->Value.time.Hour == 0xff) {
  1206. UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"??");
  1207. } else {
  1208. UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Hour);
  1209. }
  1210. *(OptionString[0] + 3) = TIME_SEPARATOR;
  1211. break;
  1212. case 1:
  1213. SetUnicodeMem (OptionString[0], 4, L' ');
  1214. if (QuestionValue->Value.time.Minute == 0xff) {
  1215. UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"??");
  1216. } else {
  1217. UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Minute);
  1218. }
  1219. *(OptionString[0] + 6) = TIME_SEPARATOR;
  1220. break;
  1221. case 2:
  1222. SetUnicodeMem (OptionString[0], 7, L' ');
  1223. if (QuestionValue->Value.time.Second == 0xff) {
  1224. UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"??");
  1225. } else {
  1226. UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Second);
  1227. }
  1228. *(OptionString[0] + 9) = RIGHT_NUMERIC_DELIMITER;
  1229. break;
  1230. }
  1231. }
  1232. break;
  1233. case EFI_IFR_STRING_OP:
  1234. if (Selected) {
  1235. StringPtr = AllocateZeroPool (Question->CurrentValue.BufferLen + sizeof (CHAR16));
  1236. ASSERT (StringPtr);
  1237. CopyMem (StringPtr, Question->CurrentValue.Buffer, Question->CurrentValue.BufferLen);
  1238. Status = ReadString (MenuOption, gPromptForData, StringPtr);
  1239. if (EFI_ERROR (Status)) {
  1240. FreePool (StringPtr);
  1241. return Status;
  1242. }
  1243. gUserInput->InputValue.Buffer = AllocateCopyPool (Question->CurrentValue.BufferLen, StringPtr);
  1244. gUserInput->InputValue.BufferLen = Question->CurrentValue.BufferLen;
  1245. gUserInput->InputValue.Type = Question->CurrentValue.Type;
  1246. gUserInput->InputValue.Value.string = HiiSetString (gFormData->HiiHandle, gUserInput->InputValue.Value.string, StringPtr, NULL);
  1247. FreePool (StringPtr);
  1248. return EFI_SUCCESS;
  1249. } else {
  1250. *OptionString = AllocateZeroPool (BufferSize);
  1251. ASSERT (*OptionString);
  1252. if (((CHAR16 *)Question->CurrentValue.Buffer)[0] == 0x0000) {
  1253. *(OptionString[0]) = '_';
  1254. } else {
  1255. if (Question->CurrentValue.BufferLen < BufferSize) {
  1256. BufferSize = Question->CurrentValue.BufferLen;
  1257. }
  1258. CopyMem (OptionString[0], (CHAR16 *)Question->CurrentValue.Buffer, BufferSize);
  1259. }
  1260. }
  1261. break;
  1262. case EFI_IFR_PASSWORD_OP:
  1263. if (Selected) {
  1264. Status = PasswordProcess (MenuOption);
  1265. }
  1266. break;
  1267. default:
  1268. break;
  1269. }
  1270. return Status;
  1271. }
  1272. /**
  1273. Process the help string: Split StringPtr to several lines of strings stored in
  1274. FormattedString and the glyph width of each line cannot exceed gHelpBlockWidth.
  1275. @param StringPtr The entire help string.
  1276. @param FormattedString The oupput formatted string.
  1277. @param EachLineWidth The max string length of each line in the formatted string.
  1278. @param RowCount TRUE: if Question is selected.
  1279. **/
  1280. UINTN
  1281. ProcessHelpString (
  1282. IN CHAR16 *StringPtr,
  1283. OUT CHAR16 **FormattedString,
  1284. OUT UINT16 *EachLineWidth,
  1285. IN UINTN RowCount
  1286. )
  1287. {
  1288. UINTN Index;
  1289. CHAR16 *OutputString;
  1290. UINTN TotalRowNum;
  1291. UINTN CheckedNum;
  1292. UINT16 GlyphWidth;
  1293. UINT16 LineWidth;
  1294. UINT16 MaxStringLen;
  1295. UINT16 StringLen;
  1296. TotalRowNum = 0;
  1297. CheckedNum = 0;
  1298. GlyphWidth = 1;
  1299. Index = 0;
  1300. MaxStringLen = 0;
  1301. StringLen = 0;
  1302. //
  1303. // Set default help string width.
  1304. //
  1305. LineWidth = (UINT16)(gHelpBlockWidth - 1);
  1306. //
  1307. // Get row number of the String.
  1308. //
  1309. while ((StringLen = GetLineByWidth (StringPtr, LineWidth, &GlyphWidth, &Index, &OutputString)) != 0) {
  1310. if (StringLen > MaxStringLen) {
  1311. MaxStringLen = StringLen;
  1312. }
  1313. TotalRowNum++;
  1314. FreePool (OutputString);
  1315. }
  1316. *EachLineWidth = MaxStringLen;
  1317. *FormattedString = AllocateZeroPool (TotalRowNum * MaxStringLen * sizeof (CHAR16));
  1318. ASSERT (*FormattedString != NULL);
  1319. //
  1320. // Generate formatted help string array.
  1321. //
  1322. GlyphWidth = 1;
  1323. Index = 0;
  1324. while ((StringLen = GetLineByWidth (StringPtr, LineWidth, &GlyphWidth, &Index, &OutputString)) != 0) {
  1325. CopyMem (*FormattedString + CheckedNum * MaxStringLen, OutputString, StringLen * sizeof (CHAR16));
  1326. CheckedNum++;
  1327. FreePool (OutputString);
  1328. }
  1329. return TotalRowNum;
  1330. }