]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
Patch to remove STATIC modifier. This is on longer recommended by EFI Framework codin...
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
1 /** @file
2 Utility functions for User Interface functions.
3
4 Copyright (c) 2004 - 2007, Intel Corporation
5 All rights reserved. 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
9
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.
12
13 **/
14
15 #include "Ui.h"
16 #include "Setup.h"
17
18 LIST_ENTRY Menu;
19 LIST_ENTRY gMenuList;
20 MENU_REFRESH_ENTRY *gMenuRefreshHead;
21
22 //
23 // Search table for UiDisplayMenu()
24 //
25 SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation[] = {
26 {
27 SCAN_UP,
28 UiUp,
29 },
30 {
31 SCAN_DOWN,
32 UiDown,
33 },
34 {
35 SCAN_PAGE_UP,
36 UiPageUp,
37 },
38 {
39 SCAN_PAGE_DOWN,
40 UiPageDown,
41 },
42 {
43 SCAN_ESC,
44 UiReset,
45 },
46 {
47 SCAN_F2,
48 UiPrevious,
49 },
50 {
51 SCAN_LEFT,
52 UiLeft,
53 },
54 {
55 SCAN_RIGHT,
56 UiRight,
57 },
58 {
59 SCAN_F9,
60 UiDefault,
61 },
62 {
63 SCAN_F10,
64 UiSave
65 }
66 };
67
68 SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag[] = {
69 {
70 UiNoOperation,
71 CfUiNoOperation,
72 },
73 {
74 UiDefault,
75 CfUiDefault,
76 },
77 {
78 UiSelect,
79 CfUiSelect,
80 },
81 {
82 UiUp,
83 CfUiUp,
84 },
85 {
86 UiDown,
87 CfUiDown,
88 },
89 {
90 UiLeft,
91 CfUiLeft,
92 },
93 {
94 UiRight,
95 CfUiRight,
96 },
97 {
98 UiReset,
99 CfUiReset,
100 },
101 {
102 UiSave,
103 CfUiSave,
104 },
105 {
106 UiPrevious,
107 CfUiPrevious,
108 },
109 {
110 UiPageUp,
111 CfUiPageUp,
112 },
113 {
114 UiPageDown,
115 CfUiPageDown
116 }
117 };
118
119
120 /**
121 Set Buffer to Value for Size bytes.
122
123 @param Buffer Memory to set.
124 @param Size Number of bytes to set
125 @param Value Value of the set operation.
126
127 @return Value.
128
129 **/
130 VOID
131 SetUnicodeMem (
132 IN VOID *Buffer,
133 IN UINTN Size,
134 IN CHAR16 Value
135 )
136 {
137 CHAR16 *Ptr;
138
139 Ptr = Buffer;
140 while ((Size--) != 0) {
141 *(Ptr++) = Value;
142 }
143 }
144
145
146 /**
147 Initialize Menu option list.
148
149 **/
150 VOID
151 UiInitMenu (
152 VOID
153 )
154 {
155 InitializeListHead (&Menu);
156 }
157
158
159 /**
160 Initialize Menu option list.
161
162 **/
163 VOID
164 UiInitMenuList (
165 VOID
166 )
167 {
168 InitializeListHead (&gMenuList);
169 }
170
171
172 /**
173 Remove a Menu in list, and return FormId/QuestionId for previous Menu.
174
175 @param Selection Menu selection.
176
177 **/
178 VOID
179 UiRemoveMenuListEntry (
180 OUT UI_MENU_SELECTION *Selection
181 )
182 {
183 UI_MENU_LIST *UiMenuList;
184
185 if (!IsListEmpty (&gMenuList)) {
186 UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);
187
188 Selection->FormId = UiMenuList->FormId;
189 Selection->QuestionId = UiMenuList->QuestionId;
190 RemoveEntryList (&UiMenuList->MenuLink);
191 gBS->FreePool (UiMenuList);
192 }
193 }
194
195
196 /**
197 Free Menu option linked list.
198
199 **/
200 VOID
201 UiFreeMenuList (
202 VOID
203 )
204 {
205 UI_MENU_LIST *UiMenuList;
206
207 while (!IsListEmpty (&gMenuList)) {
208 UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);
209 RemoveEntryList (&UiMenuList->MenuLink);
210 gBS->FreePool (UiMenuList);
211 }
212 }
213
214
215 /**
216 Add one menu entry to the linked lst
217
218 @param Selection Menu selection.
219
220 **/
221 VOID
222 UiAddMenuListEntry (
223 IN UI_MENU_SELECTION *Selection
224 )
225 {
226 UI_MENU_LIST *UiMenuList;
227
228 UiMenuList = AllocateZeroPool (sizeof (UI_MENU_LIST));
229 ASSERT (UiMenuList != NULL);
230
231 UiMenuList->Signature = UI_MENU_LIST_SIGNATURE;
232 UiMenuList->FormId = Selection->FormId;
233 UiMenuList->QuestionId = Selection->QuestionId;
234
235 InsertHeadList (&gMenuList, &UiMenuList->MenuLink);
236 }
237
238
239 /**
240 Free Menu option linked list.
241
242 **/
243 VOID
244 UiFreeMenu (
245 VOID
246 )
247 {
248 UI_MENU_OPTION *MenuOption;
249
250 while (!IsListEmpty (&Menu)) {
251 MenuOption = MENU_OPTION_FROM_LINK (Menu.ForwardLink);
252 RemoveEntryList (&MenuOption->Link);
253
254 //
255 // We allocated space for this description when we did a GetToken, free it here
256 //
257 if (MenuOption->Skip != 0) {
258 //
259 // For date/time, MenuOption->Description is shared by three Menu Options
260 // Data format : [01/02/2004] [11:22:33]
261 // Line number : 0 0 1 0 0 1
262 //
263 gBS->FreePool (MenuOption->Description);
264 }
265 gBS->FreePool (MenuOption);
266 }
267 }
268
269
270 /**
271 Free Menu option linked list.
272
273 **/
274 VOID
275 UiFreeRefreshList (
276 VOID
277 )
278 {
279 MENU_REFRESH_ENTRY *OldMenuRefreshEntry;
280
281 while (gMenuRefreshHead != NULL) {
282 OldMenuRefreshEntry = gMenuRefreshHead->Next;
283 gBS->FreePool (gMenuRefreshHead);
284 gMenuRefreshHead = OldMenuRefreshEntry;
285 }
286
287 gMenuRefreshHead = NULL;
288 }
289
290
291
292 /**
293 Refresh screen.
294
295 **/
296 VOID
297 RefreshForm (
298 VOID
299 )
300 {
301 CHAR16 *OptionString;
302 MENU_REFRESH_ENTRY *MenuRefreshEntry;
303 UINTN Index;
304 UINTN Loop;
305 EFI_STATUS Status;
306 UI_MENU_SELECTION *Selection;
307 FORM_BROWSER_STATEMENT *Question;
308
309 OptionString = NULL;
310
311 if (gMenuRefreshHead != NULL) {
312
313 MenuRefreshEntry = gMenuRefreshHead;
314
315 do {
316 gST->ConOut->SetAttribute (gST->ConOut, MenuRefreshEntry->CurrentAttribute);
317
318 Selection = MenuRefreshEntry->Selection;
319 Question = MenuRefreshEntry->MenuOption->ThisTag;
320
321 //
322 // Don't update Question being edited
323 //
324 if (Question != MenuRefreshEntry->Selection->Statement) {
325
326 Status = GetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);
327 if (EFI_ERROR (Status)) {
328 return;
329 }
330
331 ProcessOptions (Selection, MenuRefreshEntry->MenuOption, FALSE, &OptionString);
332
333 if (OptionString != NULL) {
334 //
335 // If leading spaces on OptionString - remove the spaces
336 //
337 for (Index = 0; OptionString[Index] == L' '; Index++)
338 ;
339
340 for (Loop = 0; OptionString[Index] != CHAR_NULL; Index++) {
341 OptionString[Loop] = OptionString[Index];
342 Loop++;
343 }
344
345 OptionString[Loop] = CHAR_NULL;
346
347 PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, OptionString);
348 gBS->FreePool (OptionString);
349 }
350 }
351
352 MenuRefreshEntry = MenuRefreshEntry->Next;
353
354 } while (MenuRefreshEntry != NULL);
355 }
356 }
357
358
359 /**
360 Wait for a given event to fire, or for an optional timeout to expire.
361
362 @param Event The event to wait for
363 @param Timeout An optional timeout value in 100 ns units.
364 @param RefreshInterval Menu refresh interval (in seconds).
365
366 @retval EFI_SUCCESS Event fired before Timeout expired.
367 @retval EFI_TIME_OUT Timout expired before Event fired.
368
369 **/
370 EFI_STATUS
371 UiWaitForSingleEvent (
372 IN EFI_EVENT Event,
373 IN UINT64 Timeout, OPTIONAL
374 IN UINT8 RefreshInterval OPTIONAL
375 )
376 {
377 EFI_STATUS Status;
378 UINTN Index;
379 EFI_EVENT TimerEvent;
380 EFI_EVENT WaitList[2];
381
382 if (Timeout != 0) {
383 //
384 // Create a timer event
385 //
386 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);
387 if (!EFI_ERROR (Status)) {
388 //
389 // Set the timer event
390 //
391 gBS->SetTimer (
392 TimerEvent,
393 TimerRelative,
394 Timeout
395 );
396
397 //
398 // Wait for the original event or the timer
399 //
400 WaitList[0] = Event;
401 WaitList[1] = TimerEvent;
402 Status = gBS->WaitForEvent (2, WaitList, &Index);
403 gBS->CloseEvent (TimerEvent);
404
405 //
406 // If the timer expired, change the return to timed out
407 //
408 if (!EFI_ERROR (Status) && Index == 1) {
409 Status = EFI_TIMEOUT;
410 }
411 }
412 } else {
413 //
414 // Update screen every second
415 //
416 if (RefreshInterval == 0) {
417 Timeout = ONE_SECOND;
418 } else {
419 Timeout = RefreshInterval * ONE_SECOND;
420 }
421
422 do {
423 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);
424
425 //
426 // Set the timer event
427 //
428 gBS->SetTimer (
429 TimerEvent,
430 TimerRelative,
431 Timeout
432 );
433
434 //
435 // Wait for the original event or the timer
436 //
437 WaitList[0] = Event;
438 WaitList[1] = TimerEvent;
439 Status = gBS->WaitForEvent (2, WaitList, &Index);
440
441 //
442 // If the timer expired, update anything that needs a refresh and keep waiting
443 //
444 if (!EFI_ERROR (Status) && Index == 1) {
445 Status = EFI_TIMEOUT;
446 if (RefreshInterval != 0) {
447 RefreshForm ();
448 }
449 }
450
451 gBS->CloseEvent (TimerEvent);
452 } while (Status == EFI_TIMEOUT);
453 }
454
455 return Status;
456 }
457
458
459 /**
460 Add one menu option by specified description and context.
461
462 @param String String description for this option.
463 @param Handle Hii handle for the package list.
464 @param Statement Statement of this Menu Option.
465 @param NumberOfLines Display lines for this Menu Option.
466 @param MenuItemCount The index for this Option in the Menu.
467
468 **/
469 VOID
470 UiAddMenuOption (
471 IN CHAR16 *String,
472 IN EFI_HII_HANDLE Handle,
473 IN FORM_BROWSER_STATEMENT *Statement,
474 IN UINT16 NumberOfLines,
475 IN UINT16 MenuItemCount
476 )
477 {
478 UI_MENU_OPTION *MenuOption;
479 UINTN Index;
480 UINTN Count;
481
482 Count = 1;
483
484 if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {
485 //
486 // Add three MenuOptions for Date/Time
487 // Data format : [01/02/2004] [11:22:33]
488 // Line number : 0 0 1 0 0 1
489 //
490 NumberOfLines = 0;
491 Count = 3;
492
493 if (Statement->Storage == NULL) {
494 //
495 // For RTC type of date/time, set default refresh interval to be 1 second
496 //
497 if (Statement->RefreshInterval == 0) {
498 Statement->RefreshInterval = 1;
499 }
500 }
501 }
502
503 for (Index = 0; Index < Count; Index++) {
504 MenuOption = AllocateZeroPool (sizeof (UI_MENU_OPTION));
505 ASSERT (MenuOption);
506
507 MenuOption->Signature = UI_MENU_OPTION_SIGNATURE;
508 MenuOption->Description = String;
509 MenuOption->Handle = Handle;
510 MenuOption->ThisTag = Statement;
511 MenuOption->EntryNumber = MenuItemCount;
512
513 if (Index == 2) {
514 //
515 // Override LineNumber for the MenuOption in Date/Time sequence
516 //
517 MenuOption->Skip = 1;
518 } else {
519 MenuOption->Skip = NumberOfLines;
520 }
521 MenuOption->Sequence = Index;
522
523 if (Statement->GrayOutExpression != NULL) {
524 MenuOption->GrayOut = Statement->GrayOutExpression->Result.Value.b;
525 }
526
527 if ((Statement->ValueExpression != NULL) ||
528 ((Statement->QuestionFlags & EFI_IFR_FLAG_READ_ONLY) != 0)) {
529 MenuOption->ReadOnly = TRUE;
530 }
531
532 InsertTailList (&Menu, &MenuOption->Link);
533 }
534 }
535
536
537 /**
538 Routine used to abstract a generic dialog interface and return the selected key or string
539
540 @param NumberOfLines The number of lines for the dialog box
541 @param HotKey Defines whether a single character is parsed
542 (TRUE) and returned in KeyValue or a string is
543 returned in StringBuffer. Two special characters
544 are considered when entering a string, a SCAN_ESC
545 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates
546 string input and returns
547 @param MaximumStringSize The maximum size in bytes of a typed in string
548 (each character is a CHAR16) and the minimum
549 string returned is two bytes
550 @param StringBuffer The passed in pointer to the buffer which will
551 hold the typed in string if HotKey is FALSE
552 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..
553 @param ... A series of (quantity == NumberOfLines) text
554 strings which will be used to construct the dialog
555 box
556
557 @retval EFI_SUCCESS Displayed dialog and received user interaction
558 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.
559 (StringBuffer == NULL) && (HotKey == FALSE))
560 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine
561
562 **/
563 EFI_STATUS
564 CreateDialog (
565 IN UINTN NumberOfLines,
566 IN BOOLEAN HotKey,
567 IN UINTN MaximumStringSize,
568 OUT CHAR16 *StringBuffer,
569 OUT EFI_INPUT_KEY *KeyValue,
570 ...
571 )
572 {
573 VA_LIST Marker;
574 VA_LIST MarkerBackup;
575 UINTN Count;
576 EFI_INPUT_KEY Key;
577 UINTN LargestString;
578 CHAR16 *TempString;
579 CHAR16 *BufferedString;
580 CHAR16 *StackString;
581 CHAR16 KeyPad[2];
582 UINTN Start;
583 UINTN Top;
584 UINTN Index;
585 EFI_STATUS Status;
586 BOOLEAN SelectionComplete;
587 UINTN InputOffset;
588 UINTN CurrentAttribute;
589 UINTN DimensionsWidth;
590 UINTN DimensionsHeight;
591
592 DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;
593 DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;
594
595 SelectionComplete = FALSE;
596 InputOffset = 0;
597 TempString = AllocateZeroPool (MaximumStringSize * 2);
598 BufferedString = AllocateZeroPool (MaximumStringSize * 2);
599 CurrentAttribute = gST->ConOut->Mode->Attribute;
600
601 ASSERT (TempString);
602 ASSERT (BufferedString);
603
604 VA_START (Marker, KeyValue);
605 MarkerBackup = Marker;
606
607 //
608 // Zero the outgoing buffer
609 //
610 ZeroMem (StringBuffer, MaximumStringSize);
611
612 if (HotKey) {
613 if (KeyValue == NULL) {
614 return EFI_INVALID_PARAMETER;
615 }
616 } else {
617 if (StringBuffer == NULL) {
618 return EFI_INVALID_PARAMETER;
619 }
620 }
621 //
622 // Disable cursor
623 //
624 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
625
626 LargestString = 0;
627
628 //
629 // Determine the largest string in the dialog box
630 // Notice we are starting with 1 since String is the first string
631 //
632 for (Count = 0; Count < NumberOfLines; Count++) {
633 StackString = VA_ARG (Marker, CHAR16 *);
634
635 if (StackString[0] == L' ') {
636 InputOffset = Count + 1;
637 }
638
639 if ((GetStringWidth (StackString) / 2) > LargestString) {
640 //
641 // Size of the string visually and subtract the width by one for the null-terminator
642 //
643 LargestString = (GetStringWidth (StackString) / 2);
644 }
645 }
646
647 Start = (DimensionsWidth - LargestString - 2) / 2 + gScreenDimensions.LeftColumn + 1;
648 Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1;
649
650 Count = 0;
651
652 //
653 // Display the Popup
654 //
655 CreateSharedPopUp (LargestString, NumberOfLines, MarkerBackup);
656
657 //
658 // Take the first key typed and report it back?
659 //
660 if (HotKey) {
661 Status = WaitForKeyStroke (&Key);
662 ASSERT_EFI_ERROR (Status);
663 CopyMem (KeyValue, &Key, sizeof (EFI_INPUT_KEY));
664
665 } else {
666 do {
667 Status = WaitForKeyStroke (&Key);
668
669 switch (Key.UnicodeChar) {
670 case CHAR_NULL:
671 switch (Key.ScanCode) {
672 case SCAN_ESC:
673 gBS->FreePool (TempString);
674 gBS->FreePool (BufferedString);
675 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
676 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
677 return EFI_DEVICE_ERROR;
678
679 default:
680 break;
681 }
682
683 break;
684
685 case CHAR_CARRIAGE_RETURN:
686 SelectionComplete = TRUE;
687 gBS->FreePool (TempString);
688 gBS->FreePool (BufferedString);
689 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
690 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
691 return EFI_SUCCESS;
692 break;
693
694 case CHAR_BACKSPACE:
695 if (StringBuffer[0] != CHAR_NULL) {
696 for (Index = 0; StringBuffer[Index] != CHAR_NULL; Index++) {
697 TempString[Index] = StringBuffer[Index];
698 }
699 //
700 // Effectively truncate string by 1 character
701 //
702 TempString[Index - 1] = CHAR_NULL;
703 StrCpy (StringBuffer, TempString);
704 }
705
706 default:
707 //
708 // If it is the beginning of the string, don't worry about checking maximum limits
709 //
710 if ((StringBuffer[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
711 StrnCpy (StringBuffer, &Key.UnicodeChar, 1);
712 StrnCpy (TempString, &Key.UnicodeChar, 1);
713 } else if ((GetStringWidth (StringBuffer) < MaximumStringSize) && (Key.UnicodeChar != CHAR_BACKSPACE)) {
714 KeyPad[0] = Key.UnicodeChar;
715 KeyPad[1] = CHAR_NULL;
716 StrCat (StringBuffer, KeyPad);
717 StrCat (TempString, KeyPad);
718 }
719 //
720 // If the width of the input string is now larger than the screen, we nee to
721 // adjust the index to start printing portions of the string
722 //
723 SetUnicodeMem (BufferedString, LargestString, L' ');
724
725 PrintStringAt (Start + 1, Top + InputOffset, BufferedString);
726
727 if ((GetStringWidth (StringBuffer) / 2) > (DimensionsWidth - 2)) {
728 Index = (GetStringWidth (StringBuffer) / 2) - DimensionsWidth + 2;
729 } else {
730 Index = 0;
731 }
732
733 for (Count = 0; Index + 1 < GetStringWidth (StringBuffer) / 2; Index++, Count++) {
734 BufferedString[Count] = StringBuffer[Index];
735 }
736
737 PrintStringAt (Start + 1, Top + InputOffset, BufferedString);
738 break;
739 }
740 } while (!SelectionComplete);
741 }
742
743 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
744 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
745 return EFI_SUCCESS;
746 }
747
748 /**
749 Draw a pop up windows based on the dimension, number of lines and
750 strings specified.
751
752 @param RequestedWidth The width of the pop-up.
753 @param NumberOfLines The number of lines.
754 @param Marker The variable argument list for the list of string to be printed.
755
756 **/
757 VOID
758 CreateSharedPopUp (
759 IN UINTN RequestedWidth,
760 IN UINTN NumberOfLines,
761 IN VA_LIST Marker
762 )
763 {
764 UINTN Index;
765 UINTN Count;
766 CHAR16 Character;
767 UINTN Start;
768 UINTN End;
769 UINTN Top;
770 UINTN Bottom;
771 CHAR16 *String;
772 UINTN DimensionsWidth;
773 UINTN DimensionsHeight;
774
775 DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;
776 DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;
777
778 gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);
779
780 if ((RequestedWidth + 2) > DimensionsWidth) {
781 RequestedWidth = DimensionsWidth - 2;
782 }
783
784 //
785 // Subtract the PopUp width from total Columns, allow for one space extra on
786 // each end plus a border.
787 //
788 Start = (DimensionsWidth - RequestedWidth - 2) / 2 + gScreenDimensions.LeftColumn + 1;
789 End = Start + RequestedWidth + 1;
790
791 Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1;
792 Bottom = Top + NumberOfLines + 2;
793
794 Character = BOXDRAW_DOWN_RIGHT;
795 PrintCharAt (Start, Top, Character);
796 Character = BOXDRAW_HORIZONTAL;
797 for (Index = Start; Index + 2 < End; Index++) {
798 PrintChar (Character);
799 }
800
801 Character = BOXDRAW_DOWN_LEFT;
802 PrintChar (Character);
803 Character = BOXDRAW_VERTICAL;
804
805 Count = 0;
806 for (Index = Top; Index + 2 < Bottom; Index++, Count++) {
807 String = VA_ARG (Marker, CHAR16*);
808
809 //
810 // This will clear the background of the line - we never know who might have been
811 // here before us. This differs from the next clear in that it used the non-reverse
812 // video for normal printing.
813 //
814 if (GetStringWidth (String) / 2 > 1) {
815 ClearLines (Start, End, Index + 1, Index + 1, POPUP_TEXT | POPUP_BACKGROUND);
816 }
817
818 //
819 // Passing in a space results in the assumption that this is where typing will occur
820 //
821 if (String[0] == L' ') {
822 ClearLines (Start + 1, End - 1, Index + 1, Index + 1, POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND);
823 }
824
825 //
826 // Passing in a NULL results in a blank space
827 //
828 if (String[0] == CHAR_NULL) {
829 ClearLines (Start, End, Index + 1, Index + 1, POPUP_TEXT | POPUP_BACKGROUND);
830 }
831
832 PrintStringAt (
833 ((DimensionsWidth - GetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,
834 Index + 1,
835 String
836 );
837 gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);
838 PrintCharAt (Start, Index + 1, Character);
839 PrintCharAt (End - 1, Index + 1, Character);
840 }
841
842 Character = BOXDRAW_UP_RIGHT;
843 PrintCharAt (Start, Bottom - 1, Character);
844 Character = BOXDRAW_HORIZONTAL;
845 for (Index = Start; Index + 2 < End; Index++) {
846 PrintChar (Character);
847 }
848
849 Character = BOXDRAW_UP_LEFT;
850 PrintChar (Character);
851 }
852
853 /**
854 Draw a pop up windows based on the dimension, number of lines and
855 strings specified.
856
857 @param RequestedWidth The width of the pop-up.
858 @param NumberOfLines The number of lines.
859 @param ... A series of text strings that displayed in the pop-up.
860
861 **/
862 VOID
863 CreatePopUp (
864 IN UINTN RequestedWidth,
865 IN UINTN NumberOfLines,
866 ...
867 )
868 {
869 VA_LIST Marker;
870
871 VA_START (Marker, NumberOfLines);
872
873 CreateSharedPopUp (RequestedWidth, NumberOfLines, Marker);
874
875 VA_END (Marker);
876 }
877
878
879 /**
880 Update status bar on the bottom of menu.
881
882 @param MessageType The type of message to be shown.
883 @param Flags The flags in Question header.
884 @param State Set or clear.
885
886 **/
887 VOID
888 UpdateStatusBar (
889 IN UINTN MessageType,
890 IN UINT8 Flags,
891 IN BOOLEAN State
892 )
893 {
894 UINTN Index;
895 STATIC BOOLEAN InputError;
896 CHAR16 *NvUpdateMessage;
897 CHAR16 *InputErrorMessage;
898
899 NvUpdateMessage = GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), gHiiHandle);
900 InputErrorMessage = GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), gHiiHandle);
901
902 switch (MessageType) {
903 case INPUT_ERROR:
904 if (State) {
905 gST->ConOut->SetAttribute (gST->ConOut, ERROR_TEXT);
906 PrintStringAt (
907 gScreenDimensions.LeftColumn + gPromptBlockWidth,
908 gScreenDimensions.BottomRow - 1,
909 InputErrorMessage
910 );
911 InputError = TRUE;
912 } else {
913 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT);
914 for (Index = 0; Index < (GetStringWidth (InputErrorMessage) - 2) / 2; Index++) {
915 PrintAt (gScreenDimensions.LeftColumn + gPromptBlockWidth + Index, gScreenDimensions.BottomRow - 1, L" ");
916 }
917
918 InputError = FALSE;
919 }
920 break;
921
922 case NV_UPDATE_REQUIRED:
923 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {
924 if (State) {
925 gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT);
926 PrintStringAt (
927 gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth,
928 gScreenDimensions.BottomRow - 1,
929 NvUpdateMessage
930 );
931 gResetRequired = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED));
932
933 gNvUpdateRequired = TRUE;
934 } else {
935 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT);
936 for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) {
937 PrintAt (
938 (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index),
939 gScreenDimensions.BottomRow - 1,
940 L" "
941 );
942 }
943
944 gNvUpdateRequired = FALSE;
945 }
946 }
947 break;
948
949 case REFRESH_STATUS_BAR:
950 if (InputError) {
951 UpdateStatusBar (INPUT_ERROR, Flags, TRUE);
952 }
953
954 if (gNvUpdateRequired) {
955 UpdateStatusBar (NV_UPDATE_REQUIRED, Flags, TRUE);
956 }
957 break;
958
959 default:
960 break;
961 }
962
963 gBS->FreePool (InputErrorMessage);
964 gBS->FreePool (NvUpdateMessage);
965 return ;
966 }
967
968
969 /**
970 Get the supported width for a particular op-code
971
972 @param Statement The FORM_BROWSER_STATEMENT structure passed in.
973 @param Handle The handle in the HII database being used
974
975 @return Returns the number of CHAR16 characters that is support.
976
977 **/
978 UINT16
979 GetWidth (
980 IN FORM_BROWSER_STATEMENT *Statement,
981 IN EFI_HII_HANDLE Handle
982 )
983 {
984 CHAR16 *String;
985 UINTN Size;
986 UINT16 Width;
987
988 Size = 0;
989
990 //
991 // See if the second text parameter is really NULL
992 //
993 if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) {
994 String = GetToken (Statement->TextTwo, Handle);
995 Size = StrLen (String);
996 gBS->FreePool (String);
997 }
998
999 if ((Statement->Operand == EFI_IFR_SUBTITLE_OP) ||
1000 (Statement->Operand == EFI_IFR_REF_OP) ||
1001 (Statement->Operand == EFI_IFR_PASSWORD_OP) ||
1002 (Statement->Operand == EFI_IFR_ACTION_OP) ||
1003 (Statement->Operand == EFI_IFR_RESET_BUTTON_OP) ||
1004 //
1005 // Allow a wide display if text op-code and no secondary text op-code
1006 //
1007 ((Statement->Operand == EFI_IFR_TEXT_OP) && (Size == 0))
1008 ) {
1009 Width = (UINT16) (gPromptBlockWidth + gOptionBlockWidth);
1010 } else {
1011 Width = (UINT16) gPromptBlockWidth;
1012 }
1013
1014 if (Statement->InSubtitle) {
1015 Width -= SUBTITLE_INDENT;
1016 }
1017
1018 return Width;
1019 }
1020
1021
1022 BOOLEAN GetLineByWidthFinished = FALSE;
1023
1024 /**
1025 Will copy LineWidth amount of a string in the OutputString buffer and return the
1026 number of CHAR16 characters that were copied into the OutputString buffer.
1027
1028 @param InputString String description for this option.
1029 @param LineWidth Width of the desired string to extract in CHAR16
1030 characters
1031 @param Index Where in InputString to start the copy process
1032 @param OutputString Buffer to copy the string into
1033
1034 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.
1035
1036 **/
1037 UINT16
1038 GetLineByWidth (
1039 IN CHAR16 *InputString,
1040 IN UINT16 LineWidth,
1041 IN OUT UINTN *Index,
1042 OUT CHAR16 **OutputString
1043 )
1044 {
1045 UINT16 Count;
1046 UINT16 Count2;
1047
1048 if (GetLineByWidthFinished) {
1049 GetLineByWidthFinished = FALSE;
1050 return (UINT16) 0;
1051 }
1052
1053 Count = LineWidth;
1054 Count2 = 0;
1055
1056 *OutputString = AllocateZeroPool (((UINTN) (LineWidth + 1) * 2));
1057
1058 //
1059 // Ensure we have got a valid buffer
1060 //
1061 if (*OutputString != NULL) {
1062
1063 //
1064 //NARROW_CHAR can not be printed in screen, so if a line only contain the two CHARs: 'NARROW_CHAR + CHAR_CARRIAGE_RETURN' , it is a empty line in Screen.
1065 //To avoid displaying this empty line in screen, just skip the two CHARs here.
1066 //
1067 if ((InputString[*Index] == NARROW_CHAR) && (InputString[*Index + 1] == CHAR_CARRIAGE_RETURN)) {
1068 *Index = *Index + 2;
1069 }
1070
1071 //
1072 // Fast-forward the string and see if there is a carriage-return in the string
1073 //
1074 for (; (InputString[*Index + Count2] != CHAR_CARRIAGE_RETURN) && (Count2 != LineWidth); Count2++)
1075 ;
1076
1077 //
1078 // Copy the desired LineWidth of data to the output buffer.
1079 // Also make sure that we don't copy more than the string.
1080 // Also make sure that if there are linefeeds, we account for them.
1081 //
1082 if ((StrSize (&InputString[*Index]) <= ((UINTN) (LineWidth + 1) * 2)) &&
1083 (StrSize (&InputString[*Index]) <= ((UINTN) (Count2 + 1) * 2))
1084 ) {
1085 //
1086 // Convert to CHAR16 value and show that we are done with this operation
1087 //
1088 LineWidth = (UINT16) ((StrSize (&InputString[*Index]) - 2) / 2);
1089 if (LineWidth != 0) {
1090 GetLineByWidthFinished = TRUE;
1091 }
1092 } else {
1093 if (Count2 == LineWidth) {
1094 //
1095 // Rewind the string from the maximum size until we see a space to break the line
1096 //
1097 for (; (InputString[*Index + LineWidth] != CHAR_SPACE) && (LineWidth != 0); LineWidth--)
1098 ;
1099 if (LineWidth == 0) {
1100 LineWidth = Count;
1101 }
1102 } else {
1103 LineWidth = Count2;
1104 }
1105 }
1106
1107 CopyMem (*OutputString, &InputString[*Index], LineWidth * 2);
1108
1109 //
1110 // If currently pointing to a space, increment the index to the first non-space character
1111 //
1112 for (;
1113 (InputString[*Index + LineWidth] == CHAR_SPACE) || (InputString[*Index + LineWidth] == CHAR_CARRIAGE_RETURN);
1114 (*Index)++
1115 )
1116 ;
1117 *Index = (UINT16) (*Index + LineWidth);
1118 return LineWidth;
1119 } else {
1120 return (UINT16) 0;
1121 }
1122 }
1123
1124
1125 /**
1126 Update display lines for a Menu Option.
1127
1128 @param Selection The user's selection.
1129 @param MenuOption The MenuOption to be checked.
1130 @param OptionalString The option string.
1131 @param SkipValue The number of lins to skip.
1132
1133 **/
1134 VOID
1135 UpdateOptionSkipLines (
1136 IN UI_MENU_SELECTION *Selection,
1137 IN UI_MENU_OPTION *MenuOption,
1138 OUT CHAR16 **OptionalString,
1139 IN UINTN SkipValue
1140 )
1141 {
1142 UINTN Index;
1143 UINT16 Width;
1144 UINTN Row;
1145 UINTN OriginalRow;
1146 CHAR16 *OutputString;
1147 CHAR16 *OptionString;
1148
1149 Row = 0;
1150 OptionString = *OptionalString;
1151 OutputString = NULL;
1152
1153 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);
1154
1155 if (OptionString != NULL) {
1156 Width = (UINT16) gOptionBlockWidth;
1157
1158 OriginalRow = Row;
1159
1160 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {
1161 //
1162 // If there is more string to process print on the next row and increment the Skip value
1163 //
1164 if (StrLen (&OptionString[Index])) {
1165 if (SkipValue == 0) {
1166 Row++;
1167 //
1168 // Since the Number of lines for this menu entry may or may not be reflected accurately
1169 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1170 // some testing to ensure we are keeping this in-sync.
1171 //
1172 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1173 //
1174 if ((Row - OriginalRow) >= MenuOption->Skip) {
1175 MenuOption->Skip++;
1176 }
1177 }
1178 }
1179
1180 gBS->FreePool (OutputString);
1181 if (SkipValue != 0) {
1182 SkipValue--;
1183 }
1184 }
1185
1186 Row = OriginalRow;
1187 }
1188
1189 *OptionalString = OptionString;
1190 }
1191
1192
1193 /**
1194 Check whether this Menu Option could be highlighted.
1195
1196 This is an internal function.
1197
1198 @param MenuOption The MenuOption to be checked.
1199
1200 @retval TRUE This Menu Option is selectable.
1201 @retval FALSE This Menu Option could not be selected.
1202
1203 **/
1204 BOOLEAN
1205 IsSelectable (
1206 UI_MENU_OPTION *MenuOption
1207 )
1208 {
1209 if ((MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) ||
1210 MenuOption->GrayOut || MenuOption->ReadOnly) {
1211 return FALSE;
1212 } else {
1213 return TRUE;
1214 }
1215 }
1216
1217
1218 /**
1219 Determine if the menu is the last menu that can be selected.
1220
1221 This is an internal function.
1222
1223 @param Direction The scroll direction. False is down. True is up.
1224 @param CurrentPos The current focus.
1225
1226 @return FALSE -- the menu isn't the last menu that can be selected.
1227 @return TRUE -- the menu is the last menu that can be selected.
1228
1229 **/
1230 BOOLEAN
1231 ValueIsScroll (
1232 IN BOOLEAN Direction,
1233 IN LIST_ENTRY *CurrentPos
1234 )
1235 {
1236 LIST_ENTRY *Temp;
1237 UI_MENU_OPTION *MenuOption;
1238
1239 Temp = Direction ? CurrentPos->BackLink : CurrentPos->ForwardLink;
1240
1241 if (Temp == &Menu) {
1242 return TRUE;
1243 }
1244
1245 for (; Temp != &Menu; Temp = Direction ? Temp->BackLink : Temp->ForwardLink) {
1246 MenuOption = MENU_OPTION_FROM_LINK (Temp);
1247 if (IsSelectable (MenuOption)) {
1248 return FALSE;
1249 }
1250 }
1251
1252 return TRUE;
1253 }
1254
1255
1256 /**
1257 Move to next selectable statement.
1258
1259 This is an internal function.
1260
1261 @param GoUp The navigation direction. TRUE: up, FALSE: down.
1262 @param CurrentPosition Current position.
1263
1264 @return The row distance from current MenuOption to next selectable MenuOption.
1265
1266 **/
1267 INTN
1268 MoveToNextStatement (
1269 IN BOOLEAN GoUp,
1270 IN OUT LIST_ENTRY **CurrentPosition
1271 )
1272 {
1273 INTN Distance;
1274 LIST_ENTRY *Pos;
1275 BOOLEAN HitEnd;
1276 UI_MENU_OPTION *NextMenuOption;
1277
1278 Distance = 0;
1279 Pos = *CurrentPosition;
1280 HitEnd = FALSE;
1281
1282 while (TRUE) {
1283 NextMenuOption = MENU_OPTION_FROM_LINK (Pos);
1284 if (IsSelectable (NextMenuOption)) {
1285 break;
1286 }
1287 if ((GoUp ? Pos->BackLink : Pos->ForwardLink) == &Menu) {
1288 HitEnd = TRUE;
1289 break;
1290 }
1291 Distance += NextMenuOption->Skip;
1292 Pos = (GoUp ? Pos->BackLink : Pos->ForwardLink);
1293 }
1294
1295 if (HitEnd) {
1296 //
1297 // If we hit end there is still no statement can be focused,
1298 // we go backwards to find the statement can be focused.
1299 //
1300 Distance = 0;
1301 Pos = *CurrentPosition;
1302
1303 while (TRUE) {
1304 NextMenuOption = MENU_OPTION_FROM_LINK (Pos);
1305 if (IsSelectable (NextMenuOption)) {
1306 break;
1307 }
1308 if ((!GoUp ? Pos->BackLink : Pos->ForwardLink) == &Menu) {
1309 ASSERT (FALSE);
1310 break;
1311 }
1312 Distance -= NextMenuOption->Skip;
1313 Pos = (!GoUp ? Pos->BackLink : Pos->ForwardLink);
1314 }
1315 }
1316
1317 *CurrentPosition = &NextMenuOption->Link;
1318 return Distance;
1319 }
1320
1321
1322 /**
1323 Adjust Data and Time position accordingly.
1324 Data format : [01/02/2004] [11:22:33]
1325 Line number : 0 0 1 0 0 1
1326
1327 This is an internal function.
1328
1329 @param DirectionUp the up or down direction. False is down. True is
1330 up.
1331 @param CurrentPosition Current position. On return: Point to the last
1332 Option (Year or Second) if up; Point to the first
1333 Option (Month or Hour) if down.
1334
1335 @return Return line number to pad. It is possible that we stand on a zero-advance
1336 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.
1337
1338 **/
1339 UINTN
1340 AdjustDateAndTimePosition (
1341 IN BOOLEAN DirectionUp,
1342 IN OUT LIST_ENTRY **CurrentPosition
1343 )
1344 {
1345 UINTN Count;
1346 LIST_ENTRY *NewPosition;
1347 UI_MENU_OPTION *MenuOption;
1348 UINTN PadLineNumber;
1349
1350 PadLineNumber = 0;
1351 NewPosition = *CurrentPosition;
1352 MenuOption = MENU_OPTION_FROM_LINK (NewPosition);
1353
1354 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||
1355 (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {
1356 //
1357 // Calculate the distance from current position to the last Date/Time MenuOption
1358 //
1359 Count = 0;
1360 while (MenuOption->Skip == 0) {
1361 Count++;
1362 NewPosition = NewPosition->ForwardLink;
1363 MenuOption = MENU_OPTION_FROM_LINK (NewPosition);
1364 PadLineNumber = 1;
1365 }
1366
1367 NewPosition = *CurrentPosition;
1368 if (DirectionUp) {
1369 //
1370 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended
1371 // to be one that back to the previous set of MenuOptions, we need to advance to the first
1372 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate
1373 // checking can be done.
1374 //
1375 while (Count++ < 2) {
1376 NewPosition = NewPosition->BackLink;
1377 }
1378 } else {
1379 //
1380 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended
1381 // to be one that progresses to the next set of MenuOptions, we need to advance to the last
1382 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate
1383 // checking can be done.
1384 //
1385 while (Count-- > 0) {
1386 NewPosition = NewPosition->ForwardLink;
1387 }
1388 }
1389
1390 *CurrentPosition = NewPosition;
1391 }
1392
1393 return PadLineNumber;
1394 }
1395
1396
1397 /**
1398 Display menu and wait for user to select one menu option, then return it.
1399 If AutoBoot is enabled, then if user doesn't select any option,
1400 after period of time, it will automatically return the first menu option.
1401
1402 @param Selection Menu selection.
1403
1404 @retval EFI_SUCESSS This function always return successfully for now.
1405
1406 **/
1407 EFI_STATUS
1408 UiDisplayMenu (
1409 IN OUT UI_MENU_SELECTION *Selection
1410 )
1411 {
1412 INTN SkipValue;
1413 INTN Difference;
1414 INTN OldSkipValue;
1415 UINTN DistanceValue;
1416 UINTN Row;
1417 UINTN Col;
1418 UINTN Temp;
1419 UINTN Temp2;
1420 UINTN TopRow;
1421 UINTN BottomRow;
1422 UINTN OriginalRow;
1423 UINTN Index;
1424 UINT32 Count;
1425 UINT16 Width;
1426 CHAR16 *StringPtr;
1427 CHAR16 *OptionString;
1428 CHAR16 *OutputString;
1429 CHAR16 *FormattedString;
1430 CHAR16 YesResponse;
1431 CHAR16 NoResponse;
1432 BOOLEAN NewLine;
1433 BOOLEAN Repaint;
1434 BOOLEAN SavedValue;
1435 EFI_STATUS Status;
1436 EFI_INPUT_KEY Key;
1437 LIST_ENTRY *Link;
1438 LIST_ENTRY *NewPos;
1439 LIST_ENTRY *TopOfScreen;
1440 LIST_ENTRY *SavedListEntry;
1441 UI_MENU_OPTION *MenuOption;
1442 UI_MENU_OPTION *NextMenuOption;
1443 UI_MENU_OPTION *SavedMenuOption;
1444 UI_MENU_OPTION *PreviousMenuOption;
1445 UI_CONTROL_FLAG ControlFlag;
1446 EFI_SCREEN_DESCRIPTOR LocalScreen;
1447 MENU_REFRESH_ENTRY *MenuRefreshEntry;
1448 UI_SCREEN_OPERATION ScreenOperation;
1449 UINT8 MinRefreshInterval;
1450 UINTN BufferSize;
1451 UINT16 DefaultId;
1452 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
1453 FORM_BROWSER_STATEMENT *Statement;
1454
1455 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
1456
1457 Status = EFI_SUCCESS;
1458 FormattedString = NULL;
1459 OptionString = NULL;
1460 ScreenOperation = UiNoOperation;
1461 NewLine = TRUE;
1462 MinRefreshInterval = 0;
1463 DefaultId = 0;
1464
1465 OutputString = NULL;
1466 gUpArrow = FALSE;
1467 gDownArrow = FALSE;
1468 SkipValue = 0;
1469 OldSkipValue = 0;
1470 MenuRefreshEntry = gMenuRefreshHead;
1471
1472 NextMenuOption = NULL;
1473 PreviousMenuOption = NULL;
1474 SavedMenuOption = NULL;
1475
1476 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
1477
1478 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {
1479 TopRow = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;
1480 Row = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;
1481 } else {
1482 TopRow = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;
1483 Row = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;
1484 }
1485
1486 Col = LocalScreen.LeftColumn;
1487 BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - SCROLL_ARROW_HEIGHT - 1;
1488
1489 Selection->TopRow = TopRow;
1490 Selection->BottomRow = BottomRow;
1491 Selection->PromptCol = Col;
1492 Selection->OptionCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn;
1493 Selection->Statement = NULL;
1494
1495 TopOfScreen = Menu.ForwardLink;
1496 Repaint = TRUE;
1497 MenuOption = NULL;
1498
1499 //
1500 // Get user's selection
1501 //
1502 NewPos = Menu.ForwardLink;
1503
1504 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
1505 UpdateStatusBar (REFRESH_STATUS_BAR, (UINT8) 0, TRUE);
1506
1507 ControlFlag = CfInitialization;
1508 Selection->Action = UI_ACTION_NONE;
1509 while (TRUE) {
1510 switch (ControlFlag) {
1511 case CfInitialization:
1512 if (IsListEmpty (&Menu)) {
1513 ControlFlag = CfReadKey;
1514 } else {
1515 ControlFlag = CfCheckSelection;
1516 }
1517 break;
1518
1519 case CfCheckSelection:
1520 if (Selection->Action != UI_ACTION_NONE) {
1521 ControlFlag = CfExit;
1522 } else {
1523 ControlFlag = CfRepaint;
1524 }
1525 break;
1526
1527 case CfRepaint:
1528 ControlFlag = CfRefreshHighLight;
1529
1530 if (Repaint) {
1531 //
1532 // Display menu
1533 //
1534 gDownArrow = FALSE;
1535 gUpArrow = FALSE;
1536 Row = TopRow;
1537
1538 Temp = SkipValue;
1539 Temp2 = SkipValue;
1540
1541 ClearLines (
1542 LocalScreen.LeftColumn,
1543 LocalScreen.RightColumn,
1544 TopRow - SCROLL_ARROW_HEIGHT,
1545 BottomRow + SCROLL_ARROW_HEIGHT,
1546 FIELD_TEXT | FIELD_BACKGROUND
1547 );
1548
1549 UiFreeRefreshList ();
1550 MinRefreshInterval = 0;
1551
1552 for (Link = TopOfScreen; Link != &Menu; Link = Link->ForwardLink) {
1553 MenuOption = MENU_OPTION_FROM_LINK (Link);
1554 MenuOption->Row = Row;
1555 MenuOption->Col = Col;
1556 MenuOption->OptCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn;
1557
1558 Statement = MenuOption->ThisTag;
1559 if (Statement->InSubtitle) {
1560 MenuOption->Col += SUBTITLE_INDENT;
1561 }
1562
1563 if (MenuOption->GrayOut) {
1564 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND);
1565 } else {
1566 if (Statement->Operand == EFI_IFR_SUBTITLE_OP) {
1567 gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND);
1568 }
1569 }
1570
1571 Width = GetWidth (Statement, MenuOption->Handle);
1572 OriginalRow = Row;
1573
1574 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {
1575 if ((Temp == 0) && (Row <= BottomRow)) {
1576 PrintStringAt (MenuOption->Col, Row, OutputString);
1577 }
1578 //
1579 // If there is more string to process print on the next row and increment the Skip value
1580 //
1581 if (StrLen (&MenuOption->Description[Index])) {
1582 if (Temp == 0) {
1583 Row++;
1584 }
1585 }
1586
1587 gBS->FreePool (OutputString);
1588 if (Temp != 0) {
1589 Temp--;
1590 }
1591 }
1592
1593 Temp = 0;
1594 Row = OriginalRow;
1595
1596 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
1597 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);
1598
1599 if (OptionString != NULL) {
1600 if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {
1601 //
1602 // If leading spaces on OptionString - remove the spaces
1603 //
1604 for (Index = 0; OptionString[Index] == L' '; Index++) {
1605 MenuOption->OptCol++;
1606 }
1607
1608 for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {
1609 OptionString[Count] = OptionString[Index];
1610 Count++;
1611 }
1612
1613 OptionString[Count] = CHAR_NULL;
1614 }
1615
1616 //
1617 // If Question request refresh, register the op-code
1618 //
1619 if (Statement->RefreshInterval != 0) {
1620 //
1621 // Menu will be refreshed at minimal interval of all Questions
1622 // which have refresh request
1623 //
1624 if (MinRefreshInterval == 0 || Statement->RefreshInterval < MinRefreshInterval) {
1625 MinRefreshInterval = Statement->RefreshInterval;
1626 }
1627
1628 if (gMenuRefreshHead == NULL) {
1629 MenuRefreshEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));
1630 ASSERT (MenuRefreshEntry != NULL);
1631 MenuRefreshEntry->MenuOption = MenuOption;
1632 MenuRefreshEntry->Selection = Selection;
1633 MenuRefreshEntry->CurrentColumn = MenuOption->OptCol;
1634 MenuRefreshEntry->CurrentRow = MenuOption->Row;
1635 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;
1636 gMenuRefreshHead = MenuRefreshEntry;
1637 } else {
1638 //
1639 // Advance to the last entry
1640 //
1641 for (MenuRefreshEntry = gMenuRefreshHead;
1642 MenuRefreshEntry->Next != NULL;
1643 MenuRefreshEntry = MenuRefreshEntry->Next
1644 )
1645 ;
1646 MenuRefreshEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));
1647 ASSERT (MenuRefreshEntry->Next != NULL);
1648 MenuRefreshEntry = MenuRefreshEntry->Next;
1649 MenuRefreshEntry->MenuOption = MenuOption;
1650 MenuRefreshEntry->Selection = Selection;
1651 MenuRefreshEntry->CurrentColumn = MenuOption->OptCol;
1652 MenuRefreshEntry->CurrentRow = MenuOption->Row;
1653 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;
1654 }
1655 }
1656
1657 Width = (UINT16) gOptionBlockWidth;
1658 OriginalRow = Row;
1659
1660 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {
1661 if ((Temp2 == 0) && (Row <= BottomRow)) {
1662 PrintStringAt (MenuOption->OptCol, Row, OutputString);
1663 }
1664 //
1665 // If there is more string to process print on the next row and increment the Skip value
1666 //
1667 if (StrLen (&OptionString[Index])) {
1668 if (Temp2 == 0) {
1669 Row++;
1670 //
1671 // Since the Number of lines for this menu entry may or may not be reflected accurately
1672 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1673 // some testing to ensure we are keeping this in-sync.
1674 //
1675 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1676 //
1677 if ((Row - OriginalRow) >= MenuOption->Skip) {
1678 MenuOption->Skip++;
1679 }
1680 }
1681 }
1682
1683 gBS->FreePool (OutputString);
1684 if (Temp2 != 0) {
1685 Temp2--;
1686 }
1687 }
1688
1689 Temp2 = 0;
1690 Row = OriginalRow;
1691
1692 gBS->FreePool (OptionString);
1693 }
1694 //
1695 // If this is a text op with secondary text information
1696 //
1697 if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) {
1698 StringPtr = GetToken (Statement->TextTwo, MenuOption->Handle);
1699
1700 Width = (UINT16) gOptionBlockWidth;
1701 OriginalRow = Row;
1702
1703 for (Index = 0; GetLineByWidth (StringPtr, Width, &Index, &OutputString) != 0x0000;) {
1704 if ((Temp == 0) && (Row <= BottomRow)) {
1705 PrintStringAt (MenuOption->OptCol, Row, OutputString);
1706 }
1707 //
1708 // If there is more string to process print on the next row and increment the Skip value
1709 //
1710 if (StrLen (&StringPtr[Index])) {
1711 if (Temp2 == 0) {
1712 Row++;
1713 //
1714 // Since the Number of lines for this menu entry may or may not be reflected accurately
1715 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
1716 // some testing to ensure we are keeping this in-sync.
1717 //
1718 // If the difference in rows is greater than or equal to the skip value, increase the skip value
1719 //
1720 if ((Row - OriginalRow) >= MenuOption->Skip) {
1721 MenuOption->Skip++;
1722 }
1723 }
1724 }
1725
1726 gBS->FreePool (OutputString);
1727 if (Temp2 != 0) {
1728 Temp2--;
1729 }
1730 }
1731
1732 Row = OriginalRow;
1733 gBS->FreePool (StringPtr);
1734 }
1735
1736 //
1737 // Need to handle the bottom of the display
1738 //
1739 if (MenuOption->Skip > 1) {
1740 Row += MenuOption->Skip - SkipValue;
1741 SkipValue = 0;
1742 } else {
1743 Row += MenuOption->Skip;
1744 }
1745
1746 if (Row > BottomRow) {
1747 if (!ValueIsScroll (FALSE, Link)) {
1748 gDownArrow = TRUE;
1749 }
1750
1751 Row = BottomRow + 1;
1752 break;
1753 }
1754 }
1755
1756 if (!ValueIsScroll (TRUE, TopOfScreen)) {
1757 gUpArrow = TRUE;
1758 }
1759
1760 if (gUpArrow) {
1761 gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND);
1762 PrintAt (
1763 LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,
1764 TopRow - SCROLL_ARROW_HEIGHT,
1765 L"%c",
1766 ARROW_UP
1767 );
1768 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
1769 }
1770
1771 if (gDownArrow) {
1772 gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND);
1773 PrintAt (
1774 LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,
1775 BottomRow + SCROLL_ARROW_HEIGHT,
1776 L"%c",
1777 ARROW_DOWN
1778 );
1779 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
1780 }
1781
1782 MenuOption = NULL;
1783 }
1784 break;
1785
1786 case CfRefreshHighLight:
1787 //
1788 // MenuOption: Last menu option that need to remove hilight
1789 // MenuOption is set to NULL in Repaint
1790 // NewPos: Current menu option that need to hilight
1791 //
1792 ControlFlag = CfUpdateHelpString;
1793
1794 //
1795 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily
1796 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.
1797 //
1798 SavedValue = Repaint;
1799 Repaint = FALSE;
1800
1801 if (Selection->QuestionId != 0) {
1802 NewPos = Menu.ForwardLink;
1803 SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);
1804
1805 while (SavedMenuOption->ThisTag->QuestionId != Selection->QuestionId && NewPos->ForwardLink != &Menu) {
1806 NewPos = NewPos->ForwardLink;
1807 SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);
1808 }
1809 if (SavedMenuOption->ThisTag->QuestionId == Selection->QuestionId) {
1810 //
1811 // Target Question found, find its MenuOption
1812 //
1813 Link = TopOfScreen;
1814
1815 for (Index = TopRow; Index <= BottomRow && Link != NewPos;) {
1816 SavedMenuOption = MENU_OPTION_FROM_LINK (Link);
1817 Index += SavedMenuOption->Skip;
1818 Link = Link->ForwardLink;
1819 }
1820
1821 if (Link != NewPos || Index > BottomRow) {
1822 //
1823 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page
1824 //
1825 Link = NewPos;
1826 for (Index = TopRow; Index <= BottomRow; ) {
1827 Link = Link->BackLink;
1828 SavedMenuOption = MENU_OPTION_FROM_LINK (Link);
1829 Index += SavedMenuOption->Skip;
1830 }
1831 TopOfScreen = Link->ForwardLink;
1832
1833 Repaint = TRUE;
1834 NewLine = TRUE;
1835 ControlFlag = CfRepaint;
1836 break;
1837 }
1838 } else {
1839 //
1840 // Target Question not found, highlight the default menu option
1841 //
1842 NewPos = TopOfScreen;
1843 }
1844
1845 Selection->QuestionId = 0;
1846 }
1847
1848 if (NewPos != NULL && (MenuOption == NULL || NewPos != &MenuOption->Link)) {
1849 if (MenuOption != NULL) {
1850 //
1851 // Remove highlight on last Menu Option
1852 //
1853 gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);
1854 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);
1855 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
1856 if (OptionString != NULL) {
1857 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||
1858 (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)
1859 ) {
1860 //
1861 // If leading spaces on OptionString - remove the spaces
1862 //
1863 for (Index = 0; OptionString[Index] == L' '; Index++)
1864 ;
1865
1866 for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {
1867 OptionString[Count] = OptionString[Index];
1868 Count++;
1869 }
1870
1871 OptionString[Count] = CHAR_NULL;
1872 }
1873
1874 Width = (UINT16) gOptionBlockWidth;
1875 OriginalRow = MenuOption->Row;
1876
1877 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {
1878 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {
1879 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);
1880 }
1881 //
1882 // If there is more string to process print on the next row and increment the Skip value
1883 //
1884 if (StrLen (&OptionString[Index])) {
1885 MenuOption->Row++;
1886 }
1887
1888 gBS->FreePool (OutputString);
1889 }
1890
1891 MenuOption->Row = OriginalRow;
1892
1893 gBS->FreePool (OptionString);
1894 } else {
1895 if (NewLine) {
1896 if (MenuOption->GrayOut) {
1897 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND);
1898 } else if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) {
1899 gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND);
1900 }
1901
1902 OriginalRow = MenuOption->Row;
1903 Width = GetWidth (MenuOption->ThisTag, MenuOption->Handle);
1904
1905 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {
1906 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {
1907 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);
1908 }
1909 //
1910 // If there is more string to process print on the next row and increment the Skip value
1911 //
1912 if (StrLen (&MenuOption->Description[Index])) {
1913 MenuOption->Row++;
1914 }
1915
1916 gBS->FreePool (OutputString);
1917 }
1918
1919 MenuOption->Row = OriginalRow;
1920 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
1921 }
1922 }
1923 }
1924
1925 //
1926 // This is only possible if we entered this page and the first menu option is
1927 // a "non-menu" item. In that case, force it UiDown
1928 //
1929 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1930 if (!IsSelectable (MenuOption)) {
1931 ASSERT (ScreenOperation == UiNoOperation);
1932 ScreenOperation = UiDown;
1933 ControlFlag = CfScreenOperation;
1934 break;
1935 }
1936
1937 //
1938 // This is the current selected statement
1939 //
1940 Statement = MenuOption->ThisTag;
1941 Selection->Statement = Statement;
1942
1943 //
1944 // Set reverse attribute
1945 //
1946 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT);
1947 gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);
1948
1949 //
1950 // Assuming that we have a refresh linked-list created, lets annotate the
1951 // appropriate entry that we are highlighting with its new attribute. Just prior to this
1952 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh
1953 //
1954 if (gMenuRefreshHead != NULL) {
1955 for (MenuRefreshEntry = gMenuRefreshHead; MenuRefreshEntry != NULL; MenuRefreshEntry = MenuRefreshEntry->Next) {
1956 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;
1957 if (MenuRefreshEntry->MenuOption == MenuOption) {
1958 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT;
1959 }
1960 }
1961 }
1962
1963 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);
1964 if (OptionString != NULL) {
1965 if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {
1966 //
1967 // If leading spaces on OptionString - remove the spaces
1968 //
1969 for (Index = 0; OptionString[Index] == L' '; Index++)
1970 ;
1971
1972 for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {
1973 OptionString[Count] = OptionString[Index];
1974 Count++;
1975 }
1976
1977 OptionString[Count] = CHAR_NULL;
1978 }
1979 Width = (UINT16) gOptionBlockWidth;
1980
1981 OriginalRow = MenuOption->Row;
1982
1983 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {
1984 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {
1985 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);
1986 }
1987 //
1988 // If there is more string to process print on the next row and increment the Skip value
1989 //
1990 if (StrLen (&OptionString[Index])) {
1991 MenuOption->Row++;
1992 }
1993
1994 gBS->FreePool (OutputString);
1995 }
1996
1997 MenuOption->Row = OriginalRow;
1998
1999 gBS->FreePool (OptionString);
2000 } else {
2001 if (NewLine) {
2002 OriginalRow = MenuOption->Row;
2003
2004 Width = GetWidth (Statement, MenuOption->Handle);
2005
2006 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {
2007 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {
2008 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);
2009 }
2010 //
2011 // If there is more string to process print on the next row and increment the Skip value
2012 //
2013 if (StrLen (&MenuOption->Description[Index])) {
2014 MenuOption->Row++;
2015 }
2016
2017 gBS->FreePool (OutputString);
2018 }
2019
2020 MenuOption->Row = OriginalRow;
2021
2022 }
2023 }
2024
2025 if (((NewPos->ForwardLink != &Menu) && (ScreenOperation == UiDown)) ||
2026 ((NewPos->BackLink != &Menu) && (ScreenOperation == UiUp)) ||
2027 (ScreenOperation == UiNoOperation)
2028 ) {
2029 UpdateKeyHelp (MenuOption, FALSE);
2030 }
2031 //
2032 // Clear reverse attribute
2033 //
2034 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);
2035 }
2036 //
2037 // Repaint flag will be used when process CfUpdateHelpString, so restore its value
2038 // if we didn't break halfway when process CfRefreshHighLight.
2039 //
2040 Repaint = SavedValue;
2041 break;
2042
2043 case CfUpdateHelpString:
2044 ControlFlag = CfPrepareToReadKey;
2045
2046 if ((Repaint || NewLine) && (gClassOfVfr != EFI_GENERAL_APPLICATION_SUBCLASS)) {
2047 //
2048 // Don't print anything if it is a NULL help token
2049 //
2050 if (MenuOption->ThisTag->Help == 0) {
2051 StringPtr = L"\0";
2052 } else {
2053 StringPtr = GetToken (MenuOption->ThisTag->Help, MenuOption->Handle);
2054 }
2055
2056 ProcessHelpString (StringPtr, &FormattedString, BottomRow - TopRow);
2057
2058 gST->ConOut->SetAttribute (gST->ConOut, HELP_TEXT | FIELD_BACKGROUND);
2059
2060 for (Index = 0; Index < BottomRow - TopRow; Index++) {
2061 //
2062 // Pad String with spaces to simulate a clearing of the previous line
2063 //
2064 for (; GetStringWidth (&FormattedString[Index * gHelpBlockWidth * 2]) / 2 < gHelpBlockWidth;) {
2065 StrCat (&FormattedString[Index * gHelpBlockWidth * 2], L" ");
2066 }
2067
2068 PrintStringAt (
2069 LocalScreen.RightColumn - gHelpBlockWidth,
2070 Index + TopRow,
2071 &FormattedString[Index * gHelpBlockWidth * 2]
2072 );
2073 }
2074 }
2075 //
2076 // Reset this flag every time we finish using it.
2077 //
2078 Repaint = FALSE;
2079 NewLine = FALSE;
2080 break;
2081
2082 case CfPrepareToReadKey:
2083 ControlFlag = CfReadKey;
2084 ScreenOperation = UiNoOperation;
2085 break;
2086
2087 case CfReadKey:
2088 ControlFlag = CfScreenOperation;
2089
2090 //
2091 // Wait for user's selection
2092 //
2093 do {
2094 Status = UiWaitForSingleEvent (gST->ConIn->WaitForKey, 0, MinRefreshInterval);
2095 } while (Status == EFI_TIMEOUT);
2096
2097 if (Status == EFI_TIMEOUT) {
2098 Key.UnicodeChar = CHAR_CARRIAGE_RETURN;
2099 } else {
2100 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2101 //
2102 // if we encounter error, continue to read another key in.
2103 //
2104 if (EFI_ERROR (Status)) {
2105 ControlFlag = CfReadKey;
2106 continue;
2107 }
2108 }
2109
2110 if (IsListEmpty (&Menu) && Key.UnicodeChar != CHAR_NULL) {
2111 //
2112 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2113 //
2114 break;
2115 }
2116
2117 switch (Key.UnicodeChar) {
2118 case CHAR_CARRIAGE_RETURN:
2119 ScreenOperation = UiSelect;
2120 gDirection = 0;
2121 break;
2122
2123 //
2124 // We will push the adjustment of these numeric values directly to the input handler
2125 // NOTE: we won't handle manual input numeric
2126 //
2127 case '+':
2128 case '-':
2129 Statement = MenuOption->ThisTag;
2130 if ((Statement->Operand == EFI_IFR_DATE_OP)
2131 || (Statement->Operand == EFI_IFR_TIME_OP)
2132 || ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step != 0))
2133 ){
2134 if (Key.UnicodeChar == '+') {
2135 gDirection = SCAN_RIGHT;
2136 } else {
2137 gDirection = SCAN_LEFT;
2138 }
2139 Status = ProcessOptions (Selection, MenuOption, TRUE, &OptionString);
2140 SafeFreePool (OptionString);
2141 }
2142 break;
2143
2144 case '^':
2145 ScreenOperation = UiUp;
2146 break;
2147
2148 case 'V':
2149 case 'v':
2150 ScreenOperation = UiDown;
2151 break;
2152
2153 case ' ':
2154 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {
2155 if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut) {
2156 ScreenOperation = UiSelect;
2157 }
2158 }
2159 break;
2160
2161 case CHAR_NULL:
2162 if (((Key.ScanCode == SCAN_F1) && ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE)) ||
2163 ((Key.ScanCode == SCAN_F2) && ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO)) ||
2164 ((Key.ScanCode == SCAN_F9) && ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE)) ||
2165 ((Key.ScanCode == SCAN_F10) && ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN))
2166 ) {
2167 //
2168 // If the function key has been disabled, just ignore the key.
2169 //
2170 } else {
2171 for (Index = 0; Index < sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]); Index++) {
2172 if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {
2173 if (Key.ScanCode == SCAN_F9) {
2174 //
2175 // Reset to standard default
2176 //
2177 DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;
2178 }
2179 ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;
2180 break;
2181 }
2182 }
2183 }
2184 break;
2185 }
2186 break;
2187
2188 case CfScreenOperation:
2189 if (ScreenOperation != UiPrevious && ScreenOperation != UiReset) {
2190 //
2191 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset
2192 // ignore the selection and go back to reading keys.
2193 //
2194 if (IsListEmpty (&Menu)) {
2195 ControlFlag = CfReadKey;
2196 break;
2197 }
2198 //
2199 // if there is nothing logical to place a cursor on, just move on to wait for a key.
2200 //
2201 for (Link = Menu.ForwardLink; Link != &Menu; Link = Link->ForwardLink) {
2202 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
2203 if (IsSelectable (NextMenuOption)) {
2204 break;
2205 }
2206 }
2207
2208 if (Link == &Menu) {
2209 ControlFlag = CfPrepareToReadKey;
2210 break;
2211 }
2212 } else if (ScreenOperation == UiReset) {
2213 //
2214 // Press ESC to exit FormSet
2215 //
2216 Selection->Action = UI_ACTION_EXIT;
2217 Selection->Statement = NULL;
2218 }
2219
2220 for (Index = 0;
2221 Index < sizeof (gScreenOperationToControlFlag) / sizeof (gScreenOperationToControlFlag[0]);
2222 Index++
2223 ) {
2224 if (ScreenOperation == gScreenOperationToControlFlag[Index].ScreenOperation) {
2225 ControlFlag = gScreenOperationToControlFlag[Index].ControlFlag;
2226 break;
2227 }
2228 }
2229 break;
2230
2231 case CfUiPrevious:
2232 ControlFlag = CfCheckSelection;
2233
2234 if (IsListEmpty (&gMenuList)) {
2235 Selection->Action = UI_ACTION_NONE;
2236 if (IsListEmpty (&Menu)) {
2237 ControlFlag = CfReadKey;
2238 }
2239 break;
2240 }
2241
2242 //
2243 // Remove the Cached page entry
2244 //
2245 UiRemoveMenuListEntry (Selection);
2246
2247 Selection->Action = UI_ACTION_REFRESH_FORM;
2248 Selection->Statement = NULL;
2249 break;
2250
2251 case CfUiSelect:
2252 ControlFlag = CfCheckSelection;
2253
2254 Statement = MenuOption->ThisTag;
2255 if ((Statement->Operand == EFI_IFR_TEXT_OP) ||
2256 (Statement->Operand == EFI_IFR_DATE_OP) ||
2257 (Statement->Operand == EFI_IFR_TIME_OP) ||
2258 (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0)) {
2259 break;
2260 }
2261
2262 //
2263 // Keep highlight on current MenuOption
2264 //
2265 Selection->QuestionId = Statement->QuestionId;
2266
2267 switch (Statement->Operand) {
2268 case EFI_IFR_REF_OP:
2269 if (Statement->RefDevicePath != 0) {
2270 //
2271 // Goto another Hii Package list
2272 //
2273 ControlFlag = CfUiReset;
2274 Selection->Action = UI_ACTION_REFRESH_FORMSET;
2275
2276 StringPtr = GetToken (Statement->RefDevicePath, Selection->FormSet->HiiHandle);
2277 if (StringPtr == NULL) {
2278 //
2279 // No device path string not found, exit
2280 //
2281 Selection->Action = UI_ACTION_EXIT;
2282 Selection->Statement = NULL;
2283 break;
2284 }
2285 BufferSize = StrLen (StringPtr) / 2;
2286 DevicePath = AllocatePool (BufferSize);
2287
2288 HexStringToBufInReverseOrder ((UINT8 *) DevicePath, &BufferSize, StringPtr);
2289 Selection->Handle = HiiLibDevicePathToHiiHandle (DevicePath);
2290 if (Selection->Handle == NULL) {
2291 //
2292 // If target Hii Handle not found, exit
2293 //
2294 Selection->Action = UI_ACTION_EXIT;
2295 Selection->Statement = NULL;
2296 break;
2297 }
2298
2299 gBS->FreePool (StringPtr);
2300 gBS->FreePool (DevicePath);
2301
2302 CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));
2303 Selection->FormId = Statement->RefFormId;
2304 Selection->QuestionId = Statement->RefQuestionId;
2305 } else if (!CompareGuid (&Statement->RefFormSetId, &gZeroGuid)) {
2306 //
2307 // Goto another Formset, check for uncommitted data
2308 //
2309 ControlFlag = CfUiReset;
2310 Selection->Action = UI_ACTION_REFRESH_FORMSET;
2311
2312 CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));
2313 Selection->FormId = Statement->RefFormId;
2314 Selection->QuestionId = Statement->RefQuestionId;
2315 } else if (Statement->RefFormId != 0) {
2316 //
2317 // Goto another form inside this formset,
2318 //
2319 Selection->Action = UI_ACTION_REFRESH_FORM;
2320
2321 //
2322 // Link current form so that we can always go back when someone hits the UiPrevious
2323 //
2324 UiAddMenuListEntry (Selection);
2325
2326 Selection->FormId = Statement->RefFormId;
2327 Selection->QuestionId = Statement->RefQuestionId;
2328 } else if (Statement->RefQuestionId != 0) {
2329 //
2330 // Goto another Question
2331 //
2332 Selection->QuestionId = Statement->RefQuestionId;
2333
2334 if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {
2335 Selection->Action = UI_ACTION_REFRESH_FORM;
2336 } else {
2337 Repaint = TRUE;
2338 NewLine = TRUE;
2339 break;
2340 }
2341 }
2342 break;
2343
2344 case EFI_IFR_ACTION_OP:
2345 //
2346 // Process the Config string <ConfigResp>
2347 //
2348 Status = ProcessQuestionConfig (Selection, Statement);
2349
2350 if (EFI_ERROR (Status)) {
2351 break;
2352 }
2353
2354 //
2355 // The action button may change some Question value, so refresh the form
2356 //
2357 Selection->Action = UI_ACTION_REFRESH_FORM;
2358 break;
2359
2360 case EFI_IFR_RESET_BUTTON_OP:
2361 //
2362 // Reset Question to default value specified by DefaultId
2363 //
2364 ControlFlag = CfUiDefault;
2365 DefaultId = Statement->DefaultId;
2366 break;
2367
2368 default:
2369 //
2370 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2371 //
2372 UpdateKeyHelp (MenuOption, TRUE);
2373 Status = ProcessOptions (Selection, MenuOption, TRUE, &OptionString);
2374
2375 if (EFI_ERROR (Status)) {
2376 Repaint = TRUE;
2377 NewLine = TRUE;
2378 break;
2379 }
2380
2381 if (OptionString != NULL) {
2382 PrintStringAt (LocalScreen.LeftColumn + gPromptBlockWidth + 1, MenuOption->Row, OptionString);
2383 gBS->FreePool (OptionString);
2384 }
2385
2386 Selection->Action = UI_ACTION_REFRESH_FORM;
2387 break;
2388 }
2389 break;
2390
2391 case CfUiReset:
2392 //
2393 // We are going to leave current FormSet, so check uncommited data in this FormSet
2394 //
2395 ControlFlag = CfCheckSelection;
2396
2397 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {
2398 //
2399 // There is no parent menu for FrontPage
2400 //
2401 Selection->Action = UI_ACTION_NONE;
2402 Selection->Statement = MenuOption->ThisTag;
2403 break;
2404 }
2405
2406 //
2407 // If NV flag is up, prompt user
2408 //
2409 if (gNvUpdateRequired) {
2410 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2411
2412 YesResponse = gYesResponse[0];
2413 NoResponse = gNoResponse[0];
2414
2415 do {
2416 CreateDialog (3, TRUE, 0, NULL, &Key, gEmptyString, gAreYouSure, gEmptyString);
2417 } while
2418 (
2419 (Key.ScanCode != SCAN_ESC) &&
2420 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
2421 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
2422 );
2423
2424 //
2425 // If the user hits the YesResponse key
2426 //
2427 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
2428 } else {
2429 Repaint = TRUE;
2430 NewLine = TRUE;
2431
2432 Selection->Action = UI_ACTION_NONE;
2433 break;
2434 }
2435 }
2436
2437 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
2438 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
2439
2440 UiFreeMenuList ();
2441 gST->ConOut->ClearScreen (gST->ConOut);
2442 return EFI_SUCCESS;
2443
2444 case CfUiLeft:
2445 ControlFlag = CfCheckSelection;
2446 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {
2447 if (MenuOption->Sequence != 0) {
2448 //
2449 // In the middle or tail of the Date/Time op-code set, go left.
2450 //
2451 NewPos = NewPos->BackLink;
2452 }
2453 }
2454 break;
2455
2456 case CfUiRight:
2457 ControlFlag = CfCheckSelection;
2458 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {
2459 if (MenuOption->Sequence != 2) {
2460 //
2461 // In the middle or tail of the Date/Time op-code set, go left.
2462 //
2463 NewPos = NewPos->ForwardLink;
2464 }
2465 }
2466 break;
2467
2468 case CfUiUp:
2469 ControlFlag = CfCheckSelection;
2470
2471 SavedListEntry = TopOfScreen;
2472
2473 if (NewPos->BackLink != &Menu) {
2474 NewLine = TRUE;
2475 //
2476 // Adjust Date/Time position before we advance forward.
2477 //
2478 AdjustDateAndTimePosition (TRUE, &NewPos);
2479
2480 //
2481 // Caution that we have already rewind to the top, don't go backward in this situation.
2482 //
2483 if (NewPos->BackLink != &Menu) {
2484 NewPos = NewPos->BackLink;
2485 }
2486
2487 PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos);
2488 DistanceValue = PreviousMenuOption->Skip;
2489
2490 //
2491 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended
2492 // to be one that back to the previous set of op-codes, we need to advance to the sencond
2493 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2494 // checking can be done.
2495 //
2496 DistanceValue += AdjustDateAndTimePosition (TRUE, &NewPos);
2497
2498 //
2499 // Check the previous menu entry to see if it was a zero-length advance. If it was,
2500 // don't worry about a redraw.
2501 //
2502 if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) {
2503 Repaint = TRUE;
2504 TopOfScreen = NewPos;
2505 }
2506
2507 Difference = MoveToNextStatement (TRUE, &NewPos);
2508 if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) {
2509 if (Difference > 0) {
2510 //
2511 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2512 //
2513 TopOfScreen = NewPos;
2514 Repaint = TRUE;
2515 }
2516 }
2517 if (Difference < 0) {
2518 //
2519 // We want to goto previous MenuOption, but finally we go down.
2520 // it means that we hit the begining MenuOption that can be focused
2521 // so we simply scroll to the top
2522 //
2523 if (SavedListEntry != Menu.ForwardLink) {
2524 TopOfScreen = Menu.ForwardLink;
2525 Repaint = TRUE;
2526 }
2527 }
2528
2529 //
2530 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2531 //
2532 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
2533
2534 UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);
2535 } else {
2536 SavedMenuOption = MenuOption;
2537 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
2538 if (!IsSelectable (MenuOption)) {
2539 //
2540 // If we are at the end of the list and sitting on a text op, we need to more forward
2541 //
2542 ScreenOperation = UiDown;
2543 ControlFlag = CfScreenOperation;
2544 break;
2545 }
2546
2547 MenuOption = SavedMenuOption;
2548 }
2549 break;
2550
2551 case CfUiPageUp:
2552 ControlFlag = CfCheckSelection;
2553
2554 if (NewPos->BackLink == &Menu) {
2555 NewLine = FALSE;
2556 Repaint = FALSE;
2557 break;
2558 }
2559
2560 NewLine = TRUE;
2561 Repaint = TRUE;
2562 Link = TopOfScreen;
2563 PreviousMenuOption = MENU_OPTION_FROM_LINK (Link);
2564 Index = BottomRow;
2565 while ((Index >= TopRow) && (Link->BackLink != &Menu)) {
2566 Index = Index - PreviousMenuOption->Skip;
2567 Link = Link->BackLink;
2568 PreviousMenuOption = MENU_OPTION_FROM_LINK (Link);
2569 }
2570
2571 TopOfScreen = Link;
2572 Difference = MoveToNextStatement (TRUE, &Link);
2573 if (Difference > 0) {
2574 //
2575 // The focus MenuOption is above the TopOfScreen
2576 //
2577 TopOfScreen = Link;
2578 } else if (Difference < 0) {
2579 //
2580 // This happens when there is no MenuOption can be focused from
2581 // Current MenuOption to the first MenuOption
2582 //
2583 TopOfScreen = Menu.ForwardLink;
2584 }
2585 Index += Difference;
2586 if (Index < TopRow) {
2587 MenuOption = NULL;
2588 }
2589
2590 if (NewPos == Link) {
2591 Repaint = FALSE;
2592 NewLine = FALSE;
2593 } else {
2594 NewPos = Link;
2595 }
2596
2597 //
2598 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2599 // Don't do this when we are already in the first page.
2600 //
2601 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
2602 AdjustDateAndTimePosition (TRUE, &NewPos);
2603 break;
2604
2605 case CfUiPageDown:
2606 ControlFlag = CfCheckSelection;
2607
2608 if (NewPos->ForwardLink == &Menu) {
2609 NewLine = FALSE;
2610 Repaint = FALSE;
2611 break;
2612 }
2613
2614 NewLine = TRUE;
2615 Repaint = TRUE;
2616 Link = TopOfScreen;
2617 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
2618 Index = TopRow;
2619 while ((Index <= BottomRow) && (Link->ForwardLink != &Menu)) {
2620 Index = Index + NextMenuOption->Skip;
2621 Link = Link->ForwardLink;
2622 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
2623 }
2624
2625 Index += MoveToNextStatement (FALSE, &Link);
2626 if (Index > BottomRow) {
2627 //
2628 // There are more MenuOption needing scrolling
2629 //
2630 TopOfScreen = Link;
2631 MenuOption = NULL;
2632 }
2633 if (NewPos == Link && Index <= BottomRow) {
2634 //
2635 // Finally we know that NewPos is the last MenuOption can be focused.
2636 //
2637 NewLine = FALSE;
2638 Repaint = FALSE;
2639 } else {
2640 NewPos = Link;
2641 }
2642
2643 //
2644 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2645 // Don't do this when we are already in the last page.
2646 //
2647 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
2648 AdjustDateAndTimePosition (TRUE, &NewPos);
2649 break;
2650
2651 case CfUiDown:
2652 ControlFlag = CfCheckSelection;
2653 //
2654 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
2655 // to be one that progresses to the next set of op-codes, we need to advance to the last
2656 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
2657 // checking can be done. The only other logic we need to introduce is that if a Date/Time
2658 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
2659 // the Date/Time op-code.
2660 //
2661 SavedListEntry = NewPos;
2662 DistanceValue = AdjustDateAndTimePosition (FALSE, &NewPos);
2663
2664 if (NewPos->ForwardLink != &Menu) {
2665 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
2666 NewLine = TRUE;
2667 NewPos = NewPos->ForwardLink;
2668 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);
2669
2670 DistanceValue += NextMenuOption->Skip;
2671 DistanceValue += MoveToNextStatement (FALSE, &NewPos);
2672 //
2673 // An option might be multi-line, so we need to reflect that data in the overall skip value
2674 //
2675 UpdateOptionSkipLines (Selection, NextMenuOption, &OptionString, SkipValue);
2676
2677 Temp = MenuOption->Row + MenuOption->Skip + DistanceValue - 1;
2678 if ((MenuOption->Row + MenuOption->Skip == BottomRow + 1) &&
2679 (NextMenuOption->ThisTag->Operand == EFI_IFR_DATE_OP ||
2680 NextMenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)
2681 ) {
2682 Temp ++;
2683 }
2684
2685 //
2686 // If we are going to scroll, update TopOfScreen
2687 //
2688 if (Temp > BottomRow) {
2689 do {
2690 //
2691 // Is the current top of screen a zero-advance op-code?
2692 // If so, keep moving forward till we hit a >0 advance op-code
2693 //
2694 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
2695
2696 //
2697 // If bottom op-code is more than one line or top op-code is more than one line
2698 //
2699 if ((DistanceValue > 1) || (MenuOption->Skip > 1)) {
2700 //
2701 // Is the bottom op-code greater than or equal in size to the top op-code?
2702 //
2703 if ((Temp - BottomRow) >= (SavedMenuOption->Skip - OldSkipValue)) {
2704 //
2705 // Skip the top op-code
2706 //
2707 TopOfScreen = TopOfScreen->ForwardLink;
2708 Difference = (Temp - BottomRow) - (SavedMenuOption->Skip - OldSkipValue);
2709
2710 OldSkipValue = Difference;
2711
2712 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
2713
2714 //
2715 // If we have a remainder, skip that many more op-codes until we drain the remainder
2716 //
2717 for (;
2718 Difference >= (INTN) SavedMenuOption->Skip;
2719 Difference = Difference - (INTN) SavedMenuOption->Skip
2720 ) {
2721 //
2722 // Since the Difference is greater than or equal to this op-code's skip value, skip it
2723 //
2724 TopOfScreen = TopOfScreen->ForwardLink;
2725 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
2726 if (Difference < (INTN) SavedMenuOption->Skip) {
2727 Difference = SavedMenuOption->Skip - Difference - 1;
2728 break;
2729 } else {
2730 if (Difference == (INTN) SavedMenuOption->Skip) {
2731 TopOfScreen = TopOfScreen->ForwardLink;
2732 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
2733 Difference = SavedMenuOption->Skip - Difference;
2734 break;
2735 }
2736 }
2737 }
2738 //
2739 // Since we will act on this op-code in the next routine, and increment the
2740 // SkipValue, set the skips to one less than what is required.
2741 //
2742 SkipValue = Difference - 1;
2743
2744 } else {
2745 //
2746 // Since we will act on this op-code in the next routine, and increment the
2747 // SkipValue, set the skips to one less than what is required.
2748 //
2749 SkipValue = OldSkipValue + (Temp - BottomRow) - 1;
2750 }
2751 } else {
2752 if ((OldSkipValue + 1) == (INTN) SavedMenuOption->Skip) {
2753 TopOfScreen = TopOfScreen->ForwardLink;
2754 break;
2755 } else {
2756 SkipValue = OldSkipValue;
2757 }
2758 }
2759 //
2760 // If the op-code at the top of the screen is more than one line, let's not skip it yet
2761 // Let's set a skip flag to smoothly scroll the top of the screen.
2762 //
2763 if (SavedMenuOption->Skip > 1) {
2764 if (SavedMenuOption == NextMenuOption) {
2765 SkipValue = 0;
2766 } else {
2767 SkipValue++;
2768 }
2769 } else {
2770 SkipValue = 0;
2771 TopOfScreen = TopOfScreen->ForwardLink;
2772 }
2773 } while (SavedMenuOption->Skip == 0);
2774
2775 Repaint = TRUE;
2776 OldSkipValue = SkipValue;
2777 }
2778
2779 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
2780
2781 UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);
2782
2783 } else {
2784 SavedMenuOption = MenuOption;
2785 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
2786 if (!IsSelectable (MenuOption)) {
2787 //
2788 // If we are at the end of the list and sitting on a text op, we need to more forward
2789 //
2790 ScreenOperation = UiUp;
2791 ControlFlag = CfScreenOperation;
2792 break;
2793 }
2794
2795 MenuOption = SavedMenuOption;
2796 //
2797 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
2798 //
2799 AdjustDateAndTimePosition (TRUE, &NewPos);
2800 }
2801 break;
2802
2803 case CfUiSave:
2804 ControlFlag = CfCheckSelection;
2805
2806 //
2807 // Submit the form
2808 //
2809 Status = SubmitForm (Selection->FormSet, Selection->Form);
2810
2811 if (!EFI_ERROR (Status)) {
2812 UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);
2813 UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE);
2814 } else {
2815 do {
2816 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveFailed, gPressEnter, gEmptyString);
2817 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
2818
2819 Repaint = TRUE;
2820 NewLine = TRUE;
2821 }
2822 break;
2823
2824 case CfUiDefault:
2825 ControlFlag = CfCheckSelection;
2826
2827 Status = ExtractFormDefault (Selection->FormSet, Selection->Form, DefaultId);
2828
2829 if (!EFI_ERROR (Status)) {
2830 Selection->Action = UI_ACTION_REFRESH_FORM;
2831 Selection->Statement = NULL;
2832
2833 //
2834 // Show NV update flag on status bar
2835 //
2836 gNvUpdateRequired = TRUE;
2837 }
2838 break;
2839
2840 case CfUiNoOperation:
2841 ControlFlag = CfCheckSelection;
2842 break;
2843
2844 case CfExit:
2845 UiFreeRefreshList ();
2846
2847 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
2848 gST->ConOut->SetCursorPosition (gST->ConOut, 0, Row + 4);
2849 gST->ConOut->EnableCursor (gST->ConOut, TRUE);
2850 gST->ConOut->OutputString (gST->ConOut, L"\n");
2851
2852 return EFI_SUCCESS;
2853
2854 default:
2855 break;
2856 }
2857 }
2858 }