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