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