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