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