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