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