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