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