]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
Fixed user input arrow down/ page down caused form display highlight menu error.
[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 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "FormDisplay.h"
17
18 //
19 // Search table for UiDisplayMenu()
20 //
21 SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation[] = {
22 {
23 SCAN_UP,
24 UiUp,
25 },
26 {
27 SCAN_DOWN,
28 UiDown,
29 },
30 {
31 SCAN_PAGE_UP,
32 UiPageUp,
33 },
34 {
35 SCAN_PAGE_DOWN,
36 UiPageDown,
37 },
38 {
39 SCAN_ESC,
40 UiReset,
41 },
42 {
43 SCAN_LEFT,
44 UiLeft,
45 },
46 {
47 SCAN_RIGHT,
48 UiRight,
49 }
50 };
51
52 UINTN mScanCodeNumber = sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]);
53
54 SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag[] = {
55 {
56 UiNoOperation,
57 CfUiNoOperation,
58 },
59 {
60 UiSelect,
61 CfUiSelect,
62 },
63 {
64 UiUp,
65 CfUiUp,
66 },
67 {
68 UiDown,
69 CfUiDown,
70 },
71 {
72 UiLeft,
73 CfUiLeft,
74 },
75 {
76 UiRight,
77 CfUiRight,
78 },
79 {
80 UiReset,
81 CfUiReset,
82 },
83 {
84 UiPageUp,
85 CfUiPageUp,
86 },
87 {
88 UiPageDown,
89 CfUiPageDown
90 },
91 {
92 UiHotKey,
93 CfUiHotKey
94 }
95 };
96
97 EFI_GUID gDisplayEngineGuid = {
98 0xE38C1029, 0xE38F, 0x45b9, {0x8F, 0x0D, 0xE2, 0xE6, 0x0B, 0xC9, 0xB2, 0x62}
99 };
100
101 BOOLEAN gMisMatch;
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 Get the index info for this opcode.
1478
1479 @param OpCode The input opcode for the statement.
1480
1481 @retval The index of this statement.
1482
1483 **/
1484 UINTN
1485 GetIndexInfoForOpcode (
1486 IN EFI_IFR_OP_HEADER *OpCode
1487 )
1488 {
1489 LIST_ENTRY *NewPos;
1490 UI_MENU_OPTION *MenuOption;
1491 UINTN Index;
1492
1493 NewPos = gMenuOption.ForwardLink;
1494 Index = 0;
1495
1496 for (NewPos = gMenuOption.ForwardLink; NewPos != &gMenuOption; NewPos = NewPos->ForwardLink){
1497 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1498
1499 if (CompareMem (MenuOption->ThisTag->OpCode, OpCode, OpCode->Length) == 0) {
1500 if (MenuOption->ThisTag->OpCode == OpCode) {
1501 return Index;
1502 }
1503
1504 Index ++;
1505 }
1506 }
1507
1508 return Index;
1509 }
1510
1511 /**
1512 Is this the saved highlight statement.
1513
1514 @param HighLightedStatement The input highlight statement.
1515
1516 @retval TRUE This is the highlight statement.
1517 @retval FALSE This is not the highlight statement.
1518
1519 **/
1520 BOOLEAN
1521 IsSavedHighlightStatement (
1522 IN FORM_DISPLAY_ENGINE_STATEMENT *HighLightedStatement
1523 )
1524 {
1525 if ((gFormData->HiiHandle == gHighligthMenuInfo.HiiHandle) &&
1526 (gFormData->FormId == gHighligthMenuInfo.FormId)) {
1527 if (gHighligthMenuInfo.HLTQuestionId != 0) {
1528 return (gHighligthMenuInfo.HLTQuestionId == GetQuestionIdInfo (HighLightedStatement->OpCode));
1529 } else {
1530 if (CompareMem (gHighligthMenuInfo.HLTOpCode, HighLightedStatement->OpCode, gHighligthMenuInfo.HLTOpCode->Length) == 0) {
1531 if (gHighligthMenuInfo.HLTIndex == 0 || gHighligthMenuInfo.HLTIndex == GetIndexInfoForOpcode(HighLightedStatement->OpCode)) {
1532 return TRUE;
1533 } else {
1534 return FALSE;
1535 }
1536 }
1537 }
1538 }
1539
1540 return FALSE;
1541 }
1542
1543 /**
1544 Is this the highlight menu.
1545
1546 @param MenuOption The input Menu option.
1547
1548 @retval TRUE This is the highlight menu option.
1549 @retval FALSE This is not the highlight menu option.
1550
1551 **/
1552 BOOLEAN
1553 IsHighLightMenuOption (
1554 IN UI_MENU_OPTION *MenuOption
1555 )
1556 {
1557 if (gHighligthMenuInfo.HLTQuestionId != 0) {
1558 if (GetQuestionIdInfo(MenuOption->ThisTag->OpCode) == gHighligthMenuInfo.HLTQuestionId) {
1559 return (MenuOption->Sequence == gHighligthMenuInfo.HLTSequence);
1560 }
1561 } else {
1562 if(CompareMem (gHighligthMenuInfo.HLTOpCode, MenuOption->ThisTag->OpCode, gHighligthMenuInfo.HLTOpCode->Length) == 0) {
1563 if (gHighligthMenuInfo.HLTIndex == 0 || gHighligthMenuInfo.HLTIndex == GetIndexInfoForOpcode(MenuOption->ThisTag->OpCode)) {
1564 return (MenuOption->Sequence == gHighligthMenuInfo.HLTSequence);
1565 } else {
1566 return FALSE;
1567 }
1568 }
1569 }
1570
1571 return FALSE;
1572 }
1573
1574 /**
1575 Find the highlight menu.
1576
1577 If the input is NULL, base on the record highlight info in
1578 gHighligthMenuInfo to find the last highlight menu.
1579
1580 @param HighLightedStatement The input highlight statement.
1581
1582 @retval The highlight menu index.
1583
1584 **/
1585 LIST_ENTRY *
1586 FindHighLightMenuOption (
1587 IN FORM_DISPLAY_ENGINE_STATEMENT *HighLightedStatement
1588 )
1589 {
1590 LIST_ENTRY *NewPos;
1591 UI_MENU_OPTION *MenuOption;
1592
1593 NewPos = gMenuOption.ForwardLink;
1594 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1595
1596 if (HighLightedStatement != NULL) {
1597 while (MenuOption->ThisTag != HighLightedStatement) {
1598 NewPos = NewPos->ForwardLink;
1599 if (NewPos == &gMenuOption) {
1600 //
1601 // Not Found it, break
1602 //
1603 break;
1604 }
1605 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1606 }
1607
1608 //
1609 // Must find the highlight statement.
1610 //
1611 ASSERT (NewPos != &gMenuOption);
1612
1613 } else {
1614 while (!IsHighLightMenuOption (MenuOption)) {
1615 NewPos = NewPos->ForwardLink;
1616 if (NewPos == &gMenuOption) {
1617 //
1618 // Not Found it, break
1619 //
1620 break;
1621 }
1622 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1623 }
1624
1625 //
1626 // Highlight statement has disappear (suppressed/disableed)
1627 //
1628 if (NewPos == &gMenuOption) {
1629 NewPos = NULL;
1630 }
1631 }
1632
1633 return NewPos;
1634 }
1635
1636 /**
1637 Is this the Top of screen menu.
1638
1639 @param MenuOption The input Menu option.
1640
1641 @retval TRUE This is the Top of screen menu option.
1642 @retval FALSE This is not the Top of screen menu option.
1643
1644 **/
1645 BOOLEAN
1646 IsTopOfScreeMenuOption (
1647 IN UI_MENU_OPTION *MenuOption
1648 )
1649 {
1650 if (gHighligthMenuInfo.TOSQuestionId != 0) {
1651 return (GetQuestionIdInfo(MenuOption->ThisTag->OpCode) == gHighligthMenuInfo.TOSQuestionId);
1652 }
1653
1654 if(CompareMem (gHighligthMenuInfo.TOSOpCode, MenuOption->ThisTag->OpCode, gHighligthMenuInfo.TOSOpCode->Length) == 0) {
1655 if (gHighligthMenuInfo.TOSIndex == 0 || gHighligthMenuInfo.TOSIndex == GetIndexInfoForOpcode(MenuOption->ThisTag->OpCode)) {
1656 return TRUE;
1657 } else {
1658 return FALSE;
1659 }
1660 }
1661
1662 return FALSE;
1663 }
1664
1665 /**
1666 Find the Top of screen menu.
1667
1668 If the input is NULL, base on the record highlight info in
1669 gHighligthMenuInfo to find the last highlight menu.
1670
1671 @param HighLightedStatement The input highlight statement.
1672
1673 @retval The highlight menu index.
1674
1675 **/
1676 LIST_ENTRY *
1677 FindTopOfScreenMenuOption (
1678 VOID
1679 )
1680 {
1681 LIST_ENTRY *NewPos;
1682 UI_MENU_OPTION *MenuOption;
1683
1684 NewPos = gMenuOption.ForwardLink;
1685 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1686
1687 while (!IsTopOfScreeMenuOption(MenuOption)) {
1688 NewPos = NewPos->ForwardLink;
1689 if (NewPos == &gMenuOption) {
1690 //
1691 // Not Found it, break
1692 //
1693 break;
1694 }
1695 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
1696 }
1697
1698 //
1699 // Last time top of screen menu has disappeared.
1700 //
1701 if (NewPos == &gMenuOption) {
1702 NewPos = NULL;
1703 }
1704
1705 return NewPos;
1706 }
1707
1708 /**
1709 Find the first menu which will be show at the top.
1710
1711 @param FormData The data info for this form.
1712 @param TopOfScreen The link_entry pointer to top menu.
1713 @param HighlightMenu The menu which will be highlight.
1714 @param SkipValue The skip value for the top menu.
1715
1716 **/
1717 VOID
1718 FindTopMenu (
1719 IN FORM_DISPLAY_ENGINE_FORM *FormData,
1720 OUT LIST_ENTRY **TopOfScreen,
1721 OUT LIST_ENTRY **HighlightMenu,
1722 OUT UINTN *SkipValue
1723 )
1724 {
1725 UINTN TopRow;
1726 UINTN BottomRow;
1727 UI_MENU_OPTION *MenuOption;
1728 UINTN TmpValue;
1729
1730 TopRow = gStatementDimensions.TopRow + SCROLL_ARROW_HEIGHT;
1731 BottomRow = gStatementDimensions.BottomRow - SCROLL_ARROW_HEIGHT;
1732
1733 if (gMisMatch) {
1734 //
1735 // Reenter caused by option mismatch or auto exit caused by refresh form(refresh interval/guid),
1736 // base on the record highlight info to find the highlight menu.
1737 //
1738 ASSERT (gFormData->HiiHandle == gHighligthMenuInfo.HiiHandle &&
1739 gFormData->FormId == gHighligthMenuInfo.FormId);
1740
1741 *HighlightMenu = FindHighLightMenuOption(NULL);
1742 if (*HighlightMenu != NULL) {
1743 //
1744 // Update skip info for this highlight menu.
1745 //
1746 MenuOption = MENU_OPTION_FROM_LINK (*HighlightMenu);
1747 UpdateOptionSkipLines (MenuOption);
1748
1749 //
1750 // Found the last time highlight menu.
1751 //
1752 *TopOfScreen = FindTopOfScreenMenuOption();
1753 if (*TopOfScreen != NULL) {
1754 //
1755 // Found the last time selectable top of screen menu.
1756 //
1757 AdjustDateAndTimePosition(TRUE, TopOfScreen);
1758 MenuOption = MENU_OPTION_FROM_LINK (*TopOfScreen);
1759 UpdateOptionSkipLines (MenuOption);
1760
1761 *SkipValue = gHighligthMenuInfo.SkipValue;
1762 } else {
1763 //
1764 // Not found last time top of screen menu, so base on current highlight menu
1765 // to find the new top of screen menu.
1766 // Make the current highlight menu at the bottom of the form to calculate the
1767 // top of screen menu.
1768 //
1769 if (MenuOption->Skip >= BottomRow - TopRow) {
1770 *TopOfScreen = *HighlightMenu;
1771 TmpValue = 0;
1772 } else {
1773 *TopOfScreen = FindTopOfScreenMenu(*HighlightMenu, BottomRow - TopRow - MenuOption->Skip, &TmpValue);
1774 }
1775
1776 *SkipValue = TmpValue;
1777 }
1778 } else {
1779 //
1780 // Last time highlight menu has disappear, find the first highlightable menu as the defalut one.
1781 //
1782 *HighlightMenu = gMenuOption.ForwardLink;
1783 if (!IsListEmpty (&gMenuOption)) {
1784 MoveToNextStatement (FALSE, HighlightMenu, BottomRow - TopRow, TRUE);
1785 }
1786 *TopOfScreen = gMenuOption.ForwardLink;
1787 *SkipValue = 0;
1788 }
1789
1790 gMisMatch = FALSE;
1791 } else if (FormData->HighLightedStatement != NULL) {
1792 if (IsSavedHighlightStatement (FormData->HighLightedStatement)) {
1793 //
1794 // Input highlight menu is same as last time highlight menu.
1795 // Base on last time highlight menu to set the top of screen menu and highlight menu.
1796 //
1797 *HighlightMenu = FindHighLightMenuOption(NULL);
1798 ASSERT (*HighlightMenu != NULL);
1799
1800 //
1801 // Update skip info for this highlight menu.
1802 //
1803 MenuOption = MENU_OPTION_FROM_LINK (*HighlightMenu);
1804 UpdateOptionSkipLines (MenuOption);
1805
1806 *TopOfScreen = FindTopOfScreenMenuOption();
1807 if (*TopOfScreen == NULL) {
1808 //
1809 // Not found last time top of screen menu, so base on current highlight menu
1810 // to find the new top of screen menu.
1811 // Make the current highlight menu at the bottom of the form to calculate the
1812 // top of screen menu.
1813 //
1814 if (MenuOption->Skip >= BottomRow - TopRow) {
1815 *TopOfScreen = *HighlightMenu;
1816 TmpValue = 0;
1817 } else {
1818 *TopOfScreen = FindTopOfScreenMenu(*HighlightMenu, BottomRow - TopRow - MenuOption->Skip, &TmpValue);
1819 }
1820
1821 *SkipValue = TmpValue;
1822 } else {
1823 AdjustDateAndTimePosition(TRUE, TopOfScreen);
1824 MenuOption = MENU_OPTION_FROM_LINK (*TopOfScreen);
1825 UpdateOptionSkipLines (MenuOption);
1826
1827 *SkipValue = gHighligthMenuInfo.SkipValue;
1828 }
1829 AdjustDateAndTimePosition(TRUE, TopOfScreen);
1830 } else {
1831 //
1832 // Input highlight menu is not save as last time highlight menu.
1833 //
1834 *HighlightMenu = FindHighLightMenuOption(FormData->HighLightedStatement);
1835 MenuOption = MENU_OPTION_FROM_LINK (*HighlightMenu);
1836 UpdateOptionSkipLines (MenuOption);
1837
1838 //
1839 // Make the current highlight menu at the bottom of the form to calculate the
1840 // top of screen menu.
1841 //
1842 if (MenuOption->Skip >= BottomRow - TopRow) {
1843 *TopOfScreen = *HighlightMenu;
1844 TmpValue = 0;
1845 } else {
1846 *TopOfScreen = FindTopOfScreenMenu(*HighlightMenu, BottomRow - TopRow - MenuOption->Skip, &TmpValue);
1847 }
1848
1849 *SkipValue = TmpValue;
1850 }
1851 AdjustDateAndTimePosition(TRUE, TopOfScreen);
1852 } else {
1853 //
1854 // If not has input highlight statement, just return the first one in this form.
1855 //
1856 *TopOfScreen = gMenuOption.ForwardLink;
1857 *HighlightMenu = gMenuOption.ForwardLink;
1858 if (!IsListEmpty (&gMenuOption)) {
1859 MoveToNextStatement (FALSE, HighlightMenu, BottomRow - TopRow, TRUE);
1860 }
1861 *SkipValue = 0;
1862 }
1863 }
1864
1865 /**
1866 Record the highlight menu and top of screen menu info.
1867
1868 @param Highlight The menu opton which is highlight.
1869 @param TopOfScreen The menu opton which is at the top of the form.
1870 @param SkipValue The skip line info for the top of screen menu.
1871
1872 **/
1873 VOID
1874 UpdateHighlightMenuInfo (
1875 IN LIST_ENTRY *Highlight,
1876 IN LIST_ENTRY *TopOfScreen,
1877 IN UINTN SkipValue
1878 )
1879 {
1880 UI_MENU_OPTION *MenuOption;
1881 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
1882
1883 gHighligthMenuInfo.HiiHandle = gFormData->HiiHandle;
1884 gHighligthMenuInfo.FormId = gFormData->FormId;
1885 gHighligthMenuInfo.SkipValue = (UINT16)SkipValue;
1886
1887 if (!IsListEmpty (&gMenuOption)) {
1888 MenuOption = MENU_OPTION_FROM_LINK (Highlight);
1889 Statement = MenuOption->ThisTag;
1890
1891 gUserInput->SelectedStatement = Statement;
1892
1893 gHighligthMenuInfo.HLTSequence = MenuOption->Sequence;
1894 gHighligthMenuInfo.HLTQuestionId = GetQuestionIdInfo(Statement->OpCode);
1895 if (gHighligthMenuInfo.HLTQuestionId == 0) {
1896 //
1897 // if question id == 0, save the opcode buffer..
1898 //
1899 if (gHighligthMenuInfo.HLTOpCode != NULL) {
1900 FreePool (gHighligthMenuInfo.HLTOpCode);
1901 }
1902 gHighligthMenuInfo.HLTOpCode = AllocateCopyPool (Statement->OpCode->Length, Statement->OpCode);
1903 ASSERT (gHighligthMenuInfo.HLTOpCode != NULL);
1904
1905 gHighligthMenuInfo.HLTIndex = GetIndexInfoForOpcode(Statement->OpCode);
1906 }
1907
1908 MenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
1909 Statement = MenuOption->ThisTag;
1910
1911 gHighligthMenuInfo.TOSQuestionId = GetQuestionIdInfo(Statement->OpCode);
1912 if (gHighligthMenuInfo.TOSQuestionId == 0) {
1913 //
1914 // if question id == 0, save the opcode buffer..
1915 //
1916 if (gHighligthMenuInfo.TOSOpCode != NULL) {
1917 FreePool (gHighligthMenuInfo.TOSOpCode);
1918 }
1919 gHighligthMenuInfo.TOSOpCode = AllocateCopyPool (Statement->OpCode->Length, Statement->OpCode);
1920 ASSERT (gHighligthMenuInfo.TOSOpCode != NULL);
1921
1922 gHighligthMenuInfo.TOSIndex = GetIndexInfoForOpcode(Statement->OpCode);
1923 }
1924 } else {
1925 gUserInput->SelectedStatement = NULL;
1926
1927 gHighligthMenuInfo.HLTSequence = 0;
1928 gHighligthMenuInfo.HLTQuestionId = 0;
1929 if (gHighligthMenuInfo.HLTOpCode != NULL) {
1930 FreePool (gHighligthMenuInfo.HLTOpCode);
1931 }
1932 gHighligthMenuInfo.HLTOpCode = NULL;
1933 gHighligthMenuInfo.HLTIndex = 0;
1934
1935 gHighligthMenuInfo.TOSQuestionId = 0;
1936 if (gHighligthMenuInfo.TOSOpCode != NULL) {
1937 FreePool (gHighligthMenuInfo.TOSOpCode);
1938 }
1939 gHighligthMenuInfo.TOSOpCode = NULL;
1940 gHighligthMenuInfo.TOSIndex = 0;
1941 }
1942 }
1943
1944 /**
1945 Update attribut for this menu.
1946
1947 @param MenuOption The menu opton which this attribut used to.
1948 @param Highlight Whether this menu will be highlight.
1949
1950 **/
1951 VOID
1952 SetDisplayAttribute (
1953 IN UI_MENU_OPTION *MenuOption,
1954 IN BOOLEAN Highlight
1955 )
1956 {
1957 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
1958
1959 Statement = MenuOption->ThisTag;
1960
1961 if (Highlight) {
1962 gST->ConOut->SetAttribute (gST->ConOut, GetHighlightTextColor ());
1963 return;
1964 }
1965
1966 if (MenuOption->GrayOut) {
1967 gST->ConOut->SetAttribute (gST->ConOut, GetGrayedTextColor ());
1968 } else {
1969 if (Statement->OpCode->OpCode == EFI_IFR_SUBTITLE_OP) {
1970 gST->ConOut->SetAttribute (gST->ConOut, GetSubTitleTextColor ());
1971 } else {
1972 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
1973 }
1974 }
1975 }
1976
1977 /**
1978 Print string for this menu option.
1979
1980 @param MenuOption The menu opton which this attribut used to.
1981 @param Col The column that this string will be print at.
1982 @param Row The row that this string will be print at.
1983 @param String The string which need to print.
1984 @param Width The width need to print, if string is less than the
1985 width, the block space will be used.
1986 @param Highlight Whether this menu will be highlight.
1987
1988 **/
1989 VOID
1990 DisplayMenuString (
1991 IN UI_MENU_OPTION *MenuOption,
1992 IN UINTN Col,
1993 IN UINTN Row,
1994 IN CHAR16 *String,
1995 IN UINTN Width,
1996 IN BOOLEAN Highlight
1997 )
1998 {
1999 UINTN Length;
2000
2001 //
2002 // Print string with normal color.
2003 //
2004 if (!Highlight) {
2005 PrintStringAtWithWidth (Col, Row, String, Width);
2006 return;
2007 }
2008
2009 //
2010 // Print the highlight menu string.
2011 // First print the highlight string.
2012 //
2013 SetDisplayAttribute(MenuOption, TRUE);
2014 Length = PrintStringAt (Col, Row, String);
2015
2016 //
2017 // Second, clean the empty after the string.
2018 //
2019 SetDisplayAttribute(MenuOption, FALSE);
2020 PrintStringAtWithWidth (Col + Length, Row, L"", Width - Length);
2021 }
2022
2023 /**
2024 Check whether this menu can has option string.
2025
2026 @param MenuOption The menu opton which this attribut used to.
2027
2028 @retval TRUE This menu option can have option string.
2029 @retval FALSE This menu option can't have option string.
2030
2031 **/
2032 BOOLEAN
2033 HasOptionString (
2034 IN UI_MENU_OPTION *MenuOption
2035 )
2036 {
2037 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
2038 CHAR16 *String;
2039 UINTN Size;
2040 EFI_IFR_TEXT *TestOp;
2041
2042 Size = 0;
2043 Statement = MenuOption->ThisTag;
2044
2045 //
2046 // See if the second text parameter is really NULL
2047 //
2048 if (Statement->OpCode->OpCode == EFI_IFR_TEXT_OP) {
2049 TestOp = (EFI_IFR_TEXT *) Statement->OpCode;
2050 if (TestOp->TextTwo != 0) {
2051 String = GetToken (TestOp->TextTwo, gFormData->HiiHandle);
2052 Size = StrLen (String);
2053 FreePool (String);
2054 }
2055 }
2056
2057 if ((Statement->OpCode->OpCode == EFI_IFR_SUBTITLE_OP) ||
2058 (Statement->OpCode->OpCode == EFI_IFR_REF_OP) ||
2059 (Statement->OpCode->OpCode == EFI_IFR_PASSWORD_OP) ||
2060 (Statement->OpCode->OpCode == EFI_IFR_ACTION_OP) ||
2061 (Statement->OpCode->OpCode == EFI_IFR_RESET_BUTTON_OP) ||
2062 //
2063 // Allow a wide display if text op-code and no secondary text op-code
2064 //
2065 ((Statement->OpCode->OpCode == EFI_IFR_TEXT_OP) && (Size == 0))
2066 ) {
2067
2068 return FALSE;
2069 }
2070
2071 return TRUE;
2072 }
2073
2074
2075 /**
2076 Print string for this menu option.
2077
2078 @param MenuOption The menu opton which this attribut used to.
2079 @param SkipWidth The skip width between the left to the start of the prompt.
2080 @param BeginCol The begin column for one menu.
2081 @param SkipLine The skip line for this menu.
2082 @param BottomRow The bottom row for this form.
2083 @param Highlight Whether this menu will be highlight.
2084 @param UpdateCol Whether need to update the column info for Date/Time.
2085
2086 @retval EFI_SUCESSS Process the user selection success.
2087
2088 **/
2089 EFI_STATUS
2090 DisplayOneMenu (
2091 IN UI_MENU_OPTION *MenuOption,
2092 IN UINTN SkipWidth,
2093 IN UINTN BeginCol,
2094 IN UINTN SkipLine,
2095 IN UINTN BottomRow,
2096 IN BOOLEAN Highlight,
2097 IN BOOLEAN UpdateCol
2098 )
2099 {
2100 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
2101 UINTN Index;
2102 UINT16 Width;
2103 UINT16 PromptWidth;
2104 CHAR16 *StringPtr;
2105 CHAR16 *OptionString;
2106 CHAR16 *OutputString;
2107 UINT16 GlyphWidth;
2108 UINTN Temp;
2109 UINTN Temp2;
2110 UINTN Temp3;
2111 EFI_STATUS Status;
2112 UINTN Row;
2113 UINTN Col;
2114 UINTN PromptLineNum;
2115 UINTN OptionLineNum;
2116 CHAR16 AdjustValue;
2117 UINTN MaxRow;
2118
2119 Statement = MenuOption->ThisTag;
2120 Temp = SkipLine;
2121 Temp2 = SkipLine;
2122 Temp3 = SkipLine;
2123 AdjustValue = 0;
2124 PromptLineNum = 0;
2125 OptionLineNum = 0;
2126 MaxRow = 0;
2127
2128 //
2129 // Set default color.
2130 //
2131 SetDisplayAttribute (MenuOption, FALSE);
2132
2133 //
2134 // 1. Paint the option string.
2135 //
2136 Status = ProcessOptions (MenuOption, FALSE, &OptionString, FALSE);
2137 if (EFI_ERROR (Status)) {
2138 return Status;
2139 }
2140
2141 if (OptionString != NULL) {
2142 if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP || Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {
2143 //
2144 // Adjust option string for date/time opcode.
2145 //
2146 ProcessStringForDateTime(MenuOption, OptionString, UpdateCol);
2147 }
2148
2149 Width = (UINT16) gOptionBlockWidth - 1;
2150 Row = MenuOption->Row;
2151 GlyphWidth = 1;
2152 OptionLineNum = 0;
2153
2154 for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2155 if (((Temp2 == 0)) && (Row <= BottomRow)) {
2156 if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP || Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {
2157 //
2158 // For date/time question, it has three menu options for this qustion.
2159 // The first/second menu options with the skip value is 0. the last one
2160 // with skip value is 1.
2161 //
2162 if (MenuOption->Skip != 0) {
2163 //
2164 // For date/ time, print the last past (year for date and second for time)
2165 // - 7 means skip [##/##/ for date and [##:##: for time.
2166 //
2167 DisplayMenuString (MenuOption,MenuOption->OptCol, Row, OutputString, Width + 1 - 7, Highlight);
2168 } else {
2169 //
2170 // For date/ time, print the first and second past (year for date and second for time)
2171 // The OutputString has a NARROW_CHAR or WIDE_CHAR at the begin of the string,
2172 // so need to - 1 to remove it, otherwise, it will clean 1 extr char follow it.
2173 DisplayMenuString (MenuOption, MenuOption->OptCol, Row, OutputString, StrLen (OutputString) - 1, Highlight);
2174 }
2175 } else {
2176 DisplayMenuString (MenuOption, MenuOption->OptCol, Row, OutputString, Width + 1, Highlight);
2177 }
2178 OptionLineNum++;
2179 }
2180
2181 //
2182 // If there is more string to process print on the next row and increment the Skip value
2183 //
2184 if (StrLen (&OptionString[Index]) != 0) {
2185 if (Temp2 == 0) {
2186 Row++;
2187 //
2188 // Since the Number of lines for this menu entry may or may not be reflected accurately
2189 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do
2190 // some testing to ensure we are keeping this in-sync.
2191 //
2192 // If the difference in rows is greater than or equal to the skip value, increase the skip value
2193 //
2194 if ((Row - MenuOption->Row) >= MenuOption->Skip) {
2195 MenuOption->Skip++;
2196 }
2197 }
2198 }
2199
2200 FreePool (OutputString);
2201 if (Temp2 != 0) {
2202 Temp2--;
2203 }
2204 }
2205
2206 Highlight = FALSE;
2207
2208 FreePool (OptionString);
2209 }
2210
2211 //
2212 // 2. Paint the description.
2213 //
2214 PromptWidth = GetWidth (MenuOption, &AdjustValue);
2215 Row = MenuOption->Row;
2216 GlyphWidth = 1;
2217 PromptLineNum = 0;
2218
2219 if (MenuOption->Description == NULL || MenuOption->Description[0] == '\0') {
2220 PrintStringAtWithWidth (BeginCol, Row, L"", PromptWidth + AdjustValue + SkipWidth);
2221 PromptLineNum++;
2222 } else {
2223 for (Index = 0; GetLineByWidth (MenuOption->Description, PromptWidth, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2224 if ((Temp == 0) && (Row <= BottomRow)) {
2225 //
2226 // 1.Clean the start LEFT_SKIPPED_COLUMNS
2227 //
2228 PrintStringAtWithWidth (BeginCol, Row, L"", SkipWidth);
2229
2230 if (Statement->OpCode->OpCode == EFI_IFR_REF_OP && MenuOption->Col >= 2) {
2231 //
2232 // Print Arrow for Goto button.
2233 //
2234 PrintCharAt (
2235 MenuOption->Col - 2,
2236 Row,
2237 GEOMETRICSHAPE_RIGHT_TRIANGLE
2238 );
2239 }
2240 DisplayMenuString (MenuOption, MenuOption->Col, Row, OutputString, PromptWidth + AdjustValue, Highlight);
2241 PromptLineNum ++;
2242 }
2243 //
2244 // If there is more string to process print on the next row and increment the Skip value
2245 //
2246 if (StrLen (&MenuOption->Description[Index]) != 0) {
2247 if (Temp == 0) {
2248 Row++;
2249 }
2250 }
2251
2252 FreePool (OutputString);
2253 if (Temp != 0) {
2254 Temp--;
2255 }
2256 }
2257
2258 Highlight = FALSE;
2259 }
2260
2261
2262 //
2263 // 3. If this is a text op with secondary text information
2264 //
2265 if ((Statement->OpCode->OpCode == EFI_IFR_TEXT_OP) && (((EFI_IFR_TEXT*)Statement->OpCode)->TextTwo != 0)) {
2266 StringPtr = GetToken (((EFI_IFR_TEXT*)Statement->OpCode)->TextTwo, gFormData->HiiHandle);
2267
2268 Width = (UINT16) gOptionBlockWidth - 1;
2269 Row = MenuOption->Row;
2270 GlyphWidth = 1;
2271 OptionLineNum = 0;
2272
2273 for (Index = 0; GetLineByWidth (StringPtr, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2274 if ((Temp3 == 0) && (Row <= BottomRow)) {
2275 DisplayMenuString (MenuOption, MenuOption->OptCol, Row, OutputString, Width + 1, Highlight);
2276 OptionLineNum++;
2277 }
2278 //
2279 // If there is more string to process print on the next row and increment the Skip value
2280 //
2281 if (StrLen (&StringPtr[Index]) != 0) {
2282 if (Temp3 == 0) {
2283 Row++;
2284 //
2285 // If the rows for text two is greater than or equal to the skip value, increase the skip value
2286 //
2287 if ((Row - MenuOption->Row) >= MenuOption->Skip) {
2288 MenuOption->Skip++;
2289 }
2290 }
2291 }
2292
2293 FreePool (OutputString);
2294 if (Temp3 != 0) {
2295 Temp3--;
2296 }
2297 }
2298
2299 FreePool (StringPtr);
2300 }
2301
2302 //
2303 // 4.Line number for Option string and prompt string are not equal.
2304 // Clean the column whose line number is less.
2305 //
2306 if (HasOptionString(MenuOption) && (OptionLineNum != PromptLineNum)) {
2307 Col = OptionLineNum < PromptLineNum ? MenuOption->OptCol : BeginCol;
2308 Row = (OptionLineNum < PromptLineNum ? OptionLineNum : PromptLineNum) + MenuOption->Row;
2309 Width = (UINT16) (OptionLineNum < PromptLineNum ? gOptionBlockWidth : PromptWidth + AdjustValue + SkipWidth);
2310 MaxRow = (OptionLineNum < PromptLineNum ? PromptLineNum : OptionLineNum) + MenuOption->Row - 1;
2311
2312 while (Row <= MaxRow) {
2313 DisplayMenuString (MenuOption, Col, Row++, L"", Width, FALSE);
2314 }
2315 }
2316
2317 return EFI_SUCCESS;
2318 }
2319
2320 /**
2321 Display menu and wait for user to select one menu option, then return it.
2322 If AutoBoot is enabled, then if user doesn't select any option,
2323 after period of time, it will automatically return the first menu option.
2324
2325 @param FormData The current form data info.
2326
2327 @retval EFI_SUCESSS Process the user selection success.
2328 @retval EFI_NOT_FOUND Process option string for orderedlist/Oneof fail.
2329
2330 **/
2331 EFI_STATUS
2332 UiDisplayMenu (
2333 IN FORM_DISPLAY_ENGINE_FORM *FormData
2334 )
2335 {
2336 UINTN SkipValue;
2337 INTN Difference;
2338 UINTN DistanceValue;
2339 UINTN Row;
2340 UINTN Col;
2341 UINTN Temp;
2342 UINTN Temp2;
2343 UINTN TopRow;
2344 UINTN BottomRow;
2345 UINTN Index;
2346 CHAR16 *StringPtr;
2347 CHAR16 *OptionString;
2348 CHAR16 *HelpString;
2349 CHAR16 *HelpHeaderString;
2350 CHAR16 *HelpBottomString;
2351 BOOLEAN NewLine;
2352 BOOLEAN Repaint;
2353 BOOLEAN UpArrow;
2354 BOOLEAN DownArrow;
2355 EFI_STATUS Status;
2356 EFI_INPUT_KEY Key;
2357 LIST_ENTRY *Link;
2358 LIST_ENTRY *NewPos;
2359 LIST_ENTRY *TopOfScreen;
2360 LIST_ENTRY *SavedListEntry;
2361 UI_MENU_OPTION *MenuOption;
2362 UI_MENU_OPTION *NextMenuOption;
2363 UI_MENU_OPTION *SavedMenuOption;
2364 UI_CONTROL_FLAG ControlFlag;
2365 UI_SCREEN_OPERATION ScreenOperation;
2366 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
2367 BROWSER_HOT_KEY *HotKey;
2368 UINTN HelpPageIndex;
2369 UINTN HelpPageCount;
2370 UINTN RowCount;
2371 UINTN HelpLine;
2372 UINTN HelpHeaderLine;
2373 UINTN HelpBottomLine;
2374 BOOLEAN MultiHelpPage;
2375 UINT16 EachLineWidth;
2376 UINT16 HeaderLineWidth;
2377 UINT16 BottomLineWidth;
2378 EFI_STRING_ID HelpInfo;
2379 UI_EVENT_TYPE EventType;
2380 BOOLEAN SkipHighLight;
2381
2382 EventType = UIEventNone;
2383 Status = EFI_SUCCESS;
2384 HelpString = NULL;
2385 HelpHeaderString = NULL;
2386 HelpBottomString = NULL;
2387 OptionString = NULL;
2388 ScreenOperation = UiNoOperation;
2389 NewLine = TRUE;
2390 HelpPageCount = 0;
2391 HelpLine = 0;
2392 RowCount = 0;
2393 HelpBottomLine = 0;
2394 HelpHeaderLine = 0;
2395 HelpPageIndex = 0;
2396 MultiHelpPage = FALSE;
2397 EachLineWidth = 0;
2398 HeaderLineWidth = 0;
2399 BottomLineWidth = 0;
2400 UpArrow = FALSE;
2401 DownArrow = FALSE;
2402 SkipValue = 0;
2403 SkipHighLight = FALSE;
2404
2405 NextMenuOption = NULL;
2406 SavedMenuOption = NULL;
2407 HotKey = NULL;
2408 Repaint = TRUE;
2409 MenuOption = NULL;
2410 gModalSkipColumn = (CHAR16) (gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn) / 6;
2411
2412 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
2413
2414 TopRow = gStatementDimensions.TopRow + SCROLL_ARROW_HEIGHT;
2415 BottomRow = gStatementDimensions.BottomRow - SCROLL_ARROW_HEIGHT - 1;
2416
2417 Row = TopRow;
2418 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2419 Col = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS + gModalSkipColumn;
2420 } else {
2421 Col = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS;
2422 }
2423
2424 FindTopMenu(FormData, &TopOfScreen, &NewPos, &SkipValue);
2425 if (!IsListEmpty (&gMenuOption)) {
2426 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);
2427 gUserInput->SelectedStatement = NextMenuOption->ThisTag;
2428 }
2429
2430 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
2431
2432 ControlFlag = CfInitialization;
2433 while (TRUE) {
2434 switch (ControlFlag) {
2435 case CfInitialization:
2436 if ((gOldFormEntry.HiiHandle != FormData->HiiHandle) ||
2437 (!CompareGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid))) {
2438 //
2439 // Clear Statement range if different formset is painted.
2440 //
2441 ClearLines (
2442 gStatementDimensions.LeftColumn,
2443 gStatementDimensions.RightColumn,
2444 TopRow - SCROLL_ARROW_HEIGHT,
2445 BottomRow + SCROLL_ARROW_HEIGHT,
2446 GetFieldTextColor ()
2447 );
2448
2449 }
2450 ControlFlag = CfRepaint;
2451 break;
2452
2453 case CfRepaint:
2454 ControlFlag = CfRefreshHighLight;
2455
2456 if (Repaint) {
2457 //
2458 // Display menu
2459 //
2460 DownArrow = FALSE;
2461 UpArrow = FALSE;
2462 Row = TopRow;
2463
2464 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2465
2466 //
2467 // 1. Check whether need to print the arrow up.
2468 //
2469 if (!ValueIsScroll (TRUE, TopOfScreen)) {
2470 UpArrow = TRUE;
2471 }
2472
2473 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2474 PrintStringAtWithWidth(gStatementDimensions.LeftColumn + gModalSkipColumn, TopRow - 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * gModalSkipColumn);
2475 } else {
2476 PrintStringAtWithWidth(gStatementDimensions.LeftColumn, TopRow - 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn);
2477 }
2478 if (UpArrow) {
2479 gST->ConOut->SetAttribute (gST->ConOut, GetArrowColor ());
2480 PrintCharAt (
2481 gStatementDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,
2482 TopRow - SCROLL_ARROW_HEIGHT,
2483 ARROW_UP
2484 );
2485 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2486 }
2487
2488 //
2489 // 2.Paint the menu.
2490 //
2491 for (Link = TopOfScreen; Link != &gMenuOption; Link = Link->ForwardLink) {
2492 MenuOption = MENU_OPTION_FROM_LINK (Link);
2493 MenuOption->Row = Row;
2494 MenuOption->Col = Col;
2495 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2496 MenuOption->OptCol = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS + gPromptBlockWidth + gModalSkipColumn;
2497 } else {
2498 MenuOption->OptCol = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS + gPromptBlockWidth;
2499 }
2500
2501 if (MenuOption->NestInStatement) {
2502 MenuOption->Col += SUBTITLE_INDENT;
2503 }
2504
2505 //
2506 // Save the highlight menu, will be used in CfRefreshHighLight case.
2507 //
2508 if (Link == NewPos) {
2509 SavedMenuOption = MenuOption;
2510 SkipHighLight = TRUE;
2511 }
2512
2513 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2514 Status = DisplayOneMenu (MenuOption,
2515 MenuOption->Col - gStatementDimensions.LeftColumn,
2516 gStatementDimensions.LeftColumn + gModalSkipColumn,
2517 Link == TopOfScreen ? SkipValue : 0,
2518 BottomRow,
2519 (BOOLEAN) ((Link == NewPos) && IsSelectable(MenuOption)),
2520 TRUE
2521 );
2522 } else {
2523 Status = DisplayOneMenu (MenuOption,
2524 MenuOption->Col - gStatementDimensions.LeftColumn,
2525 gStatementDimensions.LeftColumn,
2526 Link == TopOfScreen ? SkipValue : 0,
2527 BottomRow,
2528 (BOOLEAN) ((Link == NewPos) && IsSelectable(MenuOption)),
2529 TRUE
2530 );
2531 }
2532
2533 if (EFI_ERROR (Status)) {
2534 if (gMisMatch) {
2535 return EFI_SUCCESS;
2536 } else {
2537 return Status;
2538 }
2539 }
2540 //
2541 // 3. Update the row info which will be used by next menu.
2542 //
2543 if (Link == TopOfScreen) {
2544 Row += MenuOption->Skip - SkipValue;
2545 } else {
2546 Row += MenuOption->Skip;
2547 }
2548
2549 if (Row > BottomRow) {
2550 if (!ValueIsScroll (FALSE, Link)) {
2551 DownArrow = TRUE;
2552 }
2553
2554 Row = BottomRow + 1;
2555 break;
2556 }
2557 }
2558
2559 //
2560 // 3. Menus in this form may not cover all form, clean the remain field.
2561 //
2562 while (Row <= BottomRow) {
2563 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2564 PrintStringAtWithWidth(gStatementDimensions.LeftColumn + gModalSkipColumn, Row++, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * gModalSkipColumn);
2565 } else {
2566 PrintStringAtWithWidth(gStatementDimensions.LeftColumn, Row++, L"", gStatementDimensions.RightColumn - gHelpBlockWidth - gStatementDimensions.LeftColumn);
2567 }
2568 }
2569
2570 //
2571 // 4. Print the down arrow row.
2572 //
2573 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2574 PrintStringAtWithWidth(gStatementDimensions.LeftColumn + gModalSkipColumn, BottomRow + 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * + gModalSkipColumn);
2575 } else {
2576 PrintStringAtWithWidth(gStatementDimensions.LeftColumn, BottomRow + 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn);
2577 }
2578 if (DownArrow) {
2579 gST->ConOut->SetAttribute (gST->ConOut, GetArrowColor ());
2580 PrintCharAt (
2581 gStatementDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,
2582 BottomRow + SCROLL_ARROW_HEIGHT,
2583 ARROW_DOWN
2584 );
2585 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2586 }
2587
2588 MenuOption = NULL;
2589 }
2590 break;
2591
2592 case CfRefreshHighLight:
2593
2594 //
2595 // MenuOption: Last menu option that need to remove hilight
2596 // MenuOption is set to NULL in Repaint
2597 // NewPos: Current menu option that need to hilight
2598 //
2599 ControlFlag = CfUpdateHelpString;
2600
2601 UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);
2602
2603 if (SkipHighLight) {
2604 SkipHighLight = FALSE;
2605 MenuOption = SavedMenuOption;
2606 RefreshKeyHelp(gFormData, SavedMenuOption->ThisTag, FALSE);
2607 break;
2608 }
2609
2610 if (IsListEmpty (&gMenuOption)) {
2611 //
2612 // No menu option, just update the hotkey filed.
2613 //
2614 RefreshKeyHelp(gFormData, NULL, FALSE);
2615 break;
2616 }
2617
2618 if (MenuOption != NULL && TopOfScreen == &MenuOption->Link) {
2619 Temp = SkipValue;
2620 } else {
2621 Temp = 0;
2622 }
2623 if (NewPos == TopOfScreen) {
2624 Temp2 = SkipValue;
2625 } else {
2626 Temp2 = 0;
2627 }
2628
2629 if (NewPos != NULL && (MenuOption == NULL || NewPos != &MenuOption->Link)) {
2630 if (MenuOption != NULL) {
2631 //
2632 // Remove the old highlight menu.
2633 //
2634 Status = DisplayOneMenu (MenuOption,
2635 MenuOption->Col - gStatementDimensions.LeftColumn,
2636 gStatementDimensions.LeftColumn,
2637 Temp,
2638 BottomRow,
2639 FALSE,
2640 FALSE
2641 );
2642 }
2643
2644 //
2645 // This is the current selected statement
2646 //
2647 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
2648 RefreshKeyHelp(gFormData, MenuOption->ThisTag, FALSE);
2649
2650 if (!IsSelectable (MenuOption)) {
2651 break;
2652 }
2653
2654 Status = DisplayOneMenu (MenuOption,
2655 MenuOption->Col - gStatementDimensions.LeftColumn,
2656 gStatementDimensions.LeftColumn,
2657 Temp2,
2658 BottomRow,
2659 TRUE,
2660 FALSE
2661 );
2662 }
2663 break;
2664
2665 case CfUpdateHelpString:
2666 ControlFlag = CfPrepareToReadKey;
2667 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2668 break;
2669 }
2670
2671 //
2672 // NewLine means only update highlight menu (remove old highlight and highlith
2673 // the new one), not need to full repain the form.
2674 //
2675 if (Repaint || NewLine) {
2676 if (IsListEmpty (&gMenuOption)) {
2677 //
2678 // Don't print anything if no mwnu option.
2679 //
2680 StringPtr = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2681 } else {
2682 //
2683 // Don't print anything if it is a NULL help token
2684 //
2685 ASSERT(MenuOption != NULL);
2686 HelpInfo = ((EFI_IFR_STATEMENT_HEADER *) ((CHAR8 *)MenuOption->ThisTag->OpCode + sizeof (EFI_IFR_OP_HEADER)))->Help;
2687 if (HelpInfo == 0 || !IsSelectable (MenuOption)) {
2688 StringPtr = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2689 } else {
2690 StringPtr = GetToken (HelpInfo, gFormData->HiiHandle);
2691 }
2692 }
2693
2694 RowCount = BottomRow - TopRow + 1;
2695 HelpPageIndex = 0;
2696 //
2697 // 1.Calculate how many line the help string need to print.
2698 //
2699 if (HelpString != NULL) {
2700 FreePool (HelpString);
2701 HelpString = NULL;
2702 }
2703 HelpLine = ProcessHelpString (StringPtr, &HelpString, &EachLineWidth, RowCount);
2704 FreePool (StringPtr);
2705
2706 if (HelpLine > RowCount) {
2707 MultiHelpPage = TRUE;
2708 StringPtr = GetToken (STRING_TOKEN(ADJUST_HELP_PAGE_UP), gHiiHandle);
2709 if (HelpHeaderString != NULL) {
2710 FreePool (HelpHeaderString);
2711 HelpHeaderString = NULL;
2712 }
2713 HelpHeaderLine = ProcessHelpString (StringPtr, &HelpHeaderString, &HeaderLineWidth, 0);
2714 FreePool (StringPtr);
2715 StringPtr = GetToken (STRING_TOKEN(ADJUST_HELP_PAGE_DOWN), gHiiHandle);
2716 if (HelpBottomString != NULL) {
2717 FreePool (HelpBottomString);
2718 HelpBottomString = NULL;
2719 }
2720 HelpBottomLine = ProcessHelpString (StringPtr, &HelpBottomString, &BottomLineWidth, 0);
2721 FreePool (StringPtr);
2722 //
2723 // Calculate the help page count.
2724 //
2725 if (HelpLine > 2 * RowCount - 2) {
2726 HelpPageCount = (HelpLine - RowCount + 1) / (RowCount - 2) + 1;
2727 if ((HelpLine - RowCount + 1) % (RowCount - 2) > 1) {
2728 HelpPageCount += 1;
2729 }
2730 } else {
2731 HelpPageCount = 2;
2732 }
2733 } else {
2734 MultiHelpPage = FALSE;
2735 }
2736 }
2737
2738 //
2739 // Check whether need to show the 'More(U/u)' at the begin.
2740 // Base on current direct info, here shows aligned to the right side of the column.
2741 // If the direction is multi line and aligned to right side may have problem, so
2742 // add ASSERT code here.
2743 //
2744 if (HelpPageIndex > 0) {
2745 gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
2746 for (Index = 0; Index < HelpHeaderLine; Index++) {
2747 ASSERT (HelpHeaderLine == 1);
2748 ASSERT (GetStringWidth (HelpHeaderString) / 2 < (UINTN) (gHelpBlockWidth - 1));
2749 PrintStringAtWithWidth (
2750 gStatementDimensions.RightColumn - gHelpBlockWidth,
2751 Index + TopRow,
2752 gEmptyString,
2753 gHelpBlockWidth
2754 );
2755 PrintStringAt (
2756 gStatementDimensions.RightColumn - GetStringWidth (HelpHeaderString) / 2 - 1,
2757 Index + TopRow,
2758 &HelpHeaderString[Index * HeaderLineWidth]
2759 );
2760 }
2761 }
2762
2763 gST->ConOut->SetAttribute (gST->ConOut, GetHelpTextColor ());
2764 //
2765 // Print the help string info.
2766 //
2767 if (!MultiHelpPage) {
2768 for (Index = 0; Index < HelpLine; Index++) {
2769 PrintStringAtWithWidth (
2770 gStatementDimensions.RightColumn - gHelpBlockWidth,
2771 Index + TopRow,
2772 &HelpString[Index * EachLineWidth],
2773 gHelpBlockWidth
2774 );
2775 }
2776 for (; Index < RowCount; Index ++) {
2777 PrintStringAtWithWidth (
2778 gStatementDimensions.RightColumn - gHelpBlockWidth,
2779 Index + TopRow,
2780 gEmptyString,
2781 gHelpBlockWidth
2782 );
2783 }
2784 gST->ConOut->SetCursorPosition(gST->ConOut, gStatementDimensions.RightColumn-1, BottomRow);
2785 } else {
2786 if (HelpPageIndex == 0) {
2787 for (Index = 0; Index < RowCount - HelpBottomLine; Index++) {
2788 PrintStringAtWithWidth (
2789 gStatementDimensions.RightColumn - gHelpBlockWidth,
2790 Index + TopRow,
2791 &HelpString[Index * EachLineWidth],
2792 gHelpBlockWidth
2793 );
2794 }
2795 } else {
2796 for (Index = 0; (Index < RowCount - HelpBottomLine - HelpHeaderLine) &&
2797 (Index + HelpPageIndex * (RowCount - 2) + 1 < HelpLine); Index++) {
2798 PrintStringAtWithWidth (
2799 gStatementDimensions.RightColumn - gHelpBlockWidth,
2800 Index + TopRow + HelpHeaderLine,
2801 &HelpString[(Index + HelpPageIndex * (RowCount - 2) + 1)* EachLineWidth],
2802 gHelpBlockWidth
2803 );
2804 }
2805 if (HelpPageIndex == HelpPageCount - 1) {
2806 for (; Index < RowCount - HelpHeaderLine; Index ++) {
2807 PrintStringAtWithWidth (
2808 gStatementDimensions.RightColumn - gHelpBlockWidth,
2809 Index + TopRow + HelpHeaderLine,
2810 gEmptyString,
2811 gHelpBlockWidth
2812 );
2813 }
2814 gST->ConOut->SetCursorPosition(gST->ConOut, gStatementDimensions.RightColumn-1, BottomRow);
2815 }
2816 }
2817 }
2818
2819 //
2820 // Check whether need to print the 'More(D/d)' at the bottom.
2821 // Base on current direct info, here shows aligned to the right side of the column.
2822 // If the direction is multi line and aligned to right side may have problem, so
2823 // add ASSERT code here.
2824 //
2825 if (HelpPageIndex < HelpPageCount - 1 && MultiHelpPage) {
2826 gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
2827 for (Index = 0; Index < HelpBottomLine; Index++) {
2828 ASSERT (HelpBottomLine == 1);
2829 ASSERT (GetStringWidth (HelpBottomString) / 2 < (UINTN) (gHelpBlockWidth - 1));
2830 PrintStringAtWithWidth (
2831 gStatementDimensions.RightColumn - gHelpBlockWidth,
2832 BottomRow + Index - HelpBottomLine + 1,
2833 gEmptyString,
2834 gHelpBlockWidth
2835 );
2836 PrintStringAt (
2837 gStatementDimensions.RightColumn - GetStringWidth (HelpBottomString) / 2 - 1,
2838 BottomRow + Index - HelpBottomLine + 1,
2839 &HelpBottomString[Index * BottomLineWidth]
2840 );
2841 }
2842 }
2843 //
2844 // Reset this flag every time we finish using it.
2845 //
2846 Repaint = FALSE;
2847 NewLine = FALSE;
2848 break;
2849
2850 case CfPrepareToReadKey:
2851 ControlFlag = CfReadKey;
2852 ScreenOperation = UiNoOperation;
2853 break;
2854
2855 case CfReadKey:
2856 ControlFlag = CfScreenOperation;
2857
2858 //
2859 // Wait for user's selection
2860 //
2861 while (TRUE) {
2862 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2863 if (!EFI_ERROR (Status)) {
2864 EventType = UIEventKey;
2865 break;
2866 }
2867
2868 //
2869 // If we encounter error, continue to read another key in.
2870 //
2871 if (Status != EFI_NOT_READY) {
2872 continue;
2873 }
2874
2875 EventType = UiWaitForEvent(gST->ConIn->WaitForKey);
2876 if (EventType == UIEventKey) {
2877 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2878 }
2879 break;
2880 }
2881
2882 if (EventType == UIEventDriver) {
2883 gMisMatch = TRUE;
2884 gUserInput->Action = BROWSER_ACTION_NONE;
2885 ControlFlag = CfExit;
2886 break;
2887 }
2888
2889 if (EventType == UIEventTimeOut) {
2890 gUserInput->Action = BROWSER_ACTION_FORM_EXIT;
2891 ControlFlag = CfExit;
2892 break;
2893 }
2894
2895 switch (Key.UnicodeChar) {
2896 case CHAR_CARRIAGE_RETURN:
2897 if(MenuOption == NULL || MenuOption->GrayOut || MenuOption->ReadOnly) {
2898 ControlFlag = CfReadKey;
2899 break;
2900 }
2901
2902 ScreenOperation = UiSelect;
2903 gDirection = 0;
2904 break;
2905
2906 //
2907 // We will push the adjustment of these numeric values directly to the input handler
2908 // NOTE: we won't handle manual input numeric
2909 //
2910 case '+':
2911 case '-':
2912 //
2913 // If the screen has no menu items, and the user didn't select UiReset
2914 // ignore the selection and go back to reading keys.
2915 //
2916 ASSERT(MenuOption != NULL);
2917 if(IsListEmpty (&gMenuOption) || MenuOption->GrayOut || MenuOption->ReadOnly) {
2918 ControlFlag = CfReadKey;
2919 break;
2920 }
2921
2922 Statement = MenuOption->ThisTag;
2923 if ((Statement->OpCode->OpCode == EFI_IFR_DATE_OP)
2924 || (Statement->OpCode->OpCode == EFI_IFR_TIME_OP)
2925 || ((Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP) && (GetFieldFromNum(Statement->OpCode) != 0))
2926 ){
2927 if (Key.UnicodeChar == '+') {
2928 gDirection = SCAN_RIGHT;
2929 } else {
2930 gDirection = SCAN_LEFT;
2931 }
2932
2933 Status = ProcessOptions (MenuOption, TRUE, &OptionString, TRUE);
2934 if (OptionString != NULL) {
2935 FreePool (OptionString);
2936 }
2937 if (EFI_ERROR (Status)) {
2938 //
2939 // Repaint to clear possible error prompt pop-up
2940 //
2941 Repaint = TRUE;
2942 NewLine = TRUE;
2943 } else {
2944 ControlFlag = CfExit;
2945 }
2946 }
2947 break;
2948
2949 case '^':
2950 ScreenOperation = UiUp;
2951 break;
2952
2953 case 'V':
2954 case 'v':
2955 ScreenOperation = UiDown;
2956 break;
2957
2958 case ' ':
2959 if(IsListEmpty (&gMenuOption)) {
2960 ControlFlag = CfReadKey;
2961 break;
2962 }
2963
2964 ASSERT(MenuOption != NULL);
2965 if (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut && !MenuOption->ReadOnly) {
2966 ScreenOperation = UiSelect;
2967 }
2968 break;
2969
2970 case 'D':
2971 case 'd':
2972 if (!MultiHelpPage) {
2973 ControlFlag = CfReadKey;
2974 break;
2975 }
2976 ControlFlag = CfUpdateHelpString;
2977 HelpPageIndex = HelpPageIndex < HelpPageCount - 1 ? HelpPageIndex + 1 : HelpPageCount - 1;
2978 break;
2979
2980 case 'U':
2981 case 'u':
2982 if (!MultiHelpPage) {
2983 ControlFlag = CfReadKey;
2984 break;
2985 }
2986 ControlFlag = CfUpdateHelpString;
2987 HelpPageIndex = HelpPageIndex > 0 ? HelpPageIndex - 1 : 0;
2988 break;
2989
2990 case CHAR_NULL:
2991 for (Index = 0; Index < mScanCodeNumber; Index++) {
2992 if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {
2993 ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;
2994 break;
2995 }
2996 }
2997
2998 if (((FormData->Attribute & HII_DISPLAY_MODAL) != 0) && (Key.ScanCode == SCAN_ESC || Index == mScanCodeNumber)) {
2999 //
3000 // ModalForm has no ESC key and Hot Key.
3001 //
3002 ControlFlag = CfReadKey;
3003 } else if (Index == mScanCodeNumber) {
3004 //
3005 // Check whether Key matches the registered hot key.
3006 //
3007 HotKey = NULL;
3008 HotKey = GetHotKeyFromRegisterList (&Key);
3009 if (HotKey != NULL) {
3010 ScreenOperation = UiHotKey;
3011 }
3012 }
3013 break;
3014 }
3015 break;
3016
3017 case CfScreenOperation:
3018 if ((ScreenOperation != UiReset) && (ScreenOperation != UiHotKey)) {
3019 //
3020 // If the screen has no menu items, and the user didn't select UiReset or UiHotKey
3021 // ignore the selection and go back to reading keys.
3022 //
3023 if (IsListEmpty (&gMenuOption)) {
3024 ControlFlag = CfReadKey;
3025 break;
3026 }
3027 }
3028
3029 for (Index = 0;
3030 Index < sizeof (gScreenOperationToControlFlag) / sizeof (gScreenOperationToControlFlag[0]);
3031 Index++
3032 ) {
3033 if (ScreenOperation == gScreenOperationToControlFlag[Index].ScreenOperation) {
3034 ControlFlag = gScreenOperationToControlFlag[Index].ControlFlag;
3035 break;
3036 }
3037 }
3038 break;
3039
3040 case CfUiSelect:
3041 ControlFlag = CfRepaint;
3042
3043 ASSERT(MenuOption != NULL);
3044 Statement = MenuOption->ThisTag;
3045 if (Statement->OpCode->OpCode == EFI_IFR_TEXT_OP) {
3046 break;
3047 }
3048
3049 switch (Statement->OpCode->OpCode) {
3050 case EFI_IFR_REF_OP:
3051 case EFI_IFR_ACTION_OP:
3052 case EFI_IFR_RESET_BUTTON_OP:
3053 ControlFlag = CfExit;
3054 break;
3055
3056 default:
3057 //
3058 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
3059 //
3060 RefreshKeyHelp (gFormData, Statement, TRUE);
3061 Status = ProcessOptions (MenuOption, TRUE, &OptionString, TRUE);
3062
3063 if (OptionString != NULL) {
3064 FreePool (OptionString);
3065 }
3066
3067 if (EFI_ERROR (Status)) {
3068 Repaint = TRUE;
3069 NewLine = TRUE;
3070 RefreshKeyHelp (gFormData, Statement, FALSE);
3071 break;
3072 } else {
3073 ControlFlag = CfExit;
3074 break;
3075 }
3076 }
3077 break;
3078
3079 case CfUiReset:
3080 //
3081 // We come here when someone press ESC
3082 // If the policy is not exit front page when user press ESC, process here.
3083 //
3084 if (!FormExitPolicy()) {
3085 Repaint = TRUE;
3086 NewLine = TRUE;
3087 ControlFlag = CfRepaint;
3088 break;
3089 }
3090
3091 gUserInput->Action = BROWSER_ACTION_FORM_EXIT;
3092 ControlFlag = CfExit;
3093 break;
3094
3095 case CfUiHotKey:
3096 ControlFlag = CfRepaint;
3097
3098 ASSERT (HotKey != NULL);
3099 gUserInput->Action = HotKey->Action;
3100 ControlFlag = CfExit;
3101 break;
3102
3103 case CfUiLeft:
3104 ControlFlag = CfRepaint;
3105 ASSERT(MenuOption != NULL);
3106 if ((MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_TIME_OP)) {
3107 if (MenuOption->Sequence != 0) {
3108 //
3109 // In the middle or tail of the Date/Time op-code set, go left.
3110 //
3111 ASSERT(NewPos != NULL);
3112 NewPos = NewPos->BackLink;
3113 }
3114 }
3115 break;
3116
3117 case CfUiRight:
3118 ControlFlag = CfRepaint;
3119 ASSERT(MenuOption != NULL);
3120 if ((MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_TIME_OP)) {
3121 if (MenuOption->Sequence != 2) {
3122 //
3123 // In the middle or tail of the Date/Time op-code set, go left.
3124 //
3125 ASSERT(NewPos != NULL);
3126 NewPos = NewPos->ForwardLink;
3127 }
3128 }
3129 break;
3130
3131 case CfUiUp:
3132 ControlFlag = CfRepaint;
3133 NewLine = TRUE;
3134
3135 SavedListEntry = NewPos;
3136 ASSERT(NewPos != NULL);
3137
3138 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
3139 ASSERT (MenuOption != NULL);
3140
3141 //
3142 // Adjust Date/Time position before we advance forward.
3143 //
3144 AdjustDateAndTimePosition (TRUE, &NewPos);
3145
3146 NewPos = NewPos->BackLink;
3147 //
3148 // Find next selectable menu or the first menu beyond current form.
3149 //
3150 Difference = MoveToNextStatement (TRUE, &NewPos, MenuOption->Row - TopRow, FALSE);
3151 if (Difference < 0) {
3152 //
3153 // We hit the begining MenuOption that can be focused
3154 // so we simply scroll to the top.
3155 //
3156 Repaint = TRUE;
3157 if (TopOfScreen != gMenuOption.ForwardLink || SkipValue != 0) {
3158 TopOfScreen = gMenuOption.ForwardLink;
3159 NewPos = SavedListEntry;
3160 SkipValue = 0;
3161 } else {
3162 //
3163 // Scroll up to the last page when we have arrived at top page.
3164 //
3165 TopOfScreen = FindTopOfScreenMenu (gMenuOption.BackLink, BottomRow - TopRow, &SkipValue);
3166 NewPos = gMenuOption.BackLink;
3167 MoveToNextStatement (TRUE, &NewPos, BottomRow - TopRow, TRUE);
3168 }
3169 } else {
3170 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);
3171
3172 if (MenuOption->Row < TopRow + Difference + NextMenuOption->Skip) {
3173 //
3174 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
3175 //
3176 TopOfScreen = NewPos;
3177 Repaint = TRUE;
3178 SkipValue = 0;
3179 }
3180
3181 //
3182 // Check whether new highlight menu is selectable, if not, keep highlight on the old one.
3183 //
3184 // BottomRow - TopRow + 1 means the total rows current forms supported.
3185 // Difference + NextMenuOption->Skip + 1 means the distance between last highlight menu
3186 // and new top menu. New top menu will all shows in next form, but last highlight menu
3187 // may only shows 1 line. + 1 at right part means at least need to keep 1 line for the
3188 // last highlight menu.
3189 //
3190 if (!IsSelectable(NextMenuOption) && IsSelectable(MenuOption) &&
3191 (BottomRow - TopRow + 1 >= Difference + NextMenuOption->Skip + 1)) {
3192 NewPos = SavedListEntry;
3193 }
3194 }
3195
3196 UpdateStatusBar (INPUT_ERROR, FALSE);
3197
3198 //
3199 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
3200 //
3201 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3202 AdjustDateAndTimePosition (TRUE, &NewPos);
3203
3204 UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);
3205 break;
3206
3207 case CfUiPageUp:
3208 //
3209 // SkipValue means lines is skipped when show the top menu option.
3210 //
3211 ControlFlag = CfRepaint;
3212 NewLine = TRUE;
3213 Repaint = TRUE;
3214
3215 Link = TopOfScreen;
3216 //
3217 // First minus the menu of the top screen, it's value is SkipValue.
3218 //
3219 if (SkipValue >= BottomRow - TopRow + 1) {
3220 //
3221 // SkipValue > (BottomRow - TopRow + 1) means current menu has more than one
3222 // form of options to be show, so just update the SkipValue to show the next
3223 // parts of options.
3224 //
3225 SkipValue -= BottomRow - TopRow + 1;
3226 NewPos = TopOfScreen;
3227 break;
3228 } else {
3229 Index = (BottomRow + 1) - SkipValue - TopRow;
3230 }
3231
3232 TopOfScreen = FindTopOfScreenMenu(TopOfScreen, Index, &SkipValue);
3233 NewPos = TopOfScreen;
3234 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow, FALSE);
3235
3236 UpdateStatusBar (INPUT_ERROR, FALSE);
3237
3238 //
3239 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
3240 // Don't do this when we are already in the first page.
3241 //
3242 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3243 AdjustDateAndTimePosition (TRUE, &NewPos);
3244
3245 UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);
3246 break;
3247
3248 case CfUiPageDown:
3249 //
3250 // SkipValue means lines is skipped when show the top menu option.
3251 //
3252 ControlFlag = CfRepaint;
3253 NewLine = TRUE;
3254 Repaint = TRUE;
3255
3256 Link = TopOfScreen;
3257 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
3258 Index = TopRow + NextMenuOption->Skip - SkipValue;
3259 //
3260 // Count to the menu option which will show at the top of the next form.
3261 //
3262 while ((Index <= BottomRow + 1) && (Link->ForwardLink != &gMenuOption)) {
3263 Link = Link->ForwardLink;
3264 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
3265 Index = Index + NextMenuOption->Skip;
3266 }
3267
3268 if ((Link->ForwardLink == &gMenuOption) && (Index <= BottomRow + 1)) {
3269 //
3270 // Highlight on the last menu which can be highlight.
3271 //
3272 Repaint = FALSE;
3273 MoveToNextStatement (TRUE, &Link, Index - TopRow, TRUE);
3274 } else {
3275 //
3276 // Calculate the skip line for top of screen menu.
3277 //
3278 if (Link == TopOfScreen) {
3279 //
3280 // The top of screen menu option occupies the entire form.
3281 //
3282 SkipValue += BottomRow - TopRow + 1;
3283 } else {
3284 SkipValue = NextMenuOption->Skip - (Index - (BottomRow + 1));
3285 }
3286 TopOfScreen = Link;
3287 MenuOption = NULL;
3288 //
3289 // Move to the Next selectable menu.
3290 //
3291 MoveToNextStatement (FALSE, &Link, BottomRow - TopRow, TRUE);
3292 }
3293
3294 //
3295 // Save the menu as the next highlight menu.
3296 //
3297 NewPos = Link;
3298
3299 UpdateStatusBar (INPUT_ERROR, FALSE);
3300
3301 //
3302 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
3303 // Don't do this when we are already in the last page.
3304 //
3305 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3306 AdjustDateAndTimePosition (TRUE, &NewPos);
3307
3308 UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);
3309 break;
3310
3311 case CfUiDown:
3312 //
3313 // SkipValue means lines is skipped when show the top menu option.
3314 // NewPos points to the menu which is highlighted now.
3315 //
3316 ControlFlag = CfRepaint;
3317 NewLine = TRUE;
3318
3319 if (NewPos == TopOfScreen) {
3320 Temp2 = SkipValue;
3321 } else {
3322 Temp2 = 0;
3323 }
3324
3325 SavedListEntry = NewPos;
3326 //
3327 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
3328 // to be one that progresses to the next set of op-codes, we need to advance to the last
3329 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
3330 // checking can be done. The only other logic we need to introduce is that if a Date/Time
3331 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
3332 // the Date/Time op-code.
3333 //
3334 AdjustDateAndTimePosition (FALSE, &NewPos);
3335
3336 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
3337 NewPos = NewPos->ForwardLink;
3338 //
3339 // Find the next selectable menu.
3340 //
3341 if (MenuOption->Row + MenuOption->Skip - Temp2 > BottomRow + 1) {
3342 if (gMenuOption.ForwardLink == NewPos || &gMenuOption == NewPos) {
3343 Difference = -1;
3344 } else {
3345 Difference = 0;
3346 }
3347 } else {
3348 Difference = MoveToNextStatement (FALSE, &NewPos, BottomRow + 1 - (MenuOption->Row + MenuOption->Skip - Temp2), FALSE);
3349 }
3350 if (Difference < 0) {
3351 //
3352 // Scroll to the first page.
3353 //
3354 if (TopOfScreen != gMenuOption.ForwardLink || SkipValue != 0) {
3355 TopOfScreen = gMenuOption.ForwardLink;
3356 Repaint = TRUE;
3357 MenuOption = NULL;
3358 } else {
3359 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
3360 }
3361 NewPos = gMenuOption.ForwardLink;
3362 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow, TRUE);
3363
3364 SkipValue = 0;
3365 //
3366 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
3367 //
3368 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3369 AdjustDateAndTimePosition (TRUE, &NewPos);
3370
3371 UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);
3372 break;
3373 }
3374
3375 //
3376 // Get next selected menu info.
3377 //
3378 AdjustDateAndTimePosition (FALSE, &NewPos);
3379 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);
3380 if (NextMenuOption->Row == 0) {
3381 UpdateOptionSkipLines (NextMenuOption);
3382 }
3383
3384 //
3385 // Calculate new highlight menu end row.
3386 //
3387 Temp = (MenuOption->Row + MenuOption->Skip - Temp2) + Difference + NextMenuOption->Skip - 1;
3388 if (Temp > BottomRow) {
3389 //
3390 // Get the top screen menu info.
3391 //
3392 AdjustDateAndTimePosition (FALSE, &TopOfScreen);
3393 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
3394
3395 //
3396 // Current Top screen menu occupy (SavedMenuOption->Skip - SkipValue) rows.
3397 // Full shows the new selected menu need to skip (Temp - BottomRow - 1) rows.
3398 //
3399 if ((Temp - BottomRow) >= (SavedMenuOption->Skip - SkipValue)) {
3400 //
3401 // Skip the top op-code
3402 //
3403 TopOfScreen = TopOfScreen->ForwardLink;
3404 DistanceValue = (Temp - BottomRow) - (SavedMenuOption->Skip - SkipValue);
3405
3406 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
3407
3408 //
3409 // If we have a remainder, skip that many more op-codes until we drain the remainder
3410 // Special case is the selected highlight menu has more than one form of menus.
3411 //
3412 while (DistanceValue >= SavedMenuOption->Skip && TopOfScreen != NewPos) {
3413 //
3414 // Since the Difference is greater than or equal to this op-code's skip value, skip it
3415 //
3416 DistanceValue = DistanceValue - (INTN) SavedMenuOption->Skip;
3417 TopOfScreen = TopOfScreen->ForwardLink;
3418 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
3419 }
3420 //
3421 // Since we will act on this op-code in the next routine, and increment the
3422 // SkipValue, set the skips to one less than what is required.
3423 //
3424 if (TopOfScreen != NewPos) {
3425 SkipValue = DistanceValue;
3426 } else {
3427 SkipValue = 0;
3428 }
3429 } else {
3430 //
3431 // Since we will act on this op-code in the next routine, and increment the
3432 // SkipValue, set the skips to one less than what is required.
3433 //
3434 SkipValue += Temp - BottomRow;
3435 }
3436 Repaint = TRUE;
3437 } else if (!IsSelectable (NextMenuOption)) {
3438 //
3439 // Continue to go down until scroll to next page or the selectable option is found.
3440 //
3441 ScreenOperation = UiDown;
3442 ControlFlag = CfScreenOperation;
3443 break;
3444 }
3445
3446 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
3447
3448 //
3449 // Check whether new highlight menu is selectable, if not, keep highlight on the old one.
3450 //
3451 // BottomRow - TopRow + 1 means the total rows current forms supported.
3452 // Difference + NextMenuOption->Skip + 1 means the distance between last highlight menu
3453 // and new top menu. New top menu will all shows in next form, but last highlight menu
3454 // may only shows 1 line. + 1 at right part means at least need to keep 1 line for the
3455 // last highlight menu.
3456 //
3457 if (!IsSelectable (NextMenuOption) && IsSelectable (MenuOption) &&
3458 (BottomRow - TopRow + 1 >= Difference + NextMenuOption->Skip + 1)) {
3459 NewPos = SavedListEntry;
3460 }
3461
3462 UpdateStatusBar (INPUT_ERROR, FALSE);
3463
3464 //
3465 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
3466 //
3467 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3468 AdjustDateAndTimePosition (TRUE, &NewPos);
3469
3470 UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);
3471 break;
3472
3473 case CfUiNoOperation:
3474 ControlFlag = CfRepaint;
3475 break;
3476
3477 case CfExit:
3478 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
3479 if (HelpString != NULL) {
3480 FreePool (HelpString);
3481 }
3482 if (HelpHeaderString != NULL) {
3483 FreePool (HelpHeaderString);
3484 }
3485 if (HelpBottomString != NULL) {
3486 FreePool (HelpBottomString);
3487 }
3488 return EFI_SUCCESS;
3489
3490 default:
3491 break;
3492 }
3493 }
3494 }
3495
3496 /**
3497
3498 Base on the browser status info to show an pop up message.
3499
3500 **/
3501 VOID
3502 BrowserStatusProcess (
3503 VOID
3504 )
3505 {
3506 CHAR16 *ErrorInfo;
3507 EFI_INPUT_KEY Key;
3508 EFI_EVENT WaitList[2];
3509 EFI_EVENT RefreshIntervalEvent;
3510 EFI_EVENT TimeOutEvent;
3511 UINT8 TimeOut;
3512 EFI_STATUS Status;
3513 UINTN Index;
3514 WARNING_IF_CONTEXT EventContext;
3515 EFI_IFR_OP_HEADER *OpCodeBuf;
3516 EFI_STRING_ID StringToken;
3517 CHAR16 DiscardChange;
3518 CHAR16 JumpToFormSet;
3519 CHAR16 *PrintString;
3520
3521 if (gFormData->BrowserStatus == BROWSER_SUCCESS) {
3522 return;
3523 }
3524
3525 StringToken = 0;
3526 TimeOutEvent = NULL;
3527 RefreshIntervalEvent = NULL;
3528 OpCodeBuf = NULL;
3529 if (gFormData->HighLightedStatement != NULL) {
3530 OpCodeBuf = gFormData->HighLightedStatement->OpCode;
3531 }
3532
3533 if (gFormData->BrowserStatus == (BROWSER_WARNING_IF)) {
3534 ASSERT (OpCodeBuf != NULL && OpCodeBuf->OpCode == EFI_IFR_WARNING_IF_OP);
3535
3536 TimeOut = ((EFI_IFR_WARNING_IF *) OpCodeBuf)->TimeOut;
3537 StringToken = ((EFI_IFR_WARNING_IF *) OpCodeBuf)->Warning;
3538 } else {
3539 TimeOut = 0;
3540 if ((gFormData->BrowserStatus == (BROWSER_NO_SUBMIT_IF)) &&
3541 (OpCodeBuf != NULL && OpCodeBuf->OpCode == EFI_IFR_NO_SUBMIT_IF_OP)) {
3542 StringToken = ((EFI_IFR_NO_SUBMIT_IF *) OpCodeBuf)->Error;
3543 } else if ((gFormData->BrowserStatus == (BROWSER_INCONSISTENT_IF)) &&
3544 (OpCodeBuf != NULL && OpCodeBuf->OpCode == EFI_IFR_INCONSISTENT_IF_OP)) {
3545 StringToken = ((EFI_IFR_INCONSISTENT_IF *) OpCodeBuf)->Error;
3546 }
3547 }
3548
3549 if (StringToken != 0) {
3550 ErrorInfo = GetToken (StringToken, gFormData->HiiHandle);
3551 } else if (gFormData->ErrorString != NULL) {
3552 //
3553 // Only used to compatible with old setup browser.
3554 // Not use this field in new browser core.
3555 //
3556 ErrorInfo = gFormData->ErrorString;
3557 } else {
3558 switch (gFormData->BrowserStatus) {
3559 case BROWSER_SUBMIT_FAIL:
3560 ErrorInfo = gSaveFailed;
3561 break;
3562
3563 case BROWSER_FORM_NOT_FOUND:
3564 ErrorInfo = gFormNotFound;
3565 break;
3566
3567 case BROWSER_FORM_SUPPRESS:
3568 ErrorInfo = gFormSuppress;
3569 break;
3570
3571 case BROWSER_PROTOCOL_NOT_FOUND:
3572 ErrorInfo = gProtocolNotFound;
3573 break;
3574
3575 case BROWSER_SUBMIT_FAIL_NO_SUBMIT_IF:
3576 ErrorInfo = gNoSubmitIfFailed;
3577 break;
3578
3579 default:
3580 ErrorInfo = gBrwoserError;
3581 break;
3582 }
3583 }
3584
3585 switch (gFormData->BrowserStatus) {
3586 case BROWSER_SUBMIT_FAIL:
3587 case BROWSER_SUBMIT_FAIL_NO_SUBMIT_IF:
3588 ASSERT (gUserInput != NULL);
3589 if (gFormData->BrowserStatus == (BROWSER_SUBMIT_FAIL)) {
3590 PrintString = gSaveProcess;
3591 JumpToFormSet = gJumpToFormSet[0];
3592 } else {
3593 PrintString = gSaveNoSubmitProcess;
3594 JumpToFormSet = gCheckError[0];
3595 }
3596 DiscardChange = gDiscardChange[0];
3597
3598 do {
3599 CreateDialog (&Key, gEmptyString, ErrorInfo, PrintString, gEmptyString, NULL);
3600 } while (((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (DiscardChange | UPPER_LOWER_CASE_OFFSET)) &&
3601 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (JumpToFormSet | UPPER_LOWER_CASE_OFFSET)));
3602
3603 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (DiscardChange | UPPER_LOWER_CASE_OFFSET)) {
3604 gUserInput->Action = BROWSER_ACTION_DISCARD;
3605 } else {
3606 gUserInput->Action = BROWSER_ACTION_GOTO;
3607 }
3608 break;
3609
3610 default:
3611 if (TimeOut == 0) {
3612 do {
3613 CreateDialog (&Key, gEmptyString, ErrorInfo, gPressEnter, gEmptyString, NULL);
3614 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
3615 } else {
3616 Status = gBS->CreateEvent (EVT_NOTIFY_WAIT, TPL_CALLBACK, EmptyEventProcess, NULL, &TimeOutEvent);
3617 ASSERT_EFI_ERROR (Status);
3618
3619 EventContext.SyncEvent = TimeOutEvent;
3620 EventContext.TimeOut = &TimeOut;
3621 EventContext.ErrorInfo = ErrorInfo;
3622
3623 Status = gBS->CreateEvent (EVT_TIMER | EVT_NOTIFY_SIGNAL, TPL_CALLBACK, RefreshTimeOutProcess, &EventContext, &RefreshIntervalEvent);
3624 ASSERT_EFI_ERROR (Status);
3625
3626 //
3627 // Show the dialog first to avoid long time not reaction.
3628 //
3629 gBS->SignalEvent (RefreshIntervalEvent);
3630
3631 Status = gBS->SetTimer (RefreshIntervalEvent, TimerPeriodic, ONE_SECOND);
3632 ASSERT_EFI_ERROR (Status);
3633
3634 while (TRUE) {
3635 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
3636 if (!EFI_ERROR (Status) && Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {
3637 break;
3638 }
3639
3640 if (Status != EFI_NOT_READY) {
3641 continue;
3642 }
3643
3644 WaitList[0] = TimeOutEvent;
3645 WaitList[1] = gST->ConIn->WaitForKey;
3646
3647 Status = gBS->WaitForEvent (2, WaitList, &Index);
3648 ASSERT_EFI_ERROR (Status);
3649
3650 if (Index == 0) {
3651 //
3652 // Timeout occur, close the hoot time out event.
3653 //
3654 break;
3655 }
3656 }
3657
3658 gBS->CloseEvent (TimeOutEvent);
3659 gBS->CloseEvent (RefreshIntervalEvent);
3660 }
3661 break;
3662 }
3663
3664 if (StringToken != 0) {
3665 FreePool (ErrorInfo);
3666 }
3667 }
3668
3669 /**
3670 Display one form, and return user input.
3671
3672 @param FormData Form Data to be shown.
3673 @param UserInputData User input data.
3674
3675 @retval EFI_SUCCESS 1.Form Data is shown, and user input is got.
3676 2.Error info has show and return.
3677 @retval EFI_INVALID_PARAMETER The input screen dimension is not valid
3678 @retval EFI_NOT_FOUND New form data has some error.
3679 **/
3680 EFI_STATUS
3681 EFIAPI
3682 FormDisplay (
3683 IN FORM_DISPLAY_ENGINE_FORM *FormData,
3684 OUT USER_INPUT *UserInputData
3685 )
3686 {
3687 EFI_STATUS Status;
3688
3689 ASSERT (FormData != NULL);
3690 if (FormData == NULL) {
3691 return EFI_INVALID_PARAMETER;
3692 }
3693
3694 gUserInput = UserInputData;
3695 gFormData = FormData;
3696
3697 //
3698 // Process the status info first.
3699 //
3700 BrowserStatusProcess();
3701 if (gFormData->BrowserStatus != BROWSER_SUCCESS) {
3702 //
3703 // gFormData->BrowserStatus != BROWSER_SUCCESS, means only need to print the error info, return here.
3704 //
3705 return EFI_SUCCESS;
3706 }
3707
3708 Status = DisplayPageFrame (FormData, &gStatementDimensions);
3709 if (EFI_ERROR (Status)) {
3710 return Status;
3711 }
3712
3713 //
3714 // Global Widths should be initialized before any MenuOption creation
3715 // or the GetWidth() used in UiAddMenuOption() will return incorrect value.
3716 //
3717 //
3718 // Left right
3719 // |<-.->|<-.........->|<- .........->|<-...........->|
3720 // Skip Prompt Option Help
3721 //
3722 gOptionBlockWidth = (CHAR16) ((gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn) / 3) + 1;
3723 gHelpBlockWidth = (CHAR16) (gOptionBlockWidth - 1 - LEFT_SKIPPED_COLUMNS);
3724 gPromptBlockWidth = (CHAR16) (gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * (gOptionBlockWidth - 1) - 1);
3725
3726 ConvertStatementToMenu();
3727
3728 //
3729 // Check whether layout is changed.
3730 //
3731 if (mIsFirstForm
3732 || (gOldFormEntry.HiiHandle != FormData->HiiHandle)
3733 || (!CompareGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid))
3734 || (gOldFormEntry.FormId != FormData->FormId)) {
3735 mStatementLayoutIsChanged = TRUE;
3736 } else {
3737 mStatementLayoutIsChanged = FALSE;
3738 }
3739
3740 Status = UiDisplayMenu(FormData);
3741
3742 //
3743 // Backup last form info.
3744 //
3745 mIsFirstForm = FALSE;
3746 gOldFormEntry.HiiHandle = FormData->HiiHandle;
3747 CopyGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid);
3748 gOldFormEntry.FormId = FormData->FormId;
3749
3750 return Status;
3751 }
3752
3753 /**
3754 Clear Screen to the initial state.
3755 **/
3756 VOID
3757 EFIAPI
3758 DriverClearDisplayPage (
3759 VOID
3760 )
3761 {
3762 ClearDisplayPage ();
3763 mIsFirstForm = TRUE;
3764 }
3765
3766 /**
3767 Set Buffer to Value for Size bytes.
3768
3769 @param Buffer Memory to set.
3770 @param Size Number of bytes to set
3771 @param Value Value of the set operation.
3772
3773 **/
3774 VOID
3775 SetUnicodeMem (
3776 IN VOID *Buffer,
3777 IN UINTN Size,
3778 IN CHAR16 Value
3779 )
3780 {
3781 CHAR16 *Ptr;
3782
3783 Ptr = Buffer;
3784 while ((Size--) != 0) {
3785 *(Ptr++) = Value;
3786 }
3787 }
3788
3789 /**
3790 Initialize Setup Browser driver.
3791
3792 @param ImageHandle The image handle.
3793 @param SystemTable The system table.
3794
3795 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
3796 @return Other value if failed to initialize the Setup Browser module.
3797
3798 **/
3799 EFI_STATUS
3800 EFIAPI
3801 InitializeDisplayEngine (
3802 IN EFI_HANDLE ImageHandle,
3803 IN EFI_SYSTEM_TABLE *SystemTable
3804 )
3805 {
3806 EFI_STATUS Status;
3807 EFI_INPUT_KEY HotKey;
3808 EFI_STRING NewString;
3809 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL *FormBrowserEx2;
3810
3811 //
3812 // Publish our HII data
3813 //
3814 gHiiHandle = HiiAddPackages (
3815 &gDisplayEngineGuid,
3816 ImageHandle,
3817 DisplayEngineStrings,
3818 NULL
3819 );
3820 ASSERT (gHiiHandle != NULL);
3821
3822 //
3823 // Install Form Display protocol
3824 //
3825 Status = gBS->InstallProtocolInterface (
3826 &mPrivateData.Handle,
3827 &gEdkiiFormDisplayEngineProtocolGuid,
3828 EFI_NATIVE_INTERFACE,
3829 &mPrivateData.FromDisplayProt
3830 );
3831 ASSERT_EFI_ERROR (Status);
3832
3833 InitializeDisplayStrings();
3834
3835 ZeroMem (&gHighligthMenuInfo, sizeof (gHighligthMenuInfo));
3836 ZeroMem (&gOldFormEntry, sizeof (gOldFormEntry));
3837
3838 //
3839 // Use BrowserEx2 protocol to register HotKey.
3840 //
3841 Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **) &FormBrowserEx2);
3842 if (!EFI_ERROR (Status)) {
3843 //
3844 // Register the default HotKey F9 and F10 again.
3845 //
3846 HotKey.UnicodeChar = CHAR_NULL;
3847 HotKey.ScanCode = SCAN_F10;
3848 NewString = HiiGetString (gHiiHandle, STRING_TOKEN (FUNCTION_TEN_STRING), NULL);
3849 ASSERT (NewString != NULL);
3850 FormBrowserEx2->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);
3851
3852 HotKey.ScanCode = SCAN_F9;
3853 NewString = HiiGetString (gHiiHandle, STRING_TOKEN (FUNCTION_NINE_STRING), NULL);
3854 ASSERT (NewString != NULL);
3855 FormBrowserEx2->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);
3856 }
3857
3858 return EFI_SUCCESS;
3859 }
3860
3861 /**
3862 This is the default unload handle for display core drivers.
3863
3864 @param[in] ImageHandle The drivers' driver image.
3865
3866 @retval EFI_SUCCESS The image is unloaded.
3867 @retval Others Failed to unload the image.
3868
3869 **/
3870 EFI_STATUS
3871 EFIAPI
3872 UnloadDisplayEngine (
3873 IN EFI_HANDLE ImageHandle
3874 )
3875 {
3876 HiiRemovePackages(gHiiHandle);
3877
3878 FreeDisplayStrings ();
3879
3880 if (gHighligthMenuInfo.HLTOpCode != NULL) {
3881 FreePool (gHighligthMenuInfo.HLTOpCode);
3882 }
3883
3884 if (gHighligthMenuInfo.TOSOpCode != NULL) {
3885 FreePool (gHighligthMenuInfo.TOSOpCode);
3886 }
3887
3888 return EFI_SUCCESS;
3889 }