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