2 Implementation for handling user input from the User Interfaces.
4 Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "FormDisplay.h"
18 Get maximum and minimum info from this opcode.
20 @param OpCode Pointer to the current input opcode.
21 @param Minimum The minimum size info for this opcode.
22 @param Maximum The maximum size info for this opcode.
27 IN EFI_IFR_OP_HEADER
*OpCode
,
32 EFI_IFR_STRING
*StringOp
;
33 EFI_IFR_PASSWORD
*PasswordOp
;
34 if (OpCode
->OpCode
== EFI_IFR_STRING_OP
) {
35 StringOp
= (EFI_IFR_STRING
*) OpCode
;
36 *Minimum
= StringOp
->MinSize
;
37 *Maximum
= StringOp
->MaxSize
;
38 } else if (OpCode
->OpCode
== EFI_IFR_PASSWORD_OP
) {
39 PasswordOp
= (EFI_IFR_PASSWORD
*) OpCode
;
40 *Minimum
= PasswordOp
->MinSize
;
41 *Maximum
= PasswordOp
->MaxSize
;
49 Get string or password input from user.
51 @param MenuOption Pointer to the current input menu.
52 @param Prompt The prompt string shown on popup window.
53 @param StringPtr Old user input and destination for use input string.
55 @retval EFI_SUCCESS If string input is read successfully
56 @retval EFI_DEVICE_ERROR If operation fails
61 IN UI_MENU_OPTION
*MenuOption
,
63 IN OUT CHAR16
*StringPtr
73 CHAR16
*BufferedString
;
79 UINTN DimensionsWidth
;
80 UINTN DimensionsHeight
;
82 BOOLEAN CursorVisible
;
85 FORM_DISPLAY_ENGINE_STATEMENT
*Question
;
88 DimensionsWidth
= gStatementDimensions
.RightColumn
- gStatementDimensions
.LeftColumn
;
89 DimensionsHeight
= gStatementDimensions
.BottomRow
- gStatementDimensions
.TopRow
;
91 NullCharacter
= CHAR_NULL
;
92 ScreenSize
= GetStringWidth (Prompt
) / sizeof (CHAR16
);
96 Question
= MenuOption
->ThisTag
;
97 GetFieldFromOp(Question
->OpCode
, &Minimum
, &Maximum
);
99 if (Question
->OpCode
->OpCode
== EFI_IFR_PASSWORD_OP
) {
105 TempString
= AllocateZeroPool ((Maximum
+ 1)* sizeof (CHAR16
));
108 if (ScreenSize
< (Maximum
+ 1)) {
109 ScreenSize
= Maximum
+ 1;
112 if ((ScreenSize
+ 2) > DimensionsWidth
) {
113 ScreenSize
= DimensionsWidth
- 2;
116 BufferedString
= AllocateZeroPool (ScreenSize
* 2);
117 ASSERT (BufferedString
);
119 Start
= (DimensionsWidth
- ScreenSize
- 2) / 2 + gStatementDimensions
.LeftColumn
+ 1;
120 Top
= ((DimensionsHeight
- 6) / 2) + gStatementDimensions
.TopRow
- 1;
123 // Display prompt for string
125 // CreateDialog (NULL, "", Prompt, Space, "", NULL);
126 CreateMultiStringPopUp (ScreenSize
, 4, &NullCharacter
, Prompt
, Space
, &NullCharacter
);
127 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_BLACK
, EFI_LIGHTGRAY
));
129 CursorVisible
= gST
->ConOut
->Mode
->CursorVisible
;
130 gST
->ConOut
->EnableCursor (gST
->ConOut
, TRUE
);
132 CurrentCursor
= GetStringWidth (StringPtr
) / 2 - 1;
133 if (CurrentCursor
!= 0) {
135 // Show the string which has beed saved before.
137 SetUnicodeMem (BufferedString
, ScreenSize
- 1, L
' ');
138 PrintStringAt (Start
+ 1, Top
+ 3, BufferedString
);
140 if ((GetStringWidth (StringPtr
) / 2) > (DimensionsWidth
- 2)) {
141 Index
= (GetStringWidth (StringPtr
) / 2) - DimensionsWidth
+ 2;
147 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Start
+ 1, Top
+ 3);
150 for (Count
= 0; Index
+ 1 < GetStringWidth (StringPtr
) / 2; Index
++, Count
++) {
151 BufferedString
[Count
] = StringPtr
[Index
];
154 PrintCharAt ((UINTN
)-1, (UINTN
)-1, L
'*');
159 PrintStringAt (Start
+ 1, Top
+ 3, BufferedString
);
162 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
163 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Start
+ GetStringWidth (StringPtr
) / 2, Top
+ 3);
167 Status
= WaitForKeyStroke (&Key
);
168 ASSERT_EFI_ERROR (Status
);
170 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_BLACK
, EFI_LIGHTGRAY
));
171 switch (Key
.UnicodeChar
) {
173 switch (Key
.ScanCode
) {
175 if (CurrentCursor
> 0) {
181 if (CurrentCursor
< (GetStringWidth (StringPtr
) / 2 - 1)) {
187 FreePool (TempString
);
188 FreePool (BufferedString
);
189 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
190 gST
->ConOut
->EnableCursor (gST
->ConOut
, CursorVisible
);
191 return EFI_DEVICE_ERROR
;
199 case CHAR_CARRIAGE_RETURN
:
200 if (GetStringWidth (StringPtr
) >= ((Minimum
+ 1) * sizeof (CHAR16
))) {
202 FreePool (TempString
);
203 FreePool (BufferedString
);
204 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
205 gST
->ConOut
->EnableCursor (gST
->ConOut
, CursorVisible
);
209 // Simply create a popup to tell the user that they had typed in too few characters.
210 // To save code space, we can then treat this as an error and return back to the menu.
213 CreateDialog (&Key
, &NullCharacter
, gMiniString
, gPressEnter
, &NullCharacter
, NULL
);
214 } while (Key
.UnicodeChar
!= CHAR_CARRIAGE_RETURN
);
216 FreePool (TempString
);
217 FreePool (BufferedString
);
218 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
219 gST
->ConOut
->EnableCursor (gST
->ConOut
, CursorVisible
);
220 return EFI_DEVICE_ERROR
;
226 if (StringPtr
[0] != CHAR_NULL
&& CurrentCursor
!= 0) {
227 for (Index
= 0; Index
< CurrentCursor
- 1; Index
++) {
228 TempString
[Index
] = StringPtr
[Index
];
230 Count
= GetStringWidth (StringPtr
) / 2 - 1;
231 if (Count
>= CurrentCursor
) {
232 for (Index
= CurrentCursor
- 1, Index2
= CurrentCursor
; Index2
< Count
; Index
++, Index2
++) {
233 TempString
[Index
] = StringPtr
[Index2
];
235 TempString
[Index
] = CHAR_NULL
;
238 // Effectively truncate string by 1 character
240 StrCpy (StringPtr
, TempString
);
246 // If it is the beginning of the string, don't worry about checking maximum limits
248 if ((StringPtr
[0] == CHAR_NULL
) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
249 StrnCpy (StringPtr
, &Key
.UnicodeChar
, 1);
251 } else if ((GetStringWidth (StringPtr
) < ((Maximum
+ 1) * sizeof (CHAR16
))) && (Key
.UnicodeChar
!= CHAR_BACKSPACE
)) {
252 KeyPad
[0] = Key
.UnicodeChar
;
253 KeyPad
[1] = CHAR_NULL
;
254 Count
= GetStringWidth (StringPtr
) / 2 - 1;
255 if (CurrentCursor
< Count
) {
256 for (Index
= 0; Index
< CurrentCursor
; Index
++) {
257 TempString
[Index
] = StringPtr
[Index
];
259 TempString
[Index
] = CHAR_NULL
;
260 StrCat (TempString
, KeyPad
);
261 StrCat (TempString
, StringPtr
+ CurrentCursor
);
262 StrCpy (StringPtr
, TempString
);
264 StrCat (StringPtr
, KeyPad
);
270 // If the width of the input string is now larger than the screen, we nee to
271 // adjust the index to start printing portions of the string
273 SetUnicodeMem (BufferedString
, ScreenSize
- 1, L
' ');
274 PrintStringAt (Start
+ 1, Top
+ 3, BufferedString
);
276 if ((GetStringWidth (StringPtr
) / 2) > (DimensionsWidth
- 2)) {
277 Index
= (GetStringWidth (StringPtr
) / 2) - DimensionsWidth
+ 2;
283 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Start
+ 1, Top
+ 3);
286 for (Count
= 0; Index
+ 1 < GetStringWidth (StringPtr
) / 2; Index
++, Count
++) {
287 BufferedString
[Count
] = StringPtr
[Index
];
290 PrintCharAt ((UINTN
)-1, (UINTN
)-1, L
'*');
295 PrintStringAt (Start
+ 1, Top
+ 3, BufferedString
);
300 gST
->ConOut
->SetAttribute (gST
->ConOut
, EFI_TEXT_ATTR (EFI_LIGHTGRAY
, EFI_BLACK
));
301 gST
->ConOut
->SetCursorPosition (gST
->ConOut
, Start
+ CurrentCursor
+ 1, Top
+ 3);
307 Adjust the value to the correct one. Rules follow the sample:
308 like: Year change: 2012.02.29 -> 2013.02.29 -> 2013.02.01
309 Month change: 2013.03.29 -> 2013.02.29 -> 2013.02.28
311 @param QuestionValue Pointer to current question.
312 @param Sequence The sequence of the field in the question.
315 AdjustQuestionValue (
316 IN EFI_HII_VALUE
*QuestionValue
,
325 Month
= QuestionValue
->Value
.date
.Month
;
326 Year
= QuestionValue
->Value
.date
.Year
;
331 if ((Year
% 4) == 0 && ((Year
% 100) != 0 || (Year
% 400) == 0)) {
349 // Change the month area.
352 if (QuestionValue
->Value
.date
.Day
> Maximum
) {
353 QuestionValue
->Value
.date
.Day
= Maximum
;
358 // Change the Year area.
361 if (QuestionValue
->Value
.date
.Day
> Maximum
) {
362 QuestionValue
->Value
.date
.Day
= Minimum
;
368 Get field info from numeric opcode.
370 @param OpCode Pointer to the current input opcode.
371 @param Minimum The minimum size info for this opcode.
372 @param Maximum The maximum size info for this opcode.
373 @param Step The step size info for this opcode.
374 @param StorageWidth The storage width info for this opcode.
379 IN EFI_IFR_OP_HEADER
*OpCode
,
383 OUT UINT16
*StorageWidth
386 EFI_IFR_NUMERIC
*NumericOp
;
388 NumericOp
= (EFI_IFR_NUMERIC
*) OpCode
;
390 switch (NumericOp
->Flags
& EFI_IFR_NUMERIC_SIZE
) {
391 case EFI_IFR_NUMERIC_SIZE_1
:
392 *Minimum
= NumericOp
->data
.u8
.MinValue
;
393 *Maximum
= NumericOp
->data
.u8
.MaxValue
;
394 *Step
= NumericOp
->data
.u8
.Step
;
395 *StorageWidth
= (UINT16
) sizeof (UINT8
);
398 case EFI_IFR_NUMERIC_SIZE_2
:
399 *Minimum
= NumericOp
->data
.u16
.MinValue
;
400 *Maximum
= NumericOp
->data
.u16
.MaxValue
;
401 *Step
= NumericOp
->data
.u16
.Step
;
402 *StorageWidth
= (UINT16
) sizeof (UINT16
);
405 case EFI_IFR_NUMERIC_SIZE_4
:
406 *Minimum
= NumericOp
->data
.u32
.MinValue
;
407 *Maximum
= NumericOp
->data
.u32
.MaxValue
;
408 *Step
= NumericOp
->data
.u32
.Step
;
409 *StorageWidth
= (UINT16
) sizeof (UINT32
);
412 case EFI_IFR_NUMERIC_SIZE_8
:
413 *Minimum
= NumericOp
->data
.u64
.MinValue
;
414 *Maximum
= NumericOp
->data
.u64
.MaxValue
;
415 *Step
= NumericOp
->data
.u64
.Step
;
416 *StorageWidth
= (UINT16
) sizeof (UINT64
);
424 *Maximum
= (UINT64
) -1;
429 This routine reads a numeric value from the user input.
431 @param MenuOption Pointer to the current input menu.
433 @retval EFI_SUCCESS If numerical input is read successfully
434 @retval EFI_DEVICE_ERROR If operation fails
439 IN UI_MENU_OPTION
*MenuOption
444 CHAR16 InputText
[MAX_NUMERIC_INPUT_WIDTH
];
445 CHAR16 FormattedNumber
[MAX_NUMERIC_INPUT_WIDTH
- 1];
446 UINT64 PreviousNumber
[MAX_NUMERIC_INPUT_WIDTH
- 3];
460 EFI_HII_VALUE
*QuestionValue
;
461 FORM_DISPLAY_ENGINE_STATEMENT
*Question
;
462 EFI_IFR_NUMERIC
*NumericOp
;
465 Column
= MenuOption
->OptCol
;
466 Row
= MenuOption
->Row
;
467 PreviousNumber
[0] = 0;
476 Question
= MenuOption
->ThisTag
;
477 QuestionValue
= &Question
->CurrentValue
;
480 // Only two case, user can enter to this function: Enter and +/- case.
481 // In Enter case, gDirection = 0; in +/- case, gDirection = SCAN_LEFT/SCAN_WRIGHT
483 ManualInput
= (BOOLEAN
)(gDirection
== 0 ? TRUE
: FALSE
);
485 if ((Question
->OpCode
->OpCode
== EFI_IFR_DATE_OP
) || (Question
->OpCode
->OpCode
== EFI_IFR_TIME_OP
)) {
492 // Prepare Value to be edit
496 if (Question
->OpCode
->OpCode
== EFI_IFR_DATE_OP
) {
500 switch (MenuOption
->Sequence
) {
504 EditValue
= QuestionValue
->Value
.date
.Month
;
508 switch (QuestionValue
->Value
.date
.Month
) {
510 if ((QuestionValue
->Value
.date
.Year
% 4) == 0 &&
511 ((QuestionValue
->Value
.date
.Year
% 100) != 0 ||
512 (QuestionValue
->Value
.date
.Year
% 400) == 0)) {
530 EditValue
= QuestionValue
->Value
.date
.Day
;
536 EditValue
= QuestionValue
->Value
.date
.Year
;
542 } else if (Question
->OpCode
->OpCode
== EFI_IFR_TIME_OP
) {
546 switch (MenuOption
->Sequence
) {
550 EditValue
= QuestionValue
->Value
.time
.Hour
;
556 EditValue
= QuestionValue
->Value
.time
.Minute
;
562 EditValue
= QuestionValue
->Value
.time
.Second
;
569 ASSERT (Question
->OpCode
->OpCode
== EFI_IFR_NUMERIC_OP
);
570 NumericOp
= (EFI_IFR_NUMERIC
*) Question
->OpCode
;
571 GetValueFromNum(Question
->OpCode
, &Minimum
, &Maximum
, &Step
, &StorageWidth
);
572 EditValue
= QuestionValue
->Value
.u64
;
573 EraseLen
= gOptionBlockWidth
;
576 if ((Question
->OpCode
->OpCode
== EFI_IFR_NUMERIC_OP
) && (NumericOp
!= NULL
) &&
577 ((NumericOp
->Flags
& EFI_IFR_DISPLAY
) == EFI_IFR_DISPLAY_UINT_HEX
)) {
584 // Enter from "Enter" input, clear the old word showing.
587 if (Question
->OpCode
->OpCode
== EFI_IFR_NUMERIC_OP
) {
589 InputWidth
= StorageWidth
* 2;
591 switch (StorageWidth
) {
614 InputText
[0] = LEFT_NUMERIC_DELIMITER
;
615 SetUnicodeMem (InputText
+ 1, InputWidth
, L
' ');
616 ASSERT (InputWidth
+ 2 < MAX_NUMERIC_INPUT_WIDTH
);
617 InputText
[InputWidth
+ 1] = RIGHT_NUMERIC_DELIMITER
;
618 InputText
[InputWidth
+ 2] = L
'\0';
620 PrintStringAt (Column
, Row
, InputText
);
624 if (Question
->OpCode
->OpCode
== EFI_IFR_DATE_OP
) {
625 if (MenuOption
->Sequence
== 2) {
631 if (MenuOption
->Sequence
== 0) {
632 InputText
[0] = LEFT_NUMERIC_DELIMITER
;
633 SetUnicodeMem (InputText
+ 1, InputWidth
, L
' ');
635 SetUnicodeMem (InputText
, InputWidth
, L
' ');
638 if (MenuOption
->Sequence
== 2) {
639 InputText
[InputWidth
+ 1] = RIGHT_NUMERIC_DELIMITER
;
641 InputText
[InputWidth
+ 1] = DATE_SEPARATOR
;
643 InputText
[InputWidth
+ 2] = L
'\0';
645 PrintStringAt (Column
, Row
, InputText
);
646 if (MenuOption
->Sequence
== 0) {
651 if (Question
->OpCode
->OpCode
== EFI_IFR_TIME_OP
) {
654 if (MenuOption
->Sequence
== 0) {
655 InputText
[0] = LEFT_NUMERIC_DELIMITER
;
656 SetUnicodeMem (InputText
+ 1, InputWidth
, L
' ');
658 SetUnicodeMem (InputText
, InputWidth
, L
' ');
661 if (MenuOption
->Sequence
== 2) {
662 InputText
[InputWidth
+ 1] = RIGHT_NUMERIC_DELIMITER
;
664 InputText
[InputWidth
+ 1] = TIME_SEPARATOR
;
666 InputText
[InputWidth
+ 2] = L
'\0';
668 PrintStringAt (Column
, Row
, InputText
);
669 if (MenuOption
->Sequence
== 0) {
676 // First time we enter this handler, we need to check to see if
677 // we were passed an increment or decrement directive
680 Key
.UnicodeChar
= CHAR_NULL
;
681 if (gDirection
!= 0) {
682 Key
.ScanCode
= gDirection
;
687 WaitForKeyStroke (&Key
);
690 switch (Key
.UnicodeChar
) {
694 if (Key
.UnicodeChar
== '+') {
695 Key
.ScanCode
= SCAN_RIGHT
;
697 Key
.ScanCode
= SCAN_LEFT
;
699 Key
.UnicodeChar
= CHAR_NULL
;
703 switch (Key
.ScanCode
) {
706 if (DateOrTime
&& !ManualInput
) {
708 // By setting this value, we will return back to the caller.
709 // We need to do this since an auto-refresh will destroy the adjustment
710 // based on what the real-time-clock is showing. So we always commit
711 // upon changing the value.
713 gDirection
= SCAN_DOWN
;
716 if ((Step
!= 0) && !ManualInput
) {
717 if (Key
.ScanCode
== SCAN_LEFT
) {
718 if (EditValue
>= Minimum
+ Step
) {
719 EditValue
= EditValue
- Step
;
720 } else if (EditValue
> Minimum
){
725 } else if (Key
.ScanCode
== SCAN_RIGHT
) {
726 if (EditValue
+ Step
<= Maximum
) {
727 EditValue
= EditValue
+ Step
;
728 } else if (EditValue
< Maximum
) {
735 ZeroMem (FormattedNumber
, 21 * sizeof (CHAR16
));
736 if (Question
->OpCode
->OpCode
== EFI_IFR_DATE_OP
) {
737 if (MenuOption
->Sequence
== 2) {
741 UnicodeSPrint (FormattedNumber
, 21 * sizeof (CHAR16
), L
"%04d", (UINT16
) EditValue
);
746 UnicodeSPrint (FormattedNumber
, 21 * sizeof (CHAR16
), L
"%02d", (UINT8
) EditValue
);
749 if (MenuOption
->Sequence
== 0) {
750 ASSERT (EraseLen
>= 2);
751 FormattedNumber
[EraseLen
- 2] = DATE_SEPARATOR
;
752 } else if (MenuOption
->Sequence
== 1) {
753 ASSERT (EraseLen
>= 1);
754 FormattedNumber
[EraseLen
- 1] = DATE_SEPARATOR
;
756 } else if (Question
->OpCode
->OpCode
== EFI_IFR_TIME_OP
) {
757 UnicodeSPrint (FormattedNumber
, 21 * sizeof (CHAR16
), L
"%02d", (UINT8
) EditValue
);
759 if (MenuOption
->Sequence
== 0) {
760 ASSERT (EraseLen
>= 2);
761 FormattedNumber
[EraseLen
- 2] = TIME_SEPARATOR
;
762 } else if (MenuOption
->Sequence
== 1) {
763 ASSERT (EraseLen
>= 1);
764 FormattedNumber
[EraseLen
- 1] = TIME_SEPARATOR
;
767 QuestionValue
->Value
.u64
= EditValue
;
768 PrintFormattedNumber (Question
, FormattedNumber
, 21 * sizeof (CHAR16
));
771 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetFieldTextColor ());
772 for (Loop
= 0; Loop
< EraseLen
; Loop
++) {
773 PrintStringAt (MenuOption
->OptCol
+ Loop
, MenuOption
->Row
, L
" ");
775 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetHighlightTextColor ());
777 if (MenuOption
->Sequence
== 0) {
778 PrintCharAt (MenuOption
->OptCol
, Row
, LEFT_NUMERIC_DELIMITER
);
779 Column
= MenuOption
->OptCol
+ 1;
782 PrintStringAt (Column
, Row
, FormattedNumber
);
784 if (!DateOrTime
|| MenuOption
->Sequence
== 2) {
785 PrintCharAt ((UINTN
)-1, (UINTN
)-1, RIGHT_NUMERIC_DELIMITER
);
789 goto EnterCarriageReturn
;
794 goto EnterCarriageReturn
;
797 return EFI_DEVICE_ERROR
;
807 case CHAR_CARRIAGE_RETURN
:
809 // Validate input value with Minimum value.
811 if (EditValue
< Minimum
) {
812 UpdateStatusBar (INPUT_ERROR
, TRUE
);
815 UpdateStatusBar (INPUT_ERROR
, FALSE
);
818 CopyMem (&gUserInput
->InputValue
, &Question
->CurrentValue
, sizeof (EFI_HII_VALUE
));
819 QuestionValue
= &gUserInput
->InputValue
;
821 // Store Edit value back to Question
823 if (Question
->OpCode
->OpCode
== EFI_IFR_DATE_OP
) {
824 switch (MenuOption
->Sequence
) {
826 QuestionValue
->Value
.date
.Month
= (UINT8
) EditValue
;
830 QuestionValue
->Value
.date
.Day
= (UINT8
) EditValue
;
834 QuestionValue
->Value
.date
.Year
= (UINT16
) EditValue
;
840 } else if (Question
->OpCode
->OpCode
== EFI_IFR_TIME_OP
) {
841 switch (MenuOption
->Sequence
) {
843 QuestionValue
->Value
.time
.Hour
= (UINT8
) EditValue
;
847 QuestionValue
->Value
.time
.Minute
= (UINT8
) EditValue
;
851 QuestionValue
->Value
.time
.Second
= (UINT8
) EditValue
;
861 QuestionValue
->Value
.u64
= EditValue
;
865 // Adjust the value to the correct one.
866 // Sample like: 2012.02.29 -> 2013.02.29 -> 2013.02.01
867 // 2013.03.29 -> 2013.02.29 -> 2013.02.28
869 if (Question
->OpCode
->OpCode
== EFI_IFR_DATE_OP
&&
870 (MenuOption
->Sequence
== 0 || MenuOption
->Sequence
== 2)) {
871 AdjustQuestionValue (QuestionValue
, (UINT8
)MenuOption
->Sequence
);
883 // Remove a character
885 EditValue
= PreviousNumber
[Count
- 1];
886 UpdateStatusBar (INPUT_ERROR
, FALSE
);
889 PrintStringAt (Column
, Row
, L
" ");
896 if ((Key
.UnicodeChar
>= L
'0') && (Key
.UnicodeChar
<= L
'9')) {
897 Digital
= (UINT8
) (Key
.UnicodeChar
- L
'0');
898 } else if ((Key
.UnicodeChar
>= L
'A') && (Key
.UnicodeChar
<= L
'F')) {
899 Digital
= (UINT8
) (Key
.UnicodeChar
- L
'A' + 0x0A);
900 } else if ((Key
.UnicodeChar
>= L
'a') && (Key
.UnicodeChar
<= L
'f')) {
901 Digital
= (UINT8
) (Key
.UnicodeChar
- L
'a' + 0x0A);
903 UpdateStatusBar (INPUT_ERROR
, TRUE
);
907 if (Key
.UnicodeChar
> L
'9' || Key
.UnicodeChar
< L
'0') {
908 UpdateStatusBar (INPUT_ERROR
, TRUE
);
914 // If Count exceed input width, there is no way more is valid
916 if (Count
>= InputWidth
) {
920 // Someone typed something valid!
924 EditValue
= LShiftU64 (EditValue
, 4) + Digital
;
926 EditValue
= MultU64x32 (EditValue
, 10) + (Key
.UnicodeChar
- L
'0');
932 EditValue
= Key
.UnicodeChar
- L
'0';
936 if (EditValue
> Maximum
) {
937 UpdateStatusBar (INPUT_ERROR
, TRUE
);
938 ASSERT (Count
< sizeof (PreviousNumber
) / sizeof (PreviousNumber
[0]));
939 EditValue
= PreviousNumber
[Count
];
942 UpdateStatusBar (INPUT_ERROR
, FALSE
);
946 ASSERT (Count
< (sizeof (PreviousNumber
) / sizeof (PreviousNumber
[0])));
947 PreviousNumber
[Count
] = EditValue
;
949 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetHighlightTextColor ());
950 PrintCharAt (Column
, Row
, Key
.UnicodeChar
);
959 Adjust option order base on the question value.
961 @param Question Pointer to current question.
962 @param PopUpMenuLines The line number of the pop up menu.
964 @retval EFI_SUCCESS If Option input is processed successfully
965 @retval EFI_DEVICE_ERROR If operation fails
970 IN FORM_DISPLAY_ENGINE_STATEMENT
*Question
,
971 OUT UINTN
*PopUpMenuLines
975 EFI_IFR_ORDERED_LIST
*OrderList
;
979 DISPLAY_QUESTION_OPTION
*OneOfOption
;
980 EFI_HII_VALUE
*HiiValueArray
;
982 Link
= GetFirstNode (&Question
->OptionListHead
);
983 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
984 ValueArray
= Question
->CurrentValue
.Buffer
;
985 ValueType
= OneOfOption
->OptionOpCode
->Type
;
986 OrderList
= (EFI_IFR_ORDERED_LIST
*) Question
->OpCode
;
988 for (Index
= 0; Index
< OrderList
->MaxContainers
; Index
++) {
989 if (GetArrayData (ValueArray
, ValueType
, Index
) == 0) {
994 *PopUpMenuLines
= Index
;
997 // Prepare HiiValue array
999 HiiValueArray
= AllocateZeroPool (*PopUpMenuLines
* sizeof (EFI_HII_VALUE
));
1000 ASSERT (HiiValueArray
!= NULL
);
1002 for (Index
= 0; Index
< *PopUpMenuLines
; Index
++) {
1003 HiiValueArray
[Index
].Type
= ValueType
;
1004 HiiValueArray
[Index
].Value
.u64
= GetArrayData (ValueArray
, ValueType
, Index
);
1007 for (Index
= 0; Index
< *PopUpMenuLines
; Index
++) {
1008 OneOfOption
= ValueToOption (Question
, &HiiValueArray
[*PopUpMenuLines
- Index
- 1]);
1009 if (OneOfOption
== NULL
) {
1010 return EFI_NOT_FOUND
;
1013 RemoveEntryList (&OneOfOption
->Link
);
1018 InsertHeadList (&Question
->OptionListHead
, &OneOfOption
->Link
);
1021 FreePool (HiiValueArray
);
1027 Base on the type to compare the value.
1029 @param Value1 The first value need to compare.
1030 @param Value2 The second value need to compare.
1031 @param Type The value type for above two values.
1033 @retval TRUE The two value are same.
1034 @retval FALSE The two value are different.
1039 IN EFI_IFR_TYPE_VALUE
*Value1
,
1040 IN EFI_IFR_TYPE_VALUE
*Value2
,
1045 case EFI_IFR_TYPE_BOOLEAN
:
1046 case EFI_IFR_TYPE_NUM_SIZE_8
:
1047 return (BOOLEAN
) (Value1
->u8
== Value2
->u8
);
1049 case EFI_IFR_TYPE_NUM_SIZE_16
:
1050 return (BOOLEAN
) (Value1
->u16
== Value2
->u16
);
1052 case EFI_IFR_TYPE_NUM_SIZE_32
:
1053 return (BOOLEAN
) (Value1
->u32
== Value2
->u32
);
1055 case EFI_IFR_TYPE_NUM_SIZE_64
:
1056 return (BOOLEAN
) (Value1
->u64
== Value2
->u64
);
1065 Base on the type to set the value.
1067 @param Dest The dest value.
1068 @param Source The source value.
1069 @param Type The value type for above two values.
1074 OUT EFI_IFR_TYPE_VALUE
*Dest
,
1075 IN EFI_IFR_TYPE_VALUE
*Source
,
1080 case EFI_IFR_TYPE_BOOLEAN
:
1081 Dest
->b
= Source
->b
;
1084 case EFI_IFR_TYPE_NUM_SIZE_8
:
1085 Dest
->u8
= Source
->u8
;
1088 case EFI_IFR_TYPE_NUM_SIZE_16
:
1089 Dest
->u16
= Source
->u16
;
1092 case EFI_IFR_TYPE_NUM_SIZE_32
:
1093 Dest
->u32
= Source
->u32
;
1096 case EFI_IFR_TYPE_NUM_SIZE_64
:
1097 Dest
->u64
= Source
->u64
;
1107 Get selection for OneOf and OrderedList (Left/Right will be ignored).
1109 @param MenuOption Pointer to the current input menu.
1111 @retval EFI_SUCCESS If Option input is processed successfully
1112 @retval EFI_DEVICE_ERROR If operation fails
1116 GetSelectionInputPopUp (
1117 IN UI_MENU_OPTION
*MenuOption
1123 CHAR16
*TempStringPtr
;
1125 UINTN TopOptionIndex
;
1126 UINTN HighlightOptionIndex
;
1131 UINTN PopUpMenuLines
;
1132 UINTN MenuLinesInView
;
1135 INT32 SavedAttribute
;
1136 BOOLEAN ShowDownArrow
;
1137 BOOLEAN ShowUpArrow
;
1138 UINTN DimensionsWidth
;
1140 BOOLEAN OrderedList
;
1144 EFI_HII_VALUE HiiValue
;
1145 DISPLAY_QUESTION_OPTION
*OneOfOption
;
1146 DISPLAY_QUESTION_OPTION
*CurrentOption
;
1147 FORM_DISPLAY_ENGINE_STATEMENT
*Question
;
1149 EFI_IFR_ORDERED_LIST
*OrderList
;
1151 DimensionsWidth
= gStatementDimensions
.RightColumn
- gStatementDimensions
.LeftColumn
;
1155 CurrentOption
= NULL
;
1156 ShowDownArrow
= FALSE
;
1157 ShowUpArrow
= FALSE
;
1159 StringPtr
= AllocateZeroPool ((gOptionBlockWidth
+ 1) * 2);
1162 ZeroMem (&HiiValue
, sizeof (EFI_HII_VALUE
));
1164 Question
= MenuOption
->ThisTag
;
1165 if (Question
->OpCode
->OpCode
== EFI_IFR_ORDERED_LIST_OP
) {
1166 Link
= GetFirstNode (&Question
->OptionListHead
);
1167 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1168 ValueArray
= Question
->CurrentValue
.Buffer
;
1169 ValueType
= OneOfOption
->OptionOpCode
->Type
;
1171 OrderList
= (EFI_IFR_ORDERED_LIST
*) Question
->OpCode
;
1173 OrderedList
= FALSE
;
1178 // Calculate Option count
1182 AdjustOptionOrder(Question
, &PopUpMenuLines
);
1184 Link
= GetFirstNode (&Question
->OptionListHead
);
1185 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1186 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1188 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1193 // Get the number of one of options present and its size
1196 HighlightOptionIndex
= 0;
1197 Link
= GetFirstNode (&Question
->OptionListHead
);
1198 for (Index
= 0; Index
< PopUpMenuLines
; Index
++) {
1199 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1201 StringPtr
= GetToken (OneOfOption
->OptionOpCode
->Option
, gFormData
->HiiHandle
);
1202 if (StrLen (StringPtr
) > PopUpWidth
) {
1203 PopUpWidth
= StrLen (StringPtr
);
1205 FreePool (StringPtr
);
1206 HiiValue
.Type
= OneOfOption
->OptionOpCode
->Type
;
1207 SetValuesByType (&HiiValue
.Value
, &OneOfOption
->OptionOpCode
->Value
, HiiValue
.Type
);
1208 if (!OrderedList
&& (CompareHiiValue (&Question
->CurrentValue
, &HiiValue
, &Result
, NULL
) == EFI_SUCCESS
) && (Result
== 0)) {
1210 // Find current selected Option for OneOf
1212 HighlightOptionIndex
= Index
;
1215 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1219 // Perform popup menu initialization.
1221 PopUpWidth
= PopUpWidth
+ POPUP_PAD_SPACE_COUNT
;
1223 SavedAttribute
= gST
->ConOut
->Mode
->Attribute
;
1224 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetPopupColor ());
1226 if ((PopUpWidth
+ POPUP_FRAME_WIDTH
) > DimensionsWidth
) {
1227 PopUpWidth
= DimensionsWidth
- POPUP_FRAME_WIDTH
;
1230 Start
= (DimensionsWidth
- PopUpWidth
- POPUP_FRAME_WIDTH
) / 2 + gStatementDimensions
.LeftColumn
;
1231 End
= Start
+ PopUpWidth
+ POPUP_FRAME_WIDTH
;
1232 Top
= gStatementDimensions
.TopRow
;
1233 Bottom
= gStatementDimensions
.BottomRow
- 1;
1235 MenuLinesInView
= Bottom
- Top
- 1;
1236 if (MenuLinesInView
>= PopUpMenuLines
) {
1237 Top
= Top
+ (MenuLinesInView
- PopUpMenuLines
) / 2;
1238 Bottom
= Top
+ PopUpMenuLines
+ 1;
1240 ShowDownArrow
= TRUE
;
1243 if (HighlightOptionIndex
> (MenuLinesInView
- 1)) {
1244 TopOptionIndex
= HighlightOptionIndex
- MenuLinesInView
+ 1;
1251 // Clear that portion of the screen
1253 ClearLines (Start
, End
, Top
, Bottom
, GetPopupColor ());
1256 // Draw "One of" pop-up menu
1258 Character
= BOXDRAW_DOWN_RIGHT
;
1259 PrintCharAt (Start
, Top
, Character
);
1260 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
1261 if ((ShowUpArrow
) && ((Index
+ 1) == (Start
+ End
) / 2)) {
1262 Character
= GEOMETRICSHAPE_UP_TRIANGLE
;
1264 Character
= BOXDRAW_HORIZONTAL
;
1267 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
1270 Character
= BOXDRAW_DOWN_LEFT
;
1271 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
1272 Character
= BOXDRAW_VERTICAL
;
1273 for (Index
= Top
+ 1; Index
< Bottom
; Index
++) {
1274 PrintCharAt (Start
, Index
, Character
);
1275 PrintCharAt (End
- 1, Index
, Character
);
1279 // Move to top Option
1281 Link
= GetFirstNode (&Question
->OptionListHead
);
1282 for (Index
= 0; Index
< TopOptionIndex
; Index
++) {
1283 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1287 // Display the One of options
1290 for (Index
= TopOptionIndex
; (Index
< PopUpMenuLines
) && (Index2
< Bottom
); Index
++) {
1291 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1292 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1294 StringPtr
= GetToken (OneOfOption
->OptionOpCode
->Option
, gFormData
->HiiHandle
);
1295 ASSERT (StringPtr
!= NULL
);
1297 // If the string occupies multiple lines, truncate it to fit in one line,
1298 // and append a "..." for indication.
1300 if (StrLen (StringPtr
) > (PopUpWidth
- 1)) {
1301 TempStringPtr
= AllocateZeroPool (sizeof (CHAR16
) * (PopUpWidth
- 1));
1302 ASSERT ( TempStringPtr
!= NULL
);
1303 CopyMem (TempStringPtr
, StringPtr
, (sizeof (CHAR16
) * (PopUpWidth
- 5)));
1304 FreePool (StringPtr
);
1305 StringPtr
= TempStringPtr
;
1306 StrCat (StringPtr
, L
"...");
1309 if (Index
== HighlightOptionIndex
) {
1311 // Highlight the selected one
1313 CurrentOption
= OneOfOption
;
1315 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetPickListColor ());
1316 PrintStringAt (Start
+ 2, Index2
, StringPtr
);
1317 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetPopupColor ());
1319 gST
->ConOut
->SetAttribute (gST
->ConOut
, GetPopupColor ());
1320 PrintStringAt (Start
+ 2, Index2
, StringPtr
);
1324 FreePool (StringPtr
);
1327 Character
= BOXDRAW_UP_RIGHT
;
1328 PrintCharAt (Start
, Bottom
, Character
);
1329 for (Index
= Start
; Index
+ 2 < End
; Index
++) {
1330 if ((ShowDownArrow
) && ((Index
+ 1) == (Start
+ End
) / 2)) {
1331 Character
= GEOMETRICSHAPE_DOWN_TRIANGLE
;
1333 Character
= BOXDRAW_HORIZONTAL
;
1336 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
1339 Character
= BOXDRAW_UP_LEFT
;
1340 PrintCharAt ((UINTN
)-1, (UINTN
)-1, Character
);
1343 // Get User selection
1345 Key
.UnicodeChar
= CHAR_NULL
;
1346 if ((gDirection
== SCAN_UP
) || (gDirection
== SCAN_DOWN
)) {
1347 Key
.ScanCode
= gDirection
;
1352 WaitForKeyStroke (&Key
);
1355 switch (Key
.UnicodeChar
) {
1358 if ((TopOptionIndex
> 0) && (TopOptionIndex
== HighlightOptionIndex
)) {
1360 // Highlight reaches the top of the popup window, scroll one menu item.
1363 ShowDownArrow
= TRUE
;
1366 if (TopOptionIndex
== 0) {
1367 ShowUpArrow
= FALSE
;
1370 if (HighlightOptionIndex
> 0) {
1371 HighlightOptionIndex
--;
1373 ASSERT (CurrentOption
!= NULL
);
1374 SwapListEntries (CurrentOption
->Link
.BackLink
, &CurrentOption
->Link
);
1381 // If an ordered list op-code, we will allow for a popup of +/- keys
1382 // to create an ordered list of items
1385 if (((TopOptionIndex
+ MenuLinesInView
) < PopUpMenuLines
) &&
1386 (HighlightOptionIndex
== (TopOptionIndex
+ MenuLinesInView
- 1))) {
1388 // Highlight reaches the bottom of the popup window, scroll one menu item.
1394 if ((TopOptionIndex
+ MenuLinesInView
) == PopUpMenuLines
) {
1395 ShowDownArrow
= FALSE
;
1398 if (HighlightOptionIndex
< (PopUpMenuLines
- 1)) {
1399 HighlightOptionIndex
++;
1401 ASSERT (CurrentOption
!= NULL
);
1402 SwapListEntries (&CurrentOption
->Link
, CurrentOption
->Link
.ForwardLink
);
1408 switch (Key
.ScanCode
) {
1411 if (Key
.ScanCode
== SCAN_UP
) {
1412 if ((TopOptionIndex
> 0) && (TopOptionIndex
== HighlightOptionIndex
)) {
1414 // Highlight reaches the top of the popup window, scroll one menu item.
1417 ShowDownArrow
= TRUE
;
1420 if (TopOptionIndex
== 0) {
1421 ShowUpArrow
= FALSE
;
1424 if (HighlightOptionIndex
> 0) {
1425 HighlightOptionIndex
--;
1428 if (((TopOptionIndex
+ MenuLinesInView
) < PopUpMenuLines
) &&
1429 (HighlightOptionIndex
== (TopOptionIndex
+ MenuLinesInView
- 1))) {
1431 // Highlight reaches the bottom of the popup window, scroll one menu item.
1437 if ((TopOptionIndex
+ MenuLinesInView
) == PopUpMenuLines
) {
1438 ShowDownArrow
= FALSE
;
1441 if (HighlightOptionIndex
< (PopUpMenuLines
- 1)) {
1442 HighlightOptionIndex
++;
1448 gST
->ConOut
->SetAttribute (gST
->ConOut
, SavedAttribute
);
1451 // Restore link list order for orderedlist
1454 HiiValue
.Type
= ValueType
;
1455 HiiValue
.Value
.u64
= 0;
1456 for (Index
= 0; Index
< OrderList
->MaxContainers
; Index
++) {
1457 HiiValue
.Value
.u64
= GetArrayData (ValueArray
, ValueType
, Index
);
1458 if (HiiValue
.Value
.u64
== 0) {
1462 OneOfOption
= ValueToOption (Question
, &HiiValue
);
1463 if (OneOfOption
== NULL
) {
1464 return EFI_NOT_FOUND
;
1467 RemoveEntryList (&OneOfOption
->Link
);
1468 InsertTailList (&Question
->OptionListHead
, &OneOfOption
->Link
);
1472 return EFI_DEVICE_ERROR
;
1480 case CHAR_CARRIAGE_RETURN
:
1482 // return the current selection
1485 ReturnValue
= AllocateZeroPool (Question
->CurrentValue
.BufferLen
);
1486 ASSERT (ReturnValue
!= NULL
);
1488 Link
= GetFirstNode (&Question
->OptionListHead
);
1489 while (!IsNull (&Question
->OptionListHead
, Link
)) {
1490 OneOfOption
= DISPLAY_QUESTION_OPTION_FROM_LINK (Link
);
1491 Link
= GetNextNode (&Question
->OptionListHead
, Link
);
1493 SetArrayData (ReturnValue
, ValueType
, Index
, OneOfOption
->OptionOpCode
->Value
.u64
);
1496 if (Index
> OrderList
->MaxContainers
) {
1500 if (CompareMem (ReturnValue
, ValueArray
, Question
->CurrentValue
.BufferLen
) == 0) {
1501 FreePool (ReturnValue
);
1502 return EFI_DEVICE_ERROR
;
1504 gUserInput
->InputValue
.Buffer
= ReturnValue
;
1505 gUserInput
->InputValue
.BufferLen
= Question
->CurrentValue
.BufferLen
;
1508 ASSERT (CurrentOption
!= NULL
);
1509 gUserInput
->InputValue
.Type
= CurrentOption
->OptionOpCode
->Type
;
1510 if (IsValuesEqual (&Question
->CurrentValue
.Value
, &CurrentOption
->OptionOpCode
->Value
, gUserInput
->InputValue
.Type
)) {
1511 return EFI_DEVICE_ERROR
;
1513 SetValuesByType (&gUserInput
->InputValue
.Value
, &CurrentOption
->OptionOpCode
->Value
, gUserInput
->InputValue
.Type
);
1517 gST
->ConOut
->SetAttribute (gST
->ConOut
, SavedAttribute
);