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