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