2 Implementation for handling the User Interface option processing.
5 Copyright (c) 2004 - 2016, 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
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.
16 #include "FormDisplay.h"
18 #define MAX_TIME_OUT_LEN 0x10
21 Concatenate a narrow string to another string.
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.
31 IN OUT CHAR16
*Destination
,
38 for (Length
= 0; Destination
[Length
] != 0; Length
++)
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
47 Destination
[Length
] = NARROW_CHAR
;
50 StrCpyS (Destination
+ Length
, DestMax
- Length
, Source
);
54 Get UINT64 type value.
56 @param Value Input Hii value.
58 @retval UINT64 Return the UINT64 type value.
63 IN EFI_HII_VALUE
*Value
70 switch (Value
->Type
) {
71 case EFI_IFR_TYPE_NUM_SIZE_8
:
72 RetVal
= Value
->Value
.u8
;
75 case EFI_IFR_TYPE_NUM_SIZE_16
:
76 RetVal
= Value
->Value
.u16
;
79 case EFI_IFR_TYPE_NUM_SIZE_32
:
80 RetVal
= Value
->Value
.u32
;
83 case EFI_IFR_TYPE_BOOLEAN
:
84 RetVal
= Value
->Value
.b
;
87 case EFI_IFR_TYPE_DATE
:
88 RetVal
= *(UINT64
*) &Value
->Value
.date
;
91 case EFI_IFR_TYPE_TIME
:
92 RetVal
= (*(UINT64
*) &Value
->Value
.time
) & 0xffffff;
96 RetVal
= Value
->Value
.u64
;
104 Check whether this value type can be transfer to EFI_IFR_TYPE_BUFFER type.
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.
109 @param Value Expression value to compare on.
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.
117 IN EFI_HII_VALUE
*Value
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
:
133 Check whether this value type can be transfer to EFI_IFR_TYPE_UINT64
135 @param Value Expression value to compare on.
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.
143 IN EFI_HII_VALUE
*Value
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
:
160 Return the buffer length and buffer pointer for this value.
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.
165 @param Value Expression value to compare on.
166 @param Buf Return the buffer pointer.
167 @param BufLen Return the buffer length.
171 GetBufAndLenForValue (
172 IN EFI_HII_VALUE
*Value
,
177 switch (Value
->Type
) {
178 case EFI_IFR_TYPE_BUFFER
:
179 *Buf
= Value
->Buffer
;
180 *BufLen
= Value
->BufferLen
;
183 case EFI_IFR_TYPE_DATE
:
184 *Buf
= (UINT8
*) (&Value
->Value
.date
);
185 *BufLen
= (UINT16
) sizeof (EFI_HII_DATE
);
188 case EFI_IFR_TYPE_TIME
:
189 *Buf
= (UINT8
*) (&Value
->Value
.time
);
190 *BufLen
= (UINT16
) sizeof (EFI_HII_TIME
);
193 case EFI_IFR_TYPE_REF
:
194 *Buf
= (UINT8
*) (&Value
->Value
.ref
);
195 *BufLen
= (UINT16
) sizeof (EFI_HII_REF
);
205 Compare two Hii value.
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.
215 @retval other Could not perform compare on two values.
216 @retval EFI_SUCCESS Compare the value success.
221 IN EFI_HII_VALUE
*Value1
,
222 IN EFI_HII_VALUE
*Value2
,
224 IN EFI_HII_HANDLE HiiHandle OPTIONAL
236 if (Value1
->Type
== EFI_IFR_TYPE_STRING
&& Value2
->Type
== EFI_IFR_TYPE_STRING
) {
237 if (Value1
->Value
.string
== 0 || Value2
->Value
.string
== 0) {
239 // StringId 0 is reserved
241 return EFI_INVALID_PARAMETER
;
244 if (Value1
->Value
.string
== Value2
->Value
.string
) {
249 Str1
= GetToken (Value1
->Value
.string
, HiiHandle
);
254 return EFI_NOT_FOUND
;
257 Str2
= GetToken (Value2
->Value
.string
, HiiHandle
);
260 return EFI_NOT_FOUND
;
263 *Result
= StrCmp (Str1
, Str2
);
272 // Take types(date, time, ref, buffer) as buffer
274 if (IsTypeInBuffer(Value1
) && IsTypeInBuffer(Value2
)) {
275 GetBufAndLenForValue(Value1
, &Buf1
, &Buf1Len
);
276 GetBufAndLenForValue(Value2
, &Buf2
, &Buf2Len
);
278 Len
= Buf1Len
> Buf2Len
? Buf2Len
: Buf1Len
;
279 *Result
= CompareMem (Buf1
, Buf2
, Len
);
280 if ((*Result
== 0) && (Buf1Len
!= Buf2Len
)) {
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.
285 *Result
= Buf1Len
> Buf2Len
? 1 : -1;
291 // Take remain types(integer, boolean, date/time) as integer
293 if (IsTypeInUINT64(Value1
) && IsTypeInUINT64(Value2
)) {
294 Temp64
= HiiValueToUINT64(Value1
) - HiiValueToUINT64(Value2
);
297 } else if (Temp64
< 0) {
305 return EFI_UNSUPPORTED
;
309 Search an Option of a Question by its value.
311 @param Question The Question
312 @param OptionValue Value for Option to be searched.
314 @retval Pointer Pointer to the found Option.
315 @retval NULL Option not found.
318 DISPLAY_QUESTION_OPTION
*
320 IN FORM_DISPLAY_ENGINE_STATEMENT
*Question
,
321 IN EFI_HII_VALUE
*OptionValue
325 DISPLAY_QUESTION_OPTION
*Option
;
329 Link
= GetFirstNode (&Question
->OptionListHead
);
330 while (!IsNull (&Question
->OptionListHead
, Link
)) {
331 Option
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
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
));
337 if ((CompareHiiValue (&Value
, OptionValue
, &Result
, NULL
) == EFI_SUCCESS
) && (Result
== 0)) {
341 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
349 Return data element in an Array by its Index.
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.
355 @retval Value The data to be returned
367 ASSERT (Array
!= NULL
);
371 case EFI_IFR_TYPE_NUM_SIZE_8
:
372 Data
= (UINT64
) *(((UINT8
*) Array
) + Index
);
375 case EFI_IFR_TYPE_NUM_SIZE_16
:
376 Data
= (UINT64
) *(((UINT16
*) Array
) + Index
);
379 case EFI_IFR_TYPE_NUM_SIZE_32
:
380 Data
= (UINT64
) *(((UINT32
*) Array
) + Index
);
383 case EFI_IFR_TYPE_NUM_SIZE_64
:
384 Data
= (UINT64
) *(((UINT64
*) Array
) + Index
);
396 Set value of a data element in an Array by its Index.
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.
413 ASSERT (Array
!= NULL
);
416 case EFI_IFR_TYPE_NUM_SIZE_8
:
417 *(((UINT8
*) Array
) + Index
) = (UINT8
) Value
;
420 case EFI_IFR_TYPE_NUM_SIZE_16
:
421 *(((UINT16
*) Array
) + Index
) = (UINT16
) Value
;
424 case EFI_IFR_TYPE_NUM_SIZE_32
:
425 *(((UINT32
*) Array
) + Index
) = (UINT32
) Value
;
428 case EFI_IFR_TYPE_NUM_SIZE_64
:
429 *(((UINT64
*) Array
) + Index
) = (UINT64
) Value
;
438 Check whether this value already in the array, if yes, return the index.
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.
445 @retval TRUE Found the value in the array.
446 @retval FALSE Not found the value.
454 OUT UINTN
*Index OPTIONAL
461 ASSERT (Array
!= NULL
);
467 case EFI_IFR_TYPE_NUM_SIZE_8
:
468 ValueComp
= (UINT8
) Value
;
471 case EFI_IFR_TYPE_NUM_SIZE_16
:
472 ValueComp
= (UINT16
) Value
;
475 case EFI_IFR_TYPE_NUM_SIZE_32
:
476 ValueComp
= (UINT32
) Value
;
479 case EFI_IFR_TYPE_NUM_SIZE_64
:
480 ValueComp
= (UINT64
) Value
;
488 while ((TmpValue
= GetArrayData (Array
, Type
, Count
)) != 0) {
489 if (ValueComp
== TmpValue
) {
503 Print Question Value according to it's storage width and display attributes.
505 @param Question The Question to be printed.
506 @param FormattedNumber Buffer for output string.
507 @param BufferSize The FormattedNumber buffer size in bytes.
509 @retval EFI_SUCCESS Print success.
510 @retval EFI_BUFFER_TOO_SMALL Buffer size is not enough for formatted number.
514 PrintFormattedNumber (
515 IN FORM_DISPLAY_ENGINE_STATEMENT
*Question
,
516 IN OUT CHAR16
*FormattedNumber
,
522 EFI_HII_VALUE
*QuestionValue
;
523 EFI_IFR_NUMERIC
*NumericOp
;
525 if (BufferSize
< (21 * sizeof (CHAR16
))) {
526 return EFI_BUFFER_TOO_SMALL
;
529 QuestionValue
= &Question
->CurrentValue
;
530 NumericOp
= (EFI_IFR_NUMERIC
*) Question
->OpCode
;
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
);
540 case EFI_IFR_NUMERIC_SIZE_2
:
541 Value
= (INT64
) ((INT16
) QuestionValue
->Value
.u16
);
544 case EFI_IFR_NUMERIC_SIZE_4
:
545 Value
= (INT64
) ((INT32
) QuestionValue
->Value
.u32
);
548 case EFI_IFR_NUMERIC_SIZE_8
:
561 case EFI_IFR_DISPLAY_UINT_DEC
:
565 case EFI_IFR_DISPLAY_UINT_HEX
:
570 return EFI_UNSUPPORTED
;
573 UnicodeSPrint (FormattedNumber
, BufferSize
, Format
, Value
);
580 Draw a pop up windows based on the dimension, number of lines and
583 @param RequestedWidth The width of the pop-up.
584 @param NumberOfLines The number of lines.
585 @param Marker The variable argument list for the list of string to be printed.
590 IN UINTN RequestedWidth
,
591 IN UINTN NumberOfLines
,
603 UINTN DimensionsWidth
;
604 UINTN DimensionsHeight
;
606 DimensionsWidth
= gStatementDimensions
.RightColumn
- gStatementDimensions
.LeftColumn
;
607 DimensionsHeight
= gStatementDimensions
.BottomRow
- gStatementDimensions
.TopRow
;
609 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetPopupColor ());
611 if ((RequestedWidth
+ 2) > DimensionsWidth
) {
612 RequestedWidth
= DimensionsWidth
- 2;
616 // Subtract the PopUp width from total Columns, allow for one space extra on
617 // each end plus a border.
619 Start
= (DimensionsWidth
- RequestedWidth
- 2) / 2 + gStatementDimensions
.LeftColumn
+ 1;
620 End
= Start
+ RequestedWidth
+ 1;
622 Top
= ((DimensionsHeight
- NumberOfLines
- 2) / 2) + gStatementDimensions
.TopRow
- 1;
623 Bottom
= Top
+ NumberOfLines
+ 2;
625 Character
= BOXDRAW_DOWN_RIGHT
;
626 PrintCharAt (Start
, Top
, Character
);
627 Character
= BOXDRAW_HORIZONTAL
;
628 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
629 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
632 Character
= BOXDRAW_DOWN_LEFT
;
633 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
634 Character
= BOXDRAW_VERTICAL
;
637 for (Index
= Top
; Index
+ 2 < Bottom
; Index
++, Count
++) {
638 String
= VA_ARG (Marker
, CHAR16
*);
641 // This will clear the background of the line - we never know who might have been
642 // here before us. This differs from the next clear in that it used the non-reverse
643 // video for normal printing.
645 if (GetStringWidth (String
) / 2 > 1) {
646 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, GetPopupColor ());
650 // Passing in a space results in the assumption that this is where typing will occur
652 if (String
[0] == L
' ') {
653 ClearLines (Start
+ 1, End
- 1, Index
+ 1, Index
+ 1, GetPopupInverseColor ());
657 // Passing in a NULL results in a blank space
659 if (String
[0] == CHAR_NULL
) {
660 ClearLines (Start
, End
, Index
+ 1, Index
+ 1, GetPopupColor ());
664 ((DimensionsWidth
- GetStringWidth (String
) / 2) / 2) + gStatementDimensions
.LeftColumn
+ 1,
668 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetPopupColor ());
669 PrintCharAt (Start
, Index
+ 1, Character
);
670 PrintCharAt (End
- 1, Index
+ 1, Character
);
673 Character
= BOXDRAW_UP_RIGHT
;
674 PrintCharAt (Start
, Bottom
- 1, Character
);
675 Character
= BOXDRAW_HORIZONTAL
;
676 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
677 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
680 Character
= BOXDRAW_UP_LEFT
;
681 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
685 Draw a pop up windows based on the dimension, number of lines and
688 @param RequestedWidth The width of the pop-up.
689 @param NumberOfLines The number of lines.
690 @param ... A series of text strings that displayed in the pop-up.
695 CreateMultiStringPopUp (
696 IN UINTN RequestedWidth
,
697 IN UINTN NumberOfLines
,
703 VA_START (Marker
, NumberOfLines
);
705 CreateSharedPopUp (RequestedWidth
, NumberOfLines
, Marker
);
713 @param Event The Event need to be process
714 @param Context The context of the event.
727 Process for the refresh interval statement.
729 @param Event The Event need to be process
730 @param Context The context of the event.
735 RefreshTimeOutProcess (
740 WARNING_IF_CONTEXT
*EventInfo
;
741 CHAR16 TimeOutString
[MAX_TIME_OUT_LEN
];
743 EventInfo
= (WARNING_IF_CONTEXT
*) Context
;
745 if (*(EventInfo
->TimeOut
) == 0) {
746 gBS
->CloseEvent (Event
);
748 gBS
->SignalEvent (EventInfo
->SyncEvent
);
752 UnicodeSPrint(TimeOutString
, MAX_TIME_OUT_LEN
, L
"%d", *(EventInfo
->TimeOut
));
754 CreateDialog (NULL
, gEmptyString
, EventInfo
->ErrorInfo
, gPressEnter
, gEmptyString
, TimeOutString
, NULL
);
756 *(EventInfo
->TimeOut
) -= 1;
760 Display error message for invalid password.
771 // Invalid password, prompt error message
774 CreateDialog (&Key
, gEmptyString
, gPassowordInvalid
, gPressEnter
, gEmptyString
, NULL
);
775 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
779 Process password op code.
781 @param MenuOption The menu for current password op code.
783 @retval EFI_SUCCESS Question Option process success.
784 @retval Other Question Option process fail.
789 IN UI_MENU_OPTION
*MenuOption
796 EFI_IFR_PASSWORD
*PasswordInfo
;
797 FORM_DISPLAY_ENGINE_STATEMENT
*Question
;
800 Question
= MenuOption
->ThisTag
;
801 PasswordInfo
= (EFI_IFR_PASSWORD
*) Question
->OpCode
;
802 Maximum
= PasswordInfo
->MaxSize
;
803 Status
= EFI_SUCCESS
;
805 StringPtr
= AllocateZeroPool ((Maximum
+ 1) * sizeof (CHAR16
));
809 // Use a NULL password to test whether old password is required
812 Status
= Question
->PasswordCheck (gFormData
, Question
, StringPtr
);
813 if (Status
== EFI_NOT_AVAILABLE_YET
|| Status
== EFI_UNSUPPORTED
) {
815 // Password can't be set now.
817 FreePool (StringPtr
);
821 if (EFI_ERROR (Status
)) {
823 // Old password exist, ask user for the old password
825 Status
= ReadString (MenuOption
, gPromptForPassword
, StringPtr
);
826 if (EFI_ERROR (Status
)) {
827 FreePool (StringPtr
);
832 // Check user input old password
834 Status
= Question
->PasswordCheck (gFormData
, Question
, StringPtr
);
835 if (EFI_ERROR (Status
)) {
836 if (Status
== EFI_NOT_READY
) {
838 // Typed in old password incorrect
842 Status
= EFI_SUCCESS
;
845 FreePool (StringPtr
);
851 // Ask for new password
853 ZeroMem (StringPtr
, (Maximum
+ 1) * sizeof (CHAR16
));
854 Status
= ReadString (MenuOption
, gPromptForNewPassword
, StringPtr
);
855 if (EFI_ERROR (Status
)) {
857 // Reset state machine for password
859 Question
->PasswordCheck (gFormData
, Question
, NULL
);
860 FreePool (StringPtr
);
865 // Confirm new password
867 TempString
= AllocateZeroPool ((Maximum
+ 1) * sizeof (CHAR16
));
869 Status
= ReadString (MenuOption
, gConfirmPassword
, TempString
);
870 if (EFI_ERROR (Status
)) {
872 // Reset state machine for password
874 Question
->PasswordCheck (gFormData
, Question
, NULL
);
875 FreePool (StringPtr
);
876 FreePool (TempString
);
881 // Compare two typed-in new passwords
883 if (StrCmp (StringPtr
, TempString
) == 0) {
884 gUserInput
->InputValue
.Buffer
= AllocateCopyPool (Question
->CurrentValue
.BufferLen
, StringPtr
);
885 gUserInput
->InputValue
.BufferLen
= Question
->CurrentValue
.BufferLen
;
886 gUserInput
->InputValue
.Type
= Question
->CurrentValue
.Type
;
887 gUserInput
->InputValue
.Value
.string
= HiiSetString(gFormData
->HiiHandle
, gUserInput
->InputValue
.Value
.string
, StringPtr
, NULL
);
889 Status
= EFI_SUCCESS
;
892 // Reset state machine for password
894 Question
->PasswordCheck (gFormData
, Question
, NULL
);
897 // Two password mismatch, prompt error message
900 CreateDialog (&Key
, gEmptyString
, gConfirmError
, gPressEnter
, gEmptyString
, NULL
);
901 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
903 Status
= EFI_INVALID_PARAMETER
;
906 FreePool (TempString
);
907 FreePool (StringPtr
);
913 Process a Question's Option (whether selected or un-selected).
915 @param MenuOption The MenuOption for this Question.
916 @param Selected TRUE: if Question is selected.
917 @param OptionString Pointer of the Option String to be displayed.
918 @param SkipErrorValue Whether need to return when value without option for it.
920 @retval EFI_SUCCESS Question Option process success.
921 @retval Other Question Option process fail.
926 IN UI_MENU_OPTION
*MenuOption
,
928 OUT CHAR16
**OptionString
,
929 IN BOOLEAN SkipErrorValue
935 FORM_DISPLAY_ENGINE_STATEMENT
*Question
;
936 CHAR16 FormattedNumber
[21];
941 DISPLAY_QUESTION_OPTION
*OneOfOption
;
943 EFI_HII_VALUE HiiValue
;
944 EFI_HII_VALUE
*QuestionValue
;
945 DISPLAY_QUESTION_OPTION
*Option
;
949 EFI_IFR_ORDERED_LIST
*OrderList
;
950 BOOLEAN ValueInvalid
;
953 Status
= EFI_SUCCESS
;
956 Character
[1] = L
'\0';
957 *OptionString
= NULL
;
958 ValueInvalid
= FALSE
;
960 ZeroMem (FormattedNumber
, 21 * sizeof (CHAR16
));
961 BufferSize
= (gOptionBlockWidth
+ 1) * 2 * gStatementDimensions
.BottomRow
;
963 Question
= MenuOption
->ThisTag
;
964 QuestionValue
= &Question
->CurrentValue
;
966 switch (Question
->OpCode
->OpCode
) {
967 case EFI_IFR_ORDERED_LIST_OP
:
970 // Check whether there are Options of this OrderedList
972 if (IsListEmpty (&Question
->OptionListHead
)) {
976 OrderList
= (EFI_IFR_ORDERED_LIST
*) Question
->OpCode
;
978 Link
= GetFirstNode (&Question
->OptionListHead
);
979 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
981 ValueType
= OneOfOption
->OptionOpCode
->Type
;
982 ValueArray
= Question
->CurrentValue
.Buffer
;
988 Status
= GetSelectionInputPopUp (MenuOption
);
991 // We now know how many strings we will have, so we can allocate the
992 // space required for the array or strings.
994 MaxLen
= OrderList
->MaxContainers
* BufferSize
/ sizeof (CHAR16
);
995 *OptionString
= AllocateZeroPool (MaxLen
* sizeof (CHAR16
));
996 ASSERT (*OptionString
);
998 HiiValue
.Type
= ValueType
;
999 HiiValue
.Value
.u64
= 0;
1000 for (Index
= 0; Index
< OrderList
->MaxContainers
; Index
++) {
1001 HiiValue
.Value
.u64
= GetArrayData (ValueArray
, ValueType
, Index
);
1002 if (HiiValue
.Value
.u64
== 0) {
1004 // Values for the options in ordered lists should never be a 0
1009 OneOfOption
= ValueToOption (Question
, &HiiValue
);
1010 if (OneOfOption
== NULL
) {
1011 if (SkipErrorValue
) {
1013 // Just try to get the option string, skip the value which not has option.
1019 // Show error message
1022 CreateDialog (&Key
, gEmptyString
, gOptionMismatch
, gPressEnter
, gEmptyString
, NULL
);
1023 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1026 // The initial value of the orderedlist is invalid, force to be valid value
1027 // Exit current DisplayForm with new value.
1029 gUserInput
->SelectedStatement
= Question
;
1031 ValueArray
= AllocateZeroPool (Question
->CurrentValue
.BufferLen
);
1032 ASSERT (ValueArray
!= NULL
);
1033 gUserInput
->InputValue
.Buffer
= ValueArray
;
1034 gUserInput
->InputValue
.BufferLen
= Question
->CurrentValue
.BufferLen
;
1035 gUserInput
->InputValue
.Type
= Question
->CurrentValue
.Type
;
1037 Link
= GetFirstNode (&Question
->OptionListHead
);
1039 while (!IsNull (&Question
->OptionListHead
, Link
) && Index2
< OrderList
->MaxContainers
) {
1040 Option
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1041 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1042 SetArrayData (ValueArray
, ValueType
, Index2
, Option
->OptionOpCode
->Value
.u64
);
1045 SetArrayData (ValueArray
, ValueType
, Index2
, 0);
1047 FreePool (*OptionString
);
1048 *OptionString
= NULL
;
1049 return EFI_NOT_FOUND
;
1052 Character
[0] = LEFT_ONEOF_DELIMITER
;
1053 NewStrCat (OptionString
[0], MaxLen
, Character
);
1054 StringPtr
= GetToken (OneOfOption
->OptionOpCode
->Option
, gFormData
->HiiHandle
);
1055 ASSERT (StringPtr
!= NULL
);
1056 NewStrCat (OptionString
[0], MaxLen
, StringPtr
);
1057 Character
[0] = RIGHT_ONEOF_DELIMITER
;
1058 NewStrCat (OptionString
[0], MaxLen
, Character
);
1059 Character
[0] = CHAR_CARRIAGE_RETURN
;
1060 NewStrCat (OptionString
[0], MaxLen
, Character
);
1061 FreePool (StringPtr
);
1065 // If valid option more than the max container, skip these options.
1067 if (Index
>= OrderList
->MaxContainers
) {
1072 // Search the other options, try to find the one not in the container.
1074 Link
= GetFirstNode (&Question
->OptionListHead
);
1075 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1076 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1077 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1079 if (FindArrayData (ValueArray
, ValueType
, OneOfOption
->OptionOpCode
->Value
.u64
, NULL
)) {
1083 if (SkipErrorValue
) {
1085 // Not report error, just get the correct option string info.
1087 Character
[0] = LEFT_ONEOF_DELIMITER
;
1088 NewStrCat (OptionString
[0], MaxLen
, Character
);
1089 StringPtr
= GetToken (OneOfOption
->OptionOpCode
->Option
, gFormData
->HiiHandle
);
1090 ASSERT (StringPtr
!= NULL
);
1091 NewStrCat (OptionString
[0], MaxLen
, StringPtr
);
1092 Character
[0] = RIGHT_ONEOF_DELIMITER
;
1093 NewStrCat (OptionString
[0], MaxLen
, Character
);
1094 Character
[0] = CHAR_CARRIAGE_RETURN
;
1095 NewStrCat (OptionString
[0], MaxLen
, Character
);
1096 FreePool (StringPtr
);
1101 if (!ValueInvalid
) {
1102 ValueInvalid
= TRUE
;
1104 // Show error message
1107 CreateDialog (&Key
, gEmptyString
, gOptionMismatch
, gPressEnter
, gEmptyString
, NULL
);
1108 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1111 // The initial value of the orderedlist is invalid, force to be valid value
1112 // Exit current DisplayForm with new value.
1114 gUserInput
->SelectedStatement
= Question
;
1116 ValueArray
= AllocateCopyPool (Question
->CurrentValue
.BufferLen
, Question
->CurrentValue
.Buffer
);
1117 ASSERT (ValueArray
!= NULL
);
1118 gUserInput
->InputValue
.Buffer
= ValueArray
;
1119 gUserInput
->InputValue
.BufferLen
= Question
->CurrentValue
.BufferLen
;
1120 gUserInput
->InputValue
.Type
= Question
->CurrentValue
.Type
;
1123 SetArrayData (ValueArray
, ValueType
, Index
++, OneOfOption
->OptionOpCode
->Value
.u64
);
1127 FreePool (*OptionString
);
1128 *OptionString
= NULL
;
1129 return EFI_NOT_FOUND
;
1134 case EFI_IFR_ONE_OF_OP
:
1136 // Check whether there are Options of this OneOf
1138 if (IsListEmpty (&Question
->OptionListHead
)) {
1145 Status
= GetSelectionInputPopUp (MenuOption
);
1147 MaxLen
= BufferSize
/ sizeof(CHAR16
);
1148 *OptionString
= AllocateZeroPool (BufferSize
);
1149 ASSERT (*OptionString
);
1151 OneOfOption
= ValueToOption (Question
, QuestionValue
);
1152 if (OneOfOption
== NULL
) {
1153 if (SkipErrorValue
) {
1155 // Not report error, just get the correct option string info.
1157 Link
= GetFirstNode (&Question
->OptionListHead
);
1158 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1161 // Show error message
1164 CreateDialog (&Key
, gEmptyString
, gOptionMismatch
, gPressEnter
, gEmptyString
, NULL
);
1165 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
1168 // Force the Question value to be valid
1169 // Exit current DisplayForm with new value.
1171 Link
= GetFirstNode (&Question
->OptionListHead
);
1172 Option
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1174 gUserInput
->InputValue
.Type
= Option
->OptionOpCode
->Type
;
1175 switch (gUserInput
->InputValue
.Type
) {
1176 case EFI_IFR_TYPE_NUM_SIZE_8
:
1177 gUserInput
->InputValue
.Value
.u8
= Option
->OptionOpCode
->Value
.u8
;
1179 case EFI_IFR_TYPE_NUM_SIZE_16
:
1180 CopyMem (&gUserInput
->InputValue
.Value
.u16
, &Option
->OptionOpCode
->Value
.u16
, sizeof (UINT16
));
1182 case EFI_IFR_TYPE_NUM_SIZE_32
:
1183 CopyMem (&gUserInput
->InputValue
.Value
.u32
, &Option
->OptionOpCode
->Value
.u32
, sizeof (UINT32
));
1185 case EFI_IFR_TYPE_NUM_SIZE_64
:
1186 CopyMem (&gUserInput
->InputValue
.Value
.u64
, &Option
->OptionOpCode
->Value
.u64
, sizeof (UINT64
));
1192 gUserInput
->SelectedStatement
= Question
;
1194 FreePool (*OptionString
);
1195 *OptionString
= NULL
;
1196 return EFI_NOT_FOUND
;
1200 Character
[0] = LEFT_ONEOF_DELIMITER
;
1201 NewStrCat (OptionString
[0], MaxLen
, Character
);
1202 StringPtr
= GetToken (OneOfOption
->OptionOpCode
->Option
, gFormData
->HiiHandle
);
1203 ASSERT (StringPtr
!= NULL
);
1204 NewStrCat (OptionString
[0], MaxLen
, StringPtr
);
1205 Character
[0] = RIGHT_ONEOF_DELIMITER
;
1206 NewStrCat (OptionString
[0], MaxLen
, Character
);
1208 FreePool (StringPtr
);
1212 case EFI_IFR_CHECKBOX_OP
:
1215 // Since this is a BOOLEAN operation, flip it upon selection
1217 gUserInput
->InputValue
.Type
= QuestionValue
->Type
;
1218 gUserInput
->InputValue
.Value
.b
= (BOOLEAN
) (QuestionValue
->Value
.b
? FALSE
: TRUE
);
1221 // Perform inconsistent check
1225 *OptionString
= AllocateZeroPool (BufferSize
);
1226 ASSERT (*OptionString
);
1228 *OptionString
[0] = LEFT_CHECKBOX_DELIMITER
;
1230 if (QuestionValue
->Value
.b
) {
1231 *(OptionString
[0] + 1) = CHECK_ON
;
1233 *(OptionString
[0] + 1) = CHECK_OFF
;
1235 *(OptionString
[0] + 2) = RIGHT_CHECKBOX_DELIMITER
;
1239 case EFI_IFR_NUMERIC_OP
:
1244 Status
= GetNumericInput (MenuOption
);
1246 *OptionString
= AllocateZeroPool (BufferSize
);
1247 ASSERT (*OptionString
);
1249 *OptionString
[0] = LEFT_NUMERIC_DELIMITER
;
1254 PrintFormattedNumber (Question
, FormattedNumber
, 21 * sizeof (CHAR16
));
1255 Number
= (UINT16
) GetStringWidth (FormattedNumber
);
1256 CopyMem (OptionString
[0] + 1, FormattedNumber
, Number
);
1258 *(OptionString
[0] + Number
/ 2) = RIGHT_NUMERIC_DELIMITER
;
1262 case EFI_IFR_DATE_OP
:
1265 // This is similar to numerics
1267 Status
= GetNumericInput (MenuOption
);
1269 *OptionString
= AllocateZeroPool (BufferSize
);
1270 ASSERT (*OptionString
);
1272 switch (MenuOption
->Sequence
) {
1274 *OptionString
[0] = LEFT_NUMERIC_DELIMITER
;
1275 if (QuestionValue
->Value
.date
.Month
== 0xff){
1276 UnicodeSPrint (OptionString
[0] + 1, 21 * sizeof (CHAR16
), L
"??");
1278 UnicodeSPrint (OptionString
[0] + 1, 21 * sizeof (CHAR16
), L
"%02d", QuestionValue
->Value
.date
.Month
);
1280 *(OptionString
[0] + 3) = DATE_SEPARATOR
;
1284 SetUnicodeMem (OptionString
[0], 4, L
' ');
1285 if (QuestionValue
->Value
.date
.Day
== 0xff){
1286 UnicodeSPrint (OptionString
[0] + 4, 21 * sizeof (CHAR16
), L
"??");
1288 UnicodeSPrint (OptionString
[0] + 4, 21 * sizeof (CHAR16
), L
"%02d", QuestionValue
->Value
.date
.Day
);
1290 *(OptionString
[0] + 6) = DATE_SEPARATOR
;
1294 SetUnicodeMem (OptionString
[0], 7, L
' ');
1295 if (QuestionValue
->Value
.date
.Year
== 0xff){
1296 UnicodeSPrint (OptionString
[0] + 7, 21 * sizeof (CHAR16
), L
"????");
1298 UnicodeSPrint (OptionString
[0] + 7, 21 * sizeof (CHAR16
), L
"%04d", QuestionValue
->Value
.date
.Year
);
1300 *(OptionString
[0] + 11) = RIGHT_NUMERIC_DELIMITER
;
1306 case EFI_IFR_TIME_OP
:
1309 // This is similar to numerics
1311 Status
= GetNumericInput (MenuOption
);
1313 *OptionString
= AllocateZeroPool (BufferSize
);
1314 ASSERT (*OptionString
);
1316 switch (MenuOption
->Sequence
) {
1318 *OptionString
[0] = LEFT_NUMERIC_DELIMITER
;
1319 if (QuestionValue
->Value
.time
.Hour
== 0xff){
1320 UnicodeSPrint (OptionString
[0] + 1, 21 * sizeof (CHAR16
), L
"??");
1322 UnicodeSPrint (OptionString
[0] + 1, 21 * sizeof (CHAR16
), L
"%02d", QuestionValue
->Value
.time
.Hour
);
1324 *(OptionString
[0] + 3) = TIME_SEPARATOR
;
1328 SetUnicodeMem (OptionString
[0], 4, L
' ');
1329 if (QuestionValue
->Value
.time
.Minute
== 0xff){
1330 UnicodeSPrint (OptionString
[0] + 4, 21 * sizeof (CHAR16
), L
"??");
1332 UnicodeSPrint (OptionString
[0] + 4, 21 * sizeof (CHAR16
), L
"%02d", QuestionValue
->Value
.time
.Minute
);
1334 *(OptionString
[0] + 6) = TIME_SEPARATOR
;
1338 SetUnicodeMem (OptionString
[0], 7, L
' ');
1339 if (QuestionValue
->Value
.time
.Second
== 0xff){
1340 UnicodeSPrint (OptionString
[0] + 7, 21 * sizeof (CHAR16
), L
"??");
1342 UnicodeSPrint (OptionString
[0] + 7, 21 * sizeof (CHAR16
), L
"%02d", QuestionValue
->Value
.time
.Second
);
1344 *(OptionString
[0] + 9) = RIGHT_NUMERIC_DELIMITER
;
1350 case EFI_IFR_STRING_OP
:
1352 StringPtr
= AllocateZeroPool (Question
->CurrentValue
.BufferLen
+ sizeof (CHAR16
));
1354 CopyMem(StringPtr
, Question
->CurrentValue
.Buffer
, Question
->CurrentValue
.BufferLen
);
1356 Status
= ReadString (MenuOption
, gPromptForData
, StringPtr
);
1357 if (EFI_ERROR (Status
)) {
1358 FreePool (StringPtr
);
1362 gUserInput
->InputValue
.Buffer
= AllocateCopyPool (Question
->CurrentValue
.BufferLen
, StringPtr
);
1363 gUserInput
->InputValue
.BufferLen
= Question
->CurrentValue
.BufferLen
;
1364 gUserInput
->InputValue
.Type
= Question
->CurrentValue
.Type
;
1365 gUserInput
->InputValue
.Value
.string
= HiiSetString(gFormData
->HiiHandle
, gUserInput
->InputValue
.Value
.string
, StringPtr
, NULL
);
1366 FreePool (StringPtr
);
1369 *OptionString
= AllocateZeroPool (BufferSize
);
1370 ASSERT (*OptionString
);
1372 if (((CHAR16
*) Question
->CurrentValue
.Buffer
)[0] == 0x0000) {
1373 *(OptionString
[0]) = '_';
1375 if (Question
->CurrentValue
.BufferLen
< BufferSize
) {
1376 BufferSize
= Question
->CurrentValue
.BufferLen
;
1378 CopyMem (OptionString
[0], (CHAR16
*) Question
->CurrentValue
.Buffer
, BufferSize
);
1383 case EFI_IFR_PASSWORD_OP
:
1385 Status
= PasswordProcess (MenuOption
);
1398 Process the help string: Split StringPtr to several lines of strings stored in
1399 FormattedString and the glyph width of each line cannot exceed gHelpBlockWidth.
1401 @param StringPtr The entire help string.
1402 @param FormattedString The oupput formatted string.
1403 @param EachLineWidth The max string length of each line in the formatted string.
1404 @param RowCount TRUE: if Question is selected.
1409 IN CHAR16
*StringPtr
,
1410 OUT CHAR16
**FormattedString
,
1411 OUT UINT16
*EachLineWidth
,
1416 CHAR16
*OutputString
;
1421 UINT16 MaxStringLen
;
1432 // Set default help string width.
1434 LineWidth
= (UINT16
) (gHelpBlockWidth
- 1);
1437 // Get row number of the String.
1439 while ((StringLen
= GetLineByWidth (StringPtr
, LineWidth
, &GlyphWidth
, &Index
, &OutputString
)) != 0) {
1440 if (StringLen
> MaxStringLen
) {
1441 MaxStringLen
= StringLen
;
1445 FreePool (OutputString
);
1447 *EachLineWidth
= MaxStringLen
;
1449 *FormattedString
= AllocateZeroPool (TotalRowNum
* MaxStringLen
* sizeof (CHAR16
));
1450 ASSERT (*FormattedString
!= NULL
);
1453 // Generate formatted help string array.
1457 while((StringLen
= GetLineByWidth (StringPtr
, LineWidth
, &GlyphWidth
, &Index
, &OutputString
)) != 0) {
1458 CopyMem (*FormattedString
+ CheckedNum
* MaxStringLen
, OutputString
, StringLen
* sizeof (CHAR16
));
1460 FreePool (OutputString
);