]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
Update HiiBlockToConfig function to follow spec.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / ProcessOptions.c
CommitLineData
c60a0616 1/** @file\r
2Implementation for handling the User Interface option processing.\r
3\r
4\r
f0a1bf11 5Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
e5eed7d3 6This program and the accompanying materials\r
c60a0616 7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
c60a0616 16#include "Setup.h"\r
17\r
18\r
19/**\r
20 Process Question Config.\r
21\r
22 @param Selection The UI menu selection.\r
23 @param Question The Question to be peocessed.\r
24\r
25 @retval EFI_SUCCESS Question Config process success.\r
26 @retval Other Question Config process fail.\r
27\r
28**/\r
29EFI_STATUS\r
30ProcessQuestionConfig (\r
31 IN UI_MENU_SELECTION *Selection,\r
32 IN FORM_BROWSER_STATEMENT *Question\r
33 )\r
34{\r
35 EFI_STATUS Status;\r
36 CHAR16 *ConfigResp;\r
37 CHAR16 *Progress;\r
38 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
39\r
40 if (Question->QuestionConfig == 0) {\r
41 return EFI_SUCCESS;\r
42 }\r
43\r
44 //\r
45 // Get <ConfigResp>\r
46 //\r
47 ConfigResp = GetToken (Question->QuestionConfig, Selection->FormSet->HiiHandle);\r
48 if (ConfigResp == NULL) {\r
49 return EFI_NOT_FOUND;\r
50 }\r
51\r
52 //\r
53 // Send config to Configuration Driver\r
54 //\r
55 ConfigAccess = Selection->FormSet->ConfigAccess;\r
56 if (ConfigAccess == NULL) {\r
57 return EFI_UNSUPPORTED;\r
58 }\r
59 Status = ConfigAccess->RouteConfig (\r
60 ConfigAccess,\r
61 ConfigResp,\r
62 &Progress\r
63 );\r
64\r
65 return Status;\r
66}\r
67\r
68\r
69/**\r
70 Search an Option of a Question by its value.\r
71\r
72 @param Question The Question\r
73 @param OptionValue Value for Option to be searched.\r
74\r
75 @retval Pointer Pointer to the found Option.\r
76 @retval NULL Option not found.\r
77\r
78**/\r
79QUESTION_OPTION *\r
80ValueToOption (\r
81 IN FORM_BROWSER_STATEMENT *Question,\r
82 IN EFI_HII_VALUE *OptionValue\r
83 )\r
84{\r
85 LIST_ENTRY *Link;\r
86 QUESTION_OPTION *Option;\r
87\r
88 Link = GetFirstNode (&Question->OptionListHead);\r
89 while (!IsNull (&Question->OptionListHead, Link)) {\r
90 Option = QUESTION_OPTION_FROM_LINK (Link);\r
91\r
92 if (CompareHiiValue (&Option->Value, OptionValue, NULL) == 0) {\r
93 return Option;\r
94 }\r
95\r
96 Link = GetNextNode (&Question->OptionListHead, Link);\r
97 }\r
98\r
99 return NULL;\r
100}\r
101\r
102\r
d02847d3 103/**\r
104 Return data element in an Array by its Index.\r
105\r
106 @param Array The data array.\r
107 @param Type Type of the data in this array.\r
108 @param Index Zero based index for data in this array.\r
109\r
110 @retval Value The data to be returned\r
111\r
112**/\r
113UINT64\r
114GetArrayData (\r
115 IN VOID *Array,\r
116 IN UINT8 Type,\r
117 IN UINTN Index\r
118 )\r
119{\r
120 UINT64 Data;\r
121\r
122 ASSERT (Array != NULL);\r
123\r
124 Data = 0;\r
125 switch (Type) {\r
126 case EFI_IFR_TYPE_NUM_SIZE_8:\r
127 Data = (UINT64) *(((UINT8 *) Array) + Index);\r
128 break;\r
129\r
130 case EFI_IFR_TYPE_NUM_SIZE_16:\r
131 Data = (UINT64) *(((UINT16 *) Array) + Index);\r
132 break;\r
133\r
134 case EFI_IFR_TYPE_NUM_SIZE_32:\r
135 Data = (UINT64) *(((UINT32 *) Array) + Index);\r
136 break;\r
137\r
138 case EFI_IFR_TYPE_NUM_SIZE_64:\r
139 Data = (UINT64) *(((UINT64 *) Array) + Index);\r
140 break;\r
141\r
142 default:\r
143 break;\r
144 }\r
145\r
146 return Data;\r
147}\r
148\r
149\r
150/**\r
151 Set value of a data element in an Array by its Index.\r
152\r
153 @param Array The data array.\r
154 @param Type Type of the data in this array.\r
155 @param Index Zero based index for data in this array.\r
156 @param Value The value to be set.\r
157\r
158**/\r
159VOID\r
160SetArrayData (\r
161 IN VOID *Array,\r
162 IN UINT8 Type,\r
163 IN UINTN Index,\r
164 IN UINT64 Value\r
165 )\r
166{\r
167\r
168 ASSERT (Array != NULL);\r
169\r
170 switch (Type) {\r
171 case EFI_IFR_TYPE_NUM_SIZE_8:\r
172 *(((UINT8 *) Array) + Index) = (UINT8) Value;\r
173 break;\r
174\r
175 case EFI_IFR_TYPE_NUM_SIZE_16:\r
176 *(((UINT16 *) Array) + Index) = (UINT16) Value;\r
177 break;\r
178\r
179 case EFI_IFR_TYPE_NUM_SIZE_32:\r
180 *(((UINT32 *) Array) + Index) = (UINT32) Value;\r
181 break;\r
182\r
183 case EFI_IFR_TYPE_NUM_SIZE_64:\r
184 *(((UINT64 *) Array) + Index) = (UINT64) Value;\r
185 break;\r
186\r
187 default:\r
188 break;\r
189 }\r
190}\r
191\r
192\r
c60a0616 193/**\r
194 Print Question Value according to it's storage width and display attributes.\r
195\r
196 @param Question The Question to be printed.\r
197 @param FormattedNumber Buffer for output string.\r
198 @param BufferSize The FormattedNumber buffer size in bytes.\r
199\r
200 @retval EFI_SUCCESS Print success.\r
201 @retval EFI_BUFFER_TOO_SMALL Buffer size is not enough for formatted number.\r
202\r
203**/\r
204EFI_STATUS\r
205PrintFormattedNumber (\r
206 IN FORM_BROWSER_STATEMENT *Question,\r
207 IN OUT CHAR16 *FormattedNumber,\r
208 IN UINTN BufferSize\r
209 )\r
210{\r
211 INT64 Value;\r
212 CHAR16 *Format;\r
213 EFI_HII_VALUE *QuestionValue;\r
214\r
215 if (BufferSize < (21 * sizeof (CHAR16))) {\r
216 return EFI_BUFFER_TOO_SMALL;\r
217 }\r
218\r
219 QuestionValue = &Question->HiiValue;\r
220\r
221 Value = (INT64) QuestionValue->Value.u64;\r
222 switch (Question->Flags & EFI_IFR_DISPLAY) {\r
223 case EFI_IFR_DISPLAY_INT_DEC:\r
224 switch (QuestionValue->Type) {\r
225 case EFI_IFR_NUMERIC_SIZE_1:\r
226 Value = (INT64) ((INT8) QuestionValue->Value.u8);\r
227 break;\r
228\r
229 case EFI_IFR_NUMERIC_SIZE_2:\r
230 Value = (INT64) ((INT16) QuestionValue->Value.u16);\r
231 break;\r
232\r
233 case EFI_IFR_NUMERIC_SIZE_4:\r
234 Value = (INT64) ((INT32) QuestionValue->Value.u32);\r
235 break;\r
236\r
237 case EFI_IFR_NUMERIC_SIZE_8:\r
238 default:\r
239 break;\r
240 }\r
241\r
242 if (Value < 0) {\r
243 Value = -Value;\r
244 Format = L"-%ld";\r
245 } else {\r
246 Format = L"%ld";\r
247 }\r
248 break;\r
249\r
250 case EFI_IFR_DISPLAY_UINT_DEC:\r
251 Format = L"%ld";\r
252 break;\r
253\r
254 case EFI_IFR_DISPLAY_UINT_HEX:\r
255 Format = L"%lx";\r
256 break;\r
257\r
258 default:\r
259 return EFI_UNSUPPORTED;\r
260 break;\r
261 }\r
262\r
263 UnicodeSPrint (FormattedNumber, BufferSize, Format, Value);\r
264\r
265 return EFI_SUCCESS;\r
266}\r
267\r
268\r
269/**\r
270 Password may be stored as encrypted by Configuration Driver. When change a\r
271 password, user will be challenged with old password. To validate user input old\r
272 password, we will send the clear text to Configuration Driver via Callback().\r
273 Configuration driver is responsible to check the passed in password and return\r
274 the validation result. If validation pass, state machine in password Callback()\r
275 will transit from BROWSER_STATE_VALIDATE_PASSWORD to BROWSER_STATE_SET_PASSWORD.\r
276 After user type in new password twice, Callback() will be invoked to send the\r
277 new password to Configuration Driver.\r
278\r
279 @param Selection Pointer to UI_MENU_SELECTION.\r
280 @param MenuOption The MenuOption for this password Question.\r
281 @param String The clear text of password.\r
282\r
283 @retval EFI_NOT_AVAILABLE_YET Callback() request to terminate password input.\r
284 @return In state of BROWSER_STATE_VALIDATE_PASSWORD:\r
285 @retval EFI_SUCCESS Password correct, Browser will prompt for new\r
286 password.\r
287 @retval EFI_NOT_READY Password incorrect, Browser will show error\r
288 message.\r
289 @retval Other Browser will do nothing.\r
290 @return In state of BROWSER_STATE_SET_PASSWORD:\r
291 @retval EFI_SUCCESS Set password success.\r
292 @retval Other Set password failed.\r
293\r
294**/\r
295EFI_STATUS\r
296PasswordCallback (\r
297 IN UI_MENU_SELECTION *Selection,\r
298 IN UI_MENU_OPTION *MenuOption,\r
299 IN CHAR16 *String\r
300 )\r
301{\r
302 EFI_STATUS Status;\r
303 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
304 EFI_BROWSER_ACTION_REQUEST ActionRequest;\r
e2100bfa 305 EFI_IFR_TYPE_VALUE IfrTypeValue;\r
c60a0616 306\r
c60a0616 307 ConfigAccess = Selection->FormSet->ConfigAccess;\r
308 if (ConfigAccess == NULL) {\r
309 return EFI_UNSUPPORTED;\r
310 }\r
311\r
312 //\r
313 // Prepare password string in HII database\r
314 //\r
315 if (String != NULL) {\r
e2100bfa 316 IfrTypeValue.string = NewString (String, Selection->FormSet->HiiHandle);\r
c60a0616 317 } else {\r
e2100bfa 318 IfrTypeValue.string = 0;\r
c60a0616 319 }\r
320\r
321 //\r
322 // Send password to Configuration Driver for validation\r
323 //\r
324 Status = ConfigAccess->Callback (\r
325 ConfigAccess,\r
326 EFI_BROWSER_ACTION_CHANGING,\r
327 MenuOption->ThisTag->QuestionId,\r
e2100bfa
ED
328 MenuOption->ThisTag->HiiValue.Type,\r
329 &IfrTypeValue,\r
c60a0616 330 &ActionRequest\r
331 );\r
332\r
333 //\r
334 // Remove password string from HII database\r
335 //\r
336 if (String != NULL) {\r
e2100bfa 337 DeleteString (IfrTypeValue.string, Selection->FormSet->HiiHandle);\r
c60a0616 338 }\r
339\r
340 return Status;\r
341}\r
342\r
343\r
344/**\r
345 Display error message for invalid password.\r
346\r
347**/\r
348VOID\r
349PasswordInvalid (\r
350 VOID\r
351 )\r
352{\r
353 EFI_INPUT_KEY Key;\r
354\r
355 //\r
356 // Invalid password, prompt error message\r
357 //\r
358 do {\r
359 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gPassowordInvalid, gPressEnter, gEmptyString);\r
360 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
361}\r
362\r
363\r
364/**\r
365 Process a Question's Option (whether selected or un-selected).\r
366\r
367 @param Selection Pointer to UI_MENU_SELECTION.\r
368 @param MenuOption The MenuOption for this Question.\r
369 @param Selected TRUE: if Question is selected.\r
370 @param OptionString Pointer of the Option String to be displayed.\r
371\r
372 @retval EFI_SUCCESS Question Option process success.\r
373 @retval Other Question Option process fail.\r
374\r
375**/\r
376EFI_STATUS\r
377ProcessOptions (\r
378 IN UI_MENU_SELECTION *Selection,\r
379 IN UI_MENU_OPTION *MenuOption,\r
380 IN BOOLEAN Selected,\r
381 OUT CHAR16 **OptionString\r
382 )\r
383{\r
384 EFI_STATUS Status;\r
385 CHAR16 *StringPtr;\r
386 CHAR16 *TempString;\r
387 UINTN Index;\r
388 FORM_BROWSER_STATEMENT *Question;\r
389 CHAR16 FormattedNumber[21];\r
390 UINT16 Number;\r
391 CHAR16 Character[2];\r
392 EFI_INPUT_KEY Key;\r
393 UINTN BufferSize;\r
394 QUESTION_OPTION *OneOfOption;\r
395 LIST_ENTRY *Link;\r
396 EFI_HII_VALUE HiiValue;\r
397 EFI_HII_VALUE *QuestionValue;\r
398 BOOLEAN Suppress;\r
399 UINT16 Maximum;\r
8d00a0f1 400 QUESTION_OPTION *Option;\r
401 UINTN Index2;\r
d02847d3 402 UINT8 *ValueArray;\r
403 UINT8 ValueType;\r
e2100bfa 404 EFI_STRING_ID StringId;\r
c60a0616 405\r
406 Status = EFI_SUCCESS;\r
407\r
408 StringPtr = NULL;\r
409 Character[1] = L'\0';\r
410 *OptionString = NULL;\r
e2100bfa 411 StringId = 0;\r
c60a0616 412\r
413 ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));\r
414 BufferSize = (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow;\r
415\r
416 Question = MenuOption->ThisTag;\r
417 QuestionValue = &Question->HiiValue;\r
418 Maximum = (UINT16) Question->Maximum;\r
419\r
d02847d3 420 ValueArray = Question->BufferValue;\r
421 ValueType = Question->ValueType;\r
422\r
c60a0616 423 switch (Question->Operand) {\r
424 case EFI_IFR_ORDERED_LIST_OP:\r
b86b413a
LG
425 //\r
426 // Check whether there are Options of this OrderedList\r
427 //\r
428 if (IsListEmpty (&Question->OptionListHead)) {\r
429 break;\r
430 }\r
c60a0616 431 //\r
432 // Initialize Option value array\r
433 //\r
d02847d3 434 if (GetArrayData (ValueArray, ValueType, 0) == 0) {\r
c60a0616 435 GetQuestionDefault (Selection->FormSet, Selection->Form, Question, 0);\r
436 }\r
437\r
438 if (Selected) {\r
439 //\r
440 // Go ask for input\r
441 //\r
442 Status = GetSelectionInputPopUp (Selection, MenuOption);\r
443 } else {\r
444 //\r
445 // We now know how many strings we will have, so we can allocate the\r
446 // space required for the array or strings.\r
447 //\r
448 *OptionString = AllocateZeroPool (Question->MaxContainers * BufferSize);\r
449 ASSERT (*OptionString);\r
450\r
d02847d3 451 HiiValue.Type = ValueType;\r
c60a0616 452 HiiValue.Value.u64 = 0;\r
453 for (Index = 0; Index < Question->MaxContainers; Index++) {\r
d02847d3 454 HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);\r
455 if (HiiValue.Value.u64 == 0) {\r
c60a0616 456 //\r
457 // Values for the options in ordered lists should never be a 0\r
458 //\r
459 break;\r
460 }\r
461\r
462 OneOfOption = ValueToOption (Question, &HiiValue);\r
463 if (OneOfOption == NULL) {\r
8d00a0f1 464 //\r
465 // Show error message\r
466 //\r
467 do {\r
468 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r
469 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
470\r
471 //\r
472 // The initial value of the orderedlist is invalid, force to be valid value\r
473 //\r
474 Link = GetFirstNode (&Question->OptionListHead);\r
475 Index2 = 0;\r
476 while (!IsNull (&Question->OptionListHead, Link) && Index2 < Question->MaxContainers) {\r
477 Option = QUESTION_OPTION_FROM_LINK (Link);\r
d02847d3 478 SetArrayData (ValueArray, ValueType, Index2, Option->Value.Value.u64);\r
479 Index2++;\r
8d00a0f1 480 Link = GetNextNode (&Question->OptionListHead, Link);\r
481 }\r
d02847d3 482 SetArrayData (ValueArray, ValueType, Index2, 0);\r
8d00a0f1 483\r
484 Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
b18e7050 485 UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
8d00a0f1 486\r
f4113e1f 487 FreePool (*OptionString);\r
8d00a0f1 488 *OptionString = NULL;\r
c60a0616 489 return EFI_NOT_FOUND;\r
490 }\r
491\r
492 Suppress = FALSE;\r
493 if ((OneOfOption->SuppressExpression != NULL) &&\r
494 (OneOfOption->SuppressExpression->Result.Value.b)) {\r
495 //\r
496 // This option is suppressed\r
497 //\r
498 Suppress = TRUE;\r
499 }\r
500\r
501 if (!Suppress) {\r
502 Character[0] = LEFT_ONEOF_DELIMITER;\r
503 NewStrCat (OptionString[0], Character);\r
504 StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r
505 NewStrCat (OptionString[0], StringPtr);\r
506 Character[0] = RIGHT_ONEOF_DELIMITER;\r
507 NewStrCat (OptionString[0], Character);\r
508 Character[0] = CHAR_CARRIAGE_RETURN;\r
509 NewStrCat (OptionString[0], Character);\r
510\r
f4113e1f 511 FreePool (StringPtr);\r
c60a0616 512 }\r
513 }\r
514 }\r
515 break;\r
516\r
517 case EFI_IFR_ONE_OF_OP:\r
b86b413a
LG
518 //\r
519 // Check whether there are Options of this OneOf\r
520 //\r
521 if (IsListEmpty (&Question->OptionListHead)) {\r
522 break;\r
523 }\r
c60a0616 524 if (Selected) {\r
525 //\r
526 // Go ask for input\r
527 //\r
528 Status = GetSelectionInputPopUp (Selection, MenuOption);\r
529 } else {\r
530 *OptionString = AllocateZeroPool (BufferSize);\r
531 ASSERT (*OptionString);\r
532\r
533 OneOfOption = ValueToOption (Question, QuestionValue);\r
534 if (OneOfOption == NULL) {\r
8d00a0f1 535 //\r
536 // Show error message\r
537 //\r
538 do {\r
539 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r
540 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
541\r
542 //\r
543 // Force the Question value to be valid\r
544 //\r
545 Link = GetFirstNode (&Question->OptionListHead);\r
546 while (!IsNull (&Question->OptionListHead, Link)) {\r
547 Option = QUESTION_OPTION_FROM_LINK (Link);\r
548\r
549 if ((Option->SuppressExpression == NULL) ||\r
550 !Option->SuppressExpression->Result.Value.b) {\r
551 CopyMem (QuestionValue, &Option->Value, sizeof (EFI_HII_VALUE));\r
552 SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
b18e7050 553 UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
8d00a0f1 554 break;\r
555 }\r
556\r
557 Link = GetNextNode (&Question->OptionListHead, Link);\r
558 }\r
559\r
f4113e1f 560 FreePool (*OptionString);\r
8d00a0f1 561 *OptionString = NULL;\r
40a06b0c 562 return EFI_NOT_FOUND;\r
c60a0616 563 }\r
564\r
565 if ((OneOfOption->SuppressExpression != NULL) &&\r
566 (OneOfOption->SuppressExpression->Result.Value.b)) {\r
567 //\r
568 // This option is suppressed\r
569 //\r
570 Suppress = TRUE;\r
571 } else {\r
572 Suppress = FALSE;\r
573 }\r
574\r
575 if (Suppress) {\r
576 //\r
577 // Current selected option happen to be suppressed,\r
578 // enforce to select on a non-suppressed option\r
579 //\r
580 Link = GetFirstNode (&Question->OptionListHead);\r
581 while (!IsNull (&Question->OptionListHead, Link)) {\r
582 OneOfOption = QUESTION_OPTION_FROM_LINK (Link);\r
583\r
584 if ((OneOfOption->SuppressExpression == NULL) ||\r
585 !OneOfOption->SuppressExpression->Result.Value.b) {\r
586 Suppress = FALSE;\r
587 CopyMem (QuestionValue, &OneOfOption->Value, sizeof (EFI_HII_VALUE));\r
588 SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
b18e7050 589 UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
f0a1bf11 590 gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND);\r
c60a0616 591 break;\r
592 }\r
593\r
594 Link = GetNextNode (&Question->OptionListHead, Link);\r
595 }\r
596 }\r
597\r
598 if (!Suppress) {\r
599 Character[0] = LEFT_ONEOF_DELIMITER;\r
600 NewStrCat (OptionString[0], Character);\r
601 StringPtr = GetToken (OneOfOption->Text, Selection->Handle);\r
602 NewStrCat (OptionString[0], StringPtr);\r
603 Character[0] = RIGHT_ONEOF_DELIMITER;\r
604 NewStrCat (OptionString[0], Character);\r
605\r
f4113e1f 606 FreePool (StringPtr);\r
c60a0616 607 }\r
608 }\r
609 break;\r
610\r
611 case EFI_IFR_CHECKBOX_OP:\r
612 *OptionString = AllocateZeroPool (BufferSize);\r
613 ASSERT (*OptionString);\r
614\r
615 *OptionString[0] = LEFT_CHECKBOX_DELIMITER;\r
616\r
617 if (Selected) {\r
618 //\r
619 // Since this is a BOOLEAN operation, flip it upon selection\r
620 //\r
621 QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r
622\r
623 //\r
624 // Perform inconsistent check\r
625 //\r
626 Status = ValidateQuestion (Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
627 if (EFI_ERROR (Status)) {\r
628 //\r
629 // Inconsistent check fail, restore Question Value\r
630 //\r
631 QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r
f4113e1f 632 FreePool (*OptionString);\r
8d00a0f1 633 *OptionString = NULL;\r
c60a0616 634 return Status;\r
635 }\r
636\r
637 //\r
638 // Save Question value\r
639 //\r
640 Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
b18e7050 641 UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
c60a0616 642 }\r
643\r
644 if (QuestionValue->Value.b) {\r
645 *(OptionString[0] + 1) = CHECK_ON;\r
646 } else {\r
647 *(OptionString[0] + 1) = CHECK_OFF;\r
648 }\r
649 *(OptionString[0] + 2) = RIGHT_CHECKBOX_DELIMITER;\r
650 break;\r
651\r
652 case EFI_IFR_NUMERIC_OP:\r
653 if (Selected) {\r
654 //\r
655 // Go ask for input\r
656 //\r
657 Status = GetNumericInput (Selection, MenuOption);\r
658 } else {\r
659 *OptionString = AllocateZeroPool (BufferSize);\r
660 ASSERT (*OptionString);\r
661\r
662 *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
663\r
664 //\r
665 // Formatted print\r
666 //\r
667 PrintFormattedNumber (Question, FormattedNumber, 21 * sizeof (CHAR16));\r
668 Number = (UINT16) GetStringWidth (FormattedNumber);\r
669 CopyMem (OptionString[0] + 1, FormattedNumber, Number);\r
670\r
671 *(OptionString[0] + Number / 2) = RIGHT_NUMERIC_DELIMITER;\r
672 }\r
673 break;\r
674\r
675 case EFI_IFR_DATE_OP:\r
676 if (Selected) {\r
677 //\r
678 // This is similar to numerics\r
679 //\r
680 Status = GetNumericInput (Selection, MenuOption);\r
681 } else {\r
682 *OptionString = AllocateZeroPool (BufferSize);\r
683 ASSERT (*OptionString);\r
684\r
685 switch (MenuOption->Sequence) {\r
686 case 0:\r
687 *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
688 UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Month);\r
689 *(OptionString[0] + 3) = DATE_SEPARATOR;\r
690 break;\r
691\r
692 case 1:\r
693 SetUnicodeMem (OptionString[0], 4, L' ');\r
694 UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.date.Day);\r
695 *(OptionString[0] + 6) = DATE_SEPARATOR;\r
696 break;\r
697\r
698 case 2:\r
699 SetUnicodeMem (OptionString[0], 7, L' ');\r
700 UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%4d", QuestionValue->Value.date.Year);\r
701 *(OptionString[0] + 11) = RIGHT_NUMERIC_DELIMITER;\r
702 break;\r
703 }\r
704 }\r
705 break;\r
706\r
707 case EFI_IFR_TIME_OP:\r
708 if (Selected) {\r
709 //\r
710 // This is similar to numerics\r
711 //\r
712 Status = GetNumericInput (Selection, MenuOption);\r
713 } else {\r
714 *OptionString = AllocateZeroPool (BufferSize);\r
715 ASSERT (*OptionString);\r
716\r
717 switch (MenuOption->Sequence) {\r
718 case 0:\r
719 *OptionString[0] = LEFT_NUMERIC_DELIMITER;\r
720 UnicodeSPrint (OptionString[0] + 1, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Hour);\r
721 *(OptionString[0] + 3) = TIME_SEPARATOR;\r
722 break;\r
723\r
724 case 1:\r
725 SetUnicodeMem (OptionString[0], 4, L' ');\r
726 UnicodeSPrint (OptionString[0] + 4, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Minute);\r
727 *(OptionString[0] + 6) = TIME_SEPARATOR;\r
728 break;\r
729\r
730 case 2:\r
731 SetUnicodeMem (OptionString[0], 7, L' ');\r
732 UnicodeSPrint (OptionString[0] + 7, 21 * sizeof (CHAR16), L"%02d", QuestionValue->Value.time.Second);\r
733 *(OptionString[0] + 9) = RIGHT_NUMERIC_DELIMITER;\r
734 break;\r
735 }\r
736 }\r
737 break;\r
738\r
739 case EFI_IFR_STRING_OP:\r
740 if (Selected) {\r
741 StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
742 ASSERT (StringPtr);\r
da588638 743 CopyMem(StringPtr, Question->BufferValue, Maximum * sizeof (CHAR16));\r
c60a0616 744\r
745 Status = ReadString (MenuOption, gPromptForData, StringPtr);\r
746 if (!EFI_ERROR (Status)) {\r
e2100bfa
ED
747 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r
748 Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
749 if (EFI_ERROR (Status)) {\r
750 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r
751 } else {\r
752 CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
753 SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
c60a0616 754\r
b18e7050 755 UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
e2100bfa 756 }\r
c60a0616 757 }\r
758\r
f4113e1f 759 FreePool (StringPtr);\r
c60a0616 760 } else {\r
761 *OptionString = AllocateZeroPool (BufferSize);\r
762 ASSERT (*OptionString);\r
763\r
764 if (((CHAR16 *) Question->BufferValue)[0] == 0x0000) {\r
765 *(OptionString[0]) = '_';\r
766 } else {\r
767 if ((Maximum * sizeof (CHAR16)) < BufferSize) {\r
768 BufferSize = Maximum * sizeof (CHAR16);\r
769 }\r
770 CopyMem (OptionString[0], (CHAR16 *) Question->BufferValue, BufferSize);\r
771 }\r
772 }\r
773 break;\r
774\r
775 case EFI_IFR_PASSWORD_OP:\r
776 if (Selected) {\r
777 StringPtr = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
778 ASSERT (StringPtr);\r
779\r
780 //\r
781 // For interactive passwords, old password is validated by callback\r
782 //\r
783 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
784 //\r
785 // Use a NULL password to test whether old password is required\r
786 //\r
787 *StringPtr = 0;\r
788 Status = PasswordCallback (Selection, MenuOption, StringPtr);\r
13ad1def 789 if (Status == EFI_NOT_AVAILABLE_YET || Status == EFI_UNSUPPORTED) {\r
c60a0616 790 //\r
13ad1def 791 // Callback is not supported, or\r
c60a0616 792 // Callback request to terminate password input\r
793 //\r
f4113e1f 794 FreePool (StringPtr);\r
c60a0616 795 return EFI_SUCCESS;\r
796 }\r
797\r
798 if (EFI_ERROR (Status)) {\r
799 //\r
800 // Old password exist, ask user for the old password\r
801 //\r
802 Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r
803 if (EFI_ERROR (Status)) {\r
f4113e1f 804 FreePool (StringPtr);\r
c60a0616 805 return Status;\r
806 }\r
807\r
808 //\r
809 // Check user input old password\r
810 //\r
811 Status = PasswordCallback (Selection, MenuOption, StringPtr);\r
812 if (EFI_ERROR (Status)) {\r
813 if (Status == EFI_NOT_READY) {\r
814 //\r
815 // Typed in old password incorrect\r
816 //\r
817 PasswordInvalid ();\r
818 } else {\r
819 Status = EFI_SUCCESS;\r
820 }\r
821\r
f4113e1f 822 FreePool (StringPtr);\r
c60a0616 823 return Status;\r
824 }\r
825 }\r
826 } else {\r
827 //\r
828 // For non-interactive password, validate old password in local\r
829 //\r
830 if (*((CHAR16 *) Question->BufferValue) != 0) {\r
831 //\r
832 // There is something there! Prompt for password\r
833 //\r
834 Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r
835 if (EFI_ERROR (Status)) {\r
f4113e1f 836 FreePool (StringPtr);\r
c60a0616 837 return Status;\r
838 }\r
839\r
840 TempString = AllocateCopyPool ((Maximum + 1) * sizeof (CHAR16), Question->BufferValue);\r
40a06b0c 841 ASSERT (TempString != NULL);\r
8b0fc5c1 842\r
c60a0616 843 TempString[Maximum] = L'\0';\r
844\r
845 if (StrCmp (StringPtr, TempString) != 0) {\r
846 //\r
847 // Typed in old password incorrect\r
848 //\r
849 PasswordInvalid ();\r
850\r
f4113e1f 851 FreePool (StringPtr);\r
852 FreePool (TempString);\r
c60a0616 853 return Status;\r
854 }\r
855\r
f4113e1f 856 FreePool (TempString);\r
c60a0616 857 }\r
858 }\r
859\r
860 //\r
861 // Ask for new password\r
862 //\r
863 ZeroMem (StringPtr, (Maximum + 1) * sizeof (CHAR16));\r
864 Status = ReadString (MenuOption, gPromptForNewPassword, StringPtr);\r
865 if (EFI_ERROR (Status)) {\r
866 //\r
867 // Reset state machine for interactive password\r
868 //\r
869 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
870 PasswordCallback (Selection, MenuOption, NULL);\r
871 }\r
872\r
f4113e1f 873 FreePool (StringPtr);\r
c60a0616 874 return Status;\r
875 }\r
876\r
877 //\r
878 // Confirm new password\r
879 //\r
880 TempString = AllocateZeroPool ((Maximum + 1) * sizeof (CHAR16));\r
881 ASSERT (TempString);\r
882 Status = ReadString (MenuOption, gConfirmPassword, TempString);\r
883 if (EFI_ERROR (Status)) {\r
884 //\r
885 // Reset state machine for interactive password\r
886 //\r
887 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
888 PasswordCallback (Selection, MenuOption, NULL);\r
889 }\r
890\r
f4113e1f 891 FreePool (StringPtr);\r
892 FreePool (TempString);\r
c60a0616 893 return Status;\r
894 }\r
895\r
896 //\r
897 // Compare two typed-in new passwords\r
898 //\r
899 if (StrCmp (StringPtr, TempString) == 0) {\r
900 //\r
e2100bfa 901 // Prepare the Question->HiiValue.Value.string for ValidateQuestion use.\r
c60a0616 902 //\r
e2100bfa
ED
903 if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
904 StringId = Question->HiiValue.Value.string;\r
905 Question->HiiValue.Value.string = NewString (StringPtr, Selection->FormSet->HiiHandle);\r
c60a0616 906 } else {\r
e2100bfa
ED
907 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r
908 }\r
909 \r
910 Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
911\r
912 //\r
913 // Researve the Question->HiiValue.Value.string.\r
914 //\r
915 if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
916 DeleteString(Question->HiiValue.Value.string, Selection->FormSet->HiiHandle);\r
917 Question->HiiValue.Value.string = StringId;\r
918 } \r
919 \r
920 if (EFI_ERROR (Status)) {\r
921 //\r
922 // Reset state machine for interactive password\r
923 //\r
924 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
925 PasswordCallback (Selection, MenuOption, NULL);\r
926 } else {\r
927 //\r
928 // Researve the Question->HiiValue.Value.string.\r
929 //\r
930 HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL); \r
931 }\r
932 } else {\r
933 //\r
934 // Two password match, send it to Configuration Driver\r
935 //\r
936 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
937 PasswordCallback (Selection, MenuOption, StringPtr);\r
938 } else {\r
939 CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
940 SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);\r
941 }\r
c60a0616 942 }\r
943 } else {\r
944 //\r
945 // Reset state machine for interactive password\r
946 //\r
947 if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
948 PasswordCallback (Selection, MenuOption, NULL);\r
949 }\r
950\r
951 //\r
952 // Two password mismatch, prompt error message\r
953 //\r
954 do {\r
955 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gConfirmError, gPressEnter, gEmptyString);\r
956 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
957 }\r
958\r
f4113e1f 959 FreePool (TempString);\r
960 FreePool (StringPtr);\r
c60a0616 961 }\r
962 break;\r
963\r
964 default:\r
965 break;\r
966 }\r
967\r
968 return Status;\r
969}\r
970\r
971\r
972/**\r
973 Process the help string: Split StringPtr to several lines of strings stored in\r
974 FormattedString and the glyph width of each line cannot exceed gHelpBlockWidth.\r
975\r
976 @param StringPtr The entire help string.\r
977 @param FormattedString The oupput formatted string.\r
978 @param RowCount TRUE: if Question is selected.\r
979\r
980**/\r
981VOID\r
982ProcessHelpString (\r
983 IN CHAR16 *StringPtr,\r
984 OUT CHAR16 **FormattedString,\r
985 IN UINTN RowCount\r
986 )\r
987{\r
f4113e1f 988 UINTN BlockWidth;\r
c60a0616 989 UINTN AllocateSize;\r
990 //\r
991 // [PrevCurrIndex, CurrIndex) forms a range of a screen-line\r
992 //\r
993 UINTN CurrIndex;\r
994 UINTN PrevCurrIndex;\r
995 UINTN LineCount;\r
996 UINTN VirtualLineCount;\r
997 //\r
998 // GlyphOffset stores glyph width of current screen-line\r
999 //\r
1000 UINTN GlyphOffset;\r
1001 //\r
1002 // GlyphWidth equals to 2 if we meet width directive\r
1003 //\r
1004 UINTN GlyphWidth;\r
1005 //\r
1006 // during scanning, we remember the position of last space character\r
1007 // in case that if next word cannot put in current line, we could restore back to the position\r
1008 // of last space character\r
1009 // while we should also remmeber the glyph width of the last space character for restoring\r
1010 //\r
1011 UINTN LastSpaceIndex;\r
1012 UINTN LastSpaceGlyphWidth;\r
1013 //\r
1014 // every time we begin to form a new screen-line, we should remember glyph width of single character\r
1015 // of last line\r
1016 //\r
1017 UINTN LineStartGlyphWidth;\r
1018 UINTN *IndexArray;\r
1019 UINTN *OldIndexArray;\r
1020\r
f4113e1f 1021 BlockWidth = (UINTN) gHelpBlockWidth - 1;\r
8b0fc5c1 1022\r
c60a0616 1023 //\r
1024 // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )\r
1025 // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want\r
1026 // to bring the width directive of the last line to current screen-line.\r
1027 // e.g.: "\wideabcde ... fghi", if "fghi" also has width directive but is splitted to the next screen-line\r
1028 // different from that of "\wideabcde", we should remember the width directive.\r
1029 //\r
1030 AllocateSize = 0x20;\r
1031 IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
40a06b0c 1032 ASSERT (IndexArray != NULL);\r
c60a0616 1033\r
1034 if (*FormattedString != NULL) {\r
f4113e1f 1035 FreePool (*FormattedString);\r
c60a0616 1036 *FormattedString = NULL;\r
1037 }\r
1038\r
1039 for (PrevCurrIndex = 0, CurrIndex = 0, LineCount = 0, LastSpaceIndex = 0,\r
1040 IndexArray[0] = 0, GlyphWidth = 1, GlyphOffset = 0, LastSpaceGlyphWidth = 1, LineStartGlyphWidth = 1;\r
1041 (StringPtr[CurrIndex] != CHAR_NULL);\r
1042 CurrIndex ++) {\r
1043\r
1044 if (LineCount == AllocateSize) {\r
1045 AllocateSize += 0x10;\r
1046 OldIndexArray = IndexArray;\r
1047 IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
bc166db3 1048 ASSERT (IndexArray != NULL);\r
8b0fc5c1 1049\r
c60a0616 1050 CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);\r
f4113e1f 1051 FreePool (OldIndexArray);\r
c60a0616 1052 }\r
1053 switch (StringPtr[CurrIndex]) {\r
1054\r
1055 case NARROW_CHAR:\r
1056 case WIDE_CHAR:\r
1057 GlyphWidth = ((StringPtr[CurrIndex] == WIDE_CHAR) ? 2 : 1);\r
1058 if (CurrIndex == 0) {\r
1059 LineStartGlyphWidth = GlyphWidth;\r
1060 }\r
1061 break;\r
1062\r
1063 //\r
1064 // char is '\n'\r
1065 // "\r\n" isn't handled here, handled by case CHAR_CARRIAGE_RETURN\r
1066 //\r
1067 case CHAR_LINEFEED:\r
1068 //\r
1069 // Store a range of string as a line\r
1070 //\r
1071 IndexArray[LineCount*3] = PrevCurrIndex;\r
1072 IndexArray[LineCount*3+1] = CurrIndex;\r
1073 IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
1074 LineCount ++;\r
1075 //\r
1076 // Reset offset and save begin position of line\r
1077 //\r
1078 GlyphOffset = 0;\r
1079 LineStartGlyphWidth = GlyphWidth;\r
1080 PrevCurrIndex = CurrIndex + 1;\r
1081 break;\r
1082\r
1083 //\r
1084 // char is '\r'\r
1085 // "\r\n" and "\r" both are handled here\r
1086 //\r
1087 case CHAR_CARRIAGE_RETURN:\r
1088 if (StringPtr[CurrIndex + 1] == CHAR_LINEFEED) {\r
1089 //\r
1090 // next char is '\n'\r
1091 //\r
1092 IndexArray[LineCount*3] = PrevCurrIndex;\r
1093 IndexArray[LineCount*3+1] = CurrIndex;\r
1094 IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
1095 LineCount ++;\r
1096 CurrIndex ++;\r
1097 }\r
1098 GlyphOffset = 0;\r
1099 LineStartGlyphWidth = GlyphWidth;\r
1100 PrevCurrIndex = CurrIndex + 1;\r
1101 break;\r
1102\r
1103 //\r
1104 // char is space or other char\r
1105 //\r
1106 default:\r
1107 GlyphOffset += GlyphWidth;\r
1108 if (GlyphOffset >= BlockWidth) {\r
1109 if (LastSpaceIndex > PrevCurrIndex) {\r
1110 //\r
1111 // LastSpaceIndex points to space inside current screen-line,\r
1112 // restore to LastSpaceIndex\r
1113 // (Otherwise the word is too long to fit one screen-line, just cut it)\r
1114 //\r
1115 CurrIndex = LastSpaceIndex;\r
1116 GlyphWidth = LastSpaceGlyphWidth;\r
1117 } else if (GlyphOffset > BlockWidth) {\r
1118 //\r
1119 // the word is too long to fit one screen-line and we don't get the chance\r
1120 // of GlyphOffset == BlockWidth because GlyphWidth = 2\r
1121 //\r
1122 CurrIndex --;\r
1123 }\r
1124\r
1125 IndexArray[LineCount*3] = PrevCurrIndex;\r
1126 IndexArray[LineCount*3+1] = CurrIndex + 1;\r
1127 IndexArray[LineCount*3+2] = LineStartGlyphWidth;\r
1128 LineStartGlyphWidth = GlyphWidth;\r
1129 LineCount ++;\r
1130 //\r
1131 // Reset offset and save begin position of line\r
1132 //\r
1133 GlyphOffset = 0;\r
1134 PrevCurrIndex = CurrIndex + 1;\r
1135 }\r
1136\r
1137 //\r
1138 // LastSpaceIndex: remember position of last space\r
1139 //\r
1140 if (StringPtr[CurrIndex] == CHAR_SPACE) {\r
1141 LastSpaceIndex = CurrIndex;\r
1142 LastSpaceGlyphWidth = GlyphWidth;\r
1143 }\r
1144 break;\r
1145 }\r
1146 }\r
1147\r
1148 if (GlyphOffset > 0) {\r
1149 IndexArray[LineCount*3] = PrevCurrIndex;\r
1150 IndexArray[LineCount*3+1] = CurrIndex;\r
1151 IndexArray[LineCount*3+2] = GlyphWidth;\r
1152 LineCount ++;\r
1153 }\r
1154\r
1155 if (LineCount == 0) {\r
1156 //\r
1157 // in case we meet null string\r
1158 //\r
1159 IndexArray[0] = 0;\r
1160 IndexArray[1] = 1;\r
1161 //\r
1162 // we assume null string's glyph width is 1\r
1163 //\r
1164 IndexArray[1] = 1;\r
1165 LineCount ++;\r
1166 }\r
1167\r
1168 VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));\r
1169 *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);\r
40a06b0c 1170 ASSERT (*FormattedString != NULL);\r
c60a0616 1171\r
1172 for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {\r
1173 *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16) ((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);\r
1174 StrnCpy (\r
1175 *FormattedString + CurrIndex * 2 * (BlockWidth + 1) + 1,\r
1176 StringPtr + IndexArray[CurrIndex*3],\r
1177 IndexArray[CurrIndex*3+1]-IndexArray[CurrIndex*3]\r
1178 );\r
1179 }\r
1180\r
f4113e1f 1181 FreePool (IndexArray);\r
c60a0616 1182}\r