]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
Clean the garbage space for the statements nest in subtitle menu.
[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 }
1860
1861 FreePool (OutputString);
1862 if (Temp3 != 0) {
1863 Temp3--;
1864 }
1865 }
1866
1867 FreePool (StringPtr);
1868 }
1869
1870 //
1871 // 4.Line number for Option string and prompt string are not equal.
1872 // Clean the column whose line number is less.
1873 //
1874 if (HasOptionString(MenuOption) && (OptionLineNum != PromptLineNum)) {
1875 Col = OptionLineNum < PromptLineNum ? MenuOption->OptCol : BeginCol;
1876 Row = (OptionLineNum < PromptLineNum ? OptionLineNum : PromptLineNum) + MenuOption->Row;
1877 Width = (UINT16) (OptionLineNum < PromptLineNum ? gOptionBlockWidth : PromptWidth + AdjustValue + SkipWidth);
1878 MaxRow = (OptionLineNum < PromptLineNum ? PromptLineNum : OptionLineNum) + MenuOption->Row - 1;
1879
1880 while (Row <= MaxRow) {
1881 DisplayMenuString (MenuOption, Col, Row++, L"", Width, FALSE);
1882 }
1883 }
1884
1885 return EFI_SUCCESS;
1886 }
1887
1888 /**
1889 Display menu and wait for user to select one menu option, then return it.
1890 If AutoBoot is enabled, then if user doesn't select any option,
1891 after period of time, it will automatically return the first menu option.
1892
1893 @param FormData The current form data info.
1894
1895 @retval EFI_SUCESSS Process the user selection success.
1896 @retval EFI_NOT_FOUND Process option string for orderedlist/Oneof fail.
1897
1898 **/
1899 EFI_STATUS
1900 UiDisplayMenu (
1901 IN FORM_DISPLAY_ENGINE_FORM *FormData
1902 )
1903 {
1904 INTN SkipValue;
1905 INTN Difference;
1906 UINTN DistanceValue;
1907 UINTN Row;
1908 UINTN Col;
1909 UINTN Temp;
1910 UINTN Temp2;
1911 UINTN TopRow;
1912 UINTN BottomRow;
1913 UINTN OriginalRow;
1914 UINTN Index;
1915 UINT16 Width;
1916 CHAR16 *StringPtr;
1917 CHAR16 *OptionString;
1918 CHAR16 *OutputString;
1919 CHAR16 *HelpString;
1920 CHAR16 *HelpHeaderString;
1921 CHAR16 *HelpBottomString;
1922 BOOLEAN NewLine;
1923 BOOLEAN Repaint;
1924 BOOLEAN UpArrow;
1925 BOOLEAN DownArrow;
1926 EFI_STATUS Status;
1927 EFI_INPUT_KEY Key;
1928 LIST_ENTRY *Link;
1929 LIST_ENTRY *NewPos;
1930 LIST_ENTRY *TopOfScreen;
1931 LIST_ENTRY *SavedListEntry;
1932 UI_MENU_OPTION *MenuOption;
1933 UI_MENU_OPTION *NextMenuOption;
1934 UI_MENU_OPTION *SavedMenuOption;
1935 UI_MENU_OPTION *PreviousMenuOption;
1936 UI_CONTROL_FLAG ControlFlag;
1937 UI_SCREEN_OPERATION ScreenOperation;
1938 UINT16 DefaultId;
1939 FORM_DISPLAY_ENGINE_STATEMENT *Statement;
1940 BROWSER_HOT_KEY *HotKey;
1941 UINTN HelpPageIndex;
1942 UINTN HelpPageCount;
1943 UINTN RowCount;
1944 UINTN HelpLine;
1945 UINTN HelpHeaderLine;
1946 UINTN HelpBottomLine;
1947 BOOLEAN MultiHelpPage;
1948 UINT16 GlyphWidth;
1949 UINT16 EachLineWidth;
1950 UINT16 HeaderLineWidth;
1951 UINT16 BottomLineWidth;
1952 EFI_STRING_ID HelpInfo;
1953 UI_EVENT_TYPE EventType;
1954 FORM_DISPLAY_ENGINE_STATEMENT *InitialHighlight;
1955 BOOLEAN SkipHighLight;
1956
1957 EventType = UIEventNone;
1958 Status = EFI_SUCCESS;
1959 HelpString = NULL;
1960 HelpHeaderString = NULL;
1961 HelpBottomString = NULL;
1962 OptionString = NULL;
1963 ScreenOperation = UiNoOperation;
1964 NewLine = TRUE;
1965 DefaultId = 0;
1966 HelpPageCount = 0;
1967 HelpLine = 0;
1968 RowCount = 0;
1969 HelpBottomLine = 0;
1970 HelpHeaderLine = 0;
1971 HelpPageIndex = 0;
1972 MultiHelpPage = FALSE;
1973 EachLineWidth = 0;
1974 HeaderLineWidth = 0;
1975 BottomLineWidth = 0;
1976 OutputString = NULL;
1977 UpArrow = FALSE;
1978 DownArrow = FALSE;
1979 SkipValue = 0;
1980 SkipHighLight = FALSE;
1981
1982 NextMenuOption = NULL;
1983 PreviousMenuOption = NULL;
1984 SavedMenuOption = NULL;
1985 HotKey = NULL;
1986 Repaint = TRUE;
1987 MenuOption = NULL;
1988 gModalSkipColumn = (CHAR16) (gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn) / 6;
1989 InitialHighlight = gFormData->HighLightedStatement;
1990
1991 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));
1992
1993 //
1994 // Left right
1995 // |<-.->|<-.........->|<- .........->|<-...........->|
1996 // Skip Prompt Option Help
1997 //
1998 Width = (CHAR16) ((gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn) / 3);
1999 gOptionBlockWidth = Width + 1;
2000 gHelpBlockWidth = (CHAR16) (Width - LEFT_SKIPPED_COLUMNS);
2001 gPromptBlockWidth = (CHAR16) (gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * Width - 1);
2002
2003 TopRow = gStatementDimensions.TopRow + SCROLL_ARROW_HEIGHT;
2004 BottomRow = gStatementDimensions.BottomRow - SCROLL_ARROW_HEIGHT - 1;
2005
2006 Row = TopRow;
2007 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2008 Col = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS + gModalSkipColumn;
2009 } else {
2010 Col = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS;
2011 }
2012
2013 FindTopMenu(FormData, &TopOfScreen, &NewPos, &SkipValue);
2014
2015 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
2016
2017 ControlFlag = CfInitialization;
2018 while (TRUE) {
2019 switch (ControlFlag) {
2020 case CfInitialization:
2021 if ((gOldFormEntry.HiiHandle != FormData->HiiHandle) ||
2022 (!CompareGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid))) {
2023 //
2024 // Clear Statement range if different formset is painted.
2025 //
2026 ClearLines (
2027 gStatementDimensions.LeftColumn,
2028 gStatementDimensions.RightColumn,
2029 TopRow - SCROLL_ARROW_HEIGHT,
2030 BottomRow + SCROLL_ARROW_HEIGHT,
2031 GetFieldTextColor ()
2032 );
2033
2034 }
2035 ControlFlag = CfRepaint;
2036 break;
2037
2038 case CfRepaint:
2039 ControlFlag = CfRefreshHighLight;
2040
2041 if (Repaint) {
2042 //
2043 // Display menu
2044 //
2045 DownArrow = FALSE;
2046 UpArrow = FALSE;
2047 Row = TopRow;
2048
2049 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2050
2051 //
2052 // 1. Check whether need to print the arrow up.
2053 //
2054 if (!ValueIsScroll (TRUE, TopOfScreen)) {
2055 UpArrow = TRUE;
2056 }
2057
2058 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2059 PrintStringAtWithWidth(gStatementDimensions.LeftColumn + gModalSkipColumn, TopRow - 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * gModalSkipColumn);
2060 } else {
2061 PrintStringAtWithWidth(gStatementDimensions.LeftColumn, TopRow - 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn);
2062 }
2063 if (UpArrow) {
2064 gST->ConOut->SetAttribute (gST->ConOut, GetArrowColor ());
2065 PrintCharAt (
2066 gStatementDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,
2067 TopRow - SCROLL_ARROW_HEIGHT,
2068 ARROW_UP
2069 );
2070 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2071 }
2072
2073 //
2074 // 2.Paint the menu.
2075 //
2076 for (Link = TopOfScreen; Link != &gMenuOption; Link = Link->ForwardLink) {
2077 MenuOption = MENU_OPTION_FROM_LINK (Link);
2078 MenuOption->Row = Row;
2079 MenuOption->Col = Col;
2080 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2081 MenuOption->OptCol = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS + gPromptBlockWidth + gModalSkipColumn;
2082 } else {
2083 MenuOption->OptCol = gStatementDimensions.LeftColumn + LEFT_SKIPPED_COLUMNS + gPromptBlockWidth;
2084 }
2085
2086 if (MenuOption->NestInStatement) {
2087 MenuOption->Col += SUBTITLE_INDENT;
2088 }
2089
2090 //
2091 // Save the highlight menu, will be used in CfRefreshHighLight case.
2092 //
2093 if (Link == NewPos) {
2094 SavedMenuOption = MenuOption;
2095 SkipHighLight = TRUE;
2096 }
2097
2098 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2099 Status = DisplayOneMenu (MenuOption,
2100 MenuOption->Col - gStatementDimensions.LeftColumn,
2101 gStatementDimensions.LeftColumn + gModalSkipColumn,
2102 Link == TopOfScreen ? SkipValue : 0,
2103 BottomRow,
2104 (BOOLEAN) ((Link == NewPos) && IsSelectable(MenuOption))
2105 );
2106 } else {
2107 Status = DisplayOneMenu (MenuOption,
2108 MenuOption->Col - gStatementDimensions.LeftColumn,
2109 gStatementDimensions.LeftColumn,
2110 Link == TopOfScreen ? SkipValue : 0,
2111 BottomRow,
2112 (BOOLEAN) ((Link == NewPos) && IsSelectable(MenuOption))
2113 );
2114 }
2115
2116 if (EFI_ERROR (Status)) {
2117 return Status;
2118 }
2119 //
2120 // 3. Update the row info which will be used by next menu.
2121 //
2122 if (Link == TopOfScreen) {
2123 Row += MenuOption->Skip - SkipValue;
2124 } else {
2125 Row += MenuOption->Skip;
2126 }
2127
2128 if (Row > BottomRow) {
2129 if (!ValueIsScroll (FALSE, Link)) {
2130 DownArrow = TRUE;
2131 }
2132
2133 Row = BottomRow + 1;
2134 break;
2135 }
2136 }
2137
2138 //
2139 // 3. Menus in this form may not cover all form, clean the remain field.
2140 //
2141 while (Row <= BottomRow) {
2142 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2143 PrintStringAtWithWidth(gStatementDimensions.LeftColumn + gModalSkipColumn, Row++, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * gModalSkipColumn);
2144 } else {
2145 PrintStringAtWithWidth(gStatementDimensions.LeftColumn, Row++, L"", gStatementDimensions.RightColumn - gHelpBlockWidth - gStatementDimensions.LeftColumn);
2146 }
2147 }
2148
2149 //
2150 // 4. Print the down arrow row.
2151 //
2152 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2153 PrintStringAtWithWidth(gStatementDimensions.LeftColumn + gModalSkipColumn, BottomRow + 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn - 2 * + gModalSkipColumn);
2154 } else {
2155 PrintStringAtWithWidth(gStatementDimensions.LeftColumn, BottomRow + 1, L"", gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn);
2156 }
2157 if (DownArrow) {
2158 gST->ConOut->SetAttribute (gST->ConOut, GetArrowColor ());
2159 PrintCharAt (
2160 gStatementDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,
2161 BottomRow + SCROLL_ARROW_HEIGHT,
2162 ARROW_DOWN
2163 );
2164 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2165 }
2166
2167 MenuOption = NULL;
2168
2169 if (IsListEmpty (&gMenuOption)) {
2170 ControlFlag = CfReadKey;
2171 }
2172 }
2173 break;
2174
2175 case CfRefreshHighLight:
2176
2177 //
2178 // MenuOption: Last menu option that need to remove hilight
2179 // MenuOption is set to NULL in Repaint
2180 // NewPos: Current menu option that need to hilight
2181 //
2182 ControlFlag = CfUpdateHelpString;
2183
2184 if (SkipHighLight) {
2185 MenuOption = SavedMenuOption;
2186 SkipHighLight = FALSE;
2187 UpdateHighlightMenuInfo (MenuOption);
2188 break;
2189 }
2190
2191 if (MenuOption != NULL && TopOfScreen == &MenuOption->Link) {
2192 Temp = SkipValue;
2193 } else {
2194 Temp = 0;
2195 }
2196 if (NewPos == TopOfScreen) {
2197 Temp2 = SkipValue;
2198 } else {
2199 Temp2 = 0;
2200 }
2201
2202 if (NewPos != NULL && (MenuOption == NULL || NewPos != &MenuOption->Link)) {
2203 if (MenuOption != NULL) {
2204 //
2205 // Remove highlight on last Menu Option
2206 //
2207 gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);
2208 ProcessOptions (MenuOption, FALSE, &OptionString, TRUE);
2209 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2210 if (OptionString != NULL) {
2211 if ((MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_DATE_OP) ||
2212 (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_TIME_OP)
2213 ) {
2214 ProcessStringForDateTime(MenuOption, OptionString, FALSE);
2215 }
2216
2217 Width = (UINT16) gOptionBlockWidth - 1;
2218 OriginalRow = MenuOption->Row;
2219 GlyphWidth = 1;
2220
2221 for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2222 if ((Temp == 0) && (MenuOption->Row >= TopRow) && (MenuOption->Row <= BottomRow)) {
2223 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);
2224 }
2225 //
2226 // If there is more string to process print on the next row and increment the Skip value
2227 //
2228 if (StrLen (&OptionString[Index]) != 0) {
2229 if (Temp == 0) {
2230 MenuOption->Row++;
2231 }
2232 }
2233
2234 FreePool (OutputString);
2235 if (Temp != 0) {
2236 Temp--;
2237 }
2238 }
2239
2240 MenuOption->Row = OriginalRow;
2241
2242 FreePool (OptionString);
2243 } else {
2244 if (NewLine) {
2245 if (MenuOption->GrayOut) {
2246 gST->ConOut->SetAttribute (gST->ConOut, GetGrayedTextColor ());
2247 } else if (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_SUBTITLE_OP) {
2248 gST->ConOut->SetAttribute (gST->ConOut, GetSubTitleTextColor ());
2249 }
2250
2251 OriginalRow = MenuOption->Row;
2252 Width = GetWidth (MenuOption, NULL);
2253 GlyphWidth = 1;
2254
2255 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2256 if ((Temp == 0) && (MenuOption->Row >= TopRow) && (MenuOption->Row <= BottomRow)) {
2257 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);
2258 }
2259 //
2260 // If there is more string to process print on the next row and increment the Skip value
2261 //
2262 if (StrLen (&MenuOption->Description[Index]) != 0) {
2263 if (Temp == 0) {
2264 MenuOption->Row++;
2265 }
2266 }
2267
2268 FreePool (OutputString);
2269 if (Temp != 0) {
2270 Temp--;
2271 }
2272 }
2273
2274 MenuOption->Row = OriginalRow;
2275 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2276 }
2277 }
2278 }
2279
2280 //
2281 // This is the current selected statement
2282 //
2283 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
2284 Statement = MenuOption->ThisTag;
2285
2286 UpdateHighlightMenuInfo (MenuOption);
2287
2288 if (!IsSelectable (MenuOption)) {
2289 break;
2290 }
2291
2292 //
2293 // Set reverse attribute
2294 //
2295 gST->ConOut->SetAttribute (gST->ConOut, GetHighlightTextColor ());
2296 gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);
2297
2298 ProcessOptions (MenuOption, FALSE, &OptionString, TRUE);
2299 if (OptionString != NULL) {
2300 if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP || Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {
2301 ProcessStringForDateTime(MenuOption, OptionString, FALSE);
2302 }
2303 Width = (UINT16) gOptionBlockWidth - 1;
2304
2305 OriginalRow = MenuOption->Row;
2306 GlyphWidth = 1;
2307
2308 for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2309 if ((Temp2 == 0) && (MenuOption->Row >= TopRow) && (MenuOption->Row <= BottomRow) ) {
2310 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);
2311 }
2312 //
2313 // If there is more string to process print on the next row and increment the Skip value
2314 //
2315 if (StrLen (&OptionString[Index]) != 0) {
2316 if (Temp2 == 0) {
2317 MenuOption->Row++;
2318 }
2319 }
2320
2321 FreePool (OutputString);
2322 if (Temp2 != 0) {
2323 Temp2--;
2324 }
2325 }
2326
2327 MenuOption->Row = OriginalRow;
2328
2329 FreePool (OptionString);
2330 } else {
2331 if (NewLine) {
2332 OriginalRow = MenuOption->Row;
2333
2334 Width = GetWidth (MenuOption, NULL);
2335 GlyphWidth = 1;
2336
2337 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {
2338 if ((Temp2 == 0) && (MenuOption->Row >= TopRow) && (MenuOption->Row <= BottomRow) ) {
2339 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);
2340 }
2341 //
2342 // If there is more string to process print on the next row and increment the Skip value
2343 //
2344 if (StrLen (&MenuOption->Description[Index]) != 0) {
2345 if (Temp2 == 0) {
2346 MenuOption->Row++;
2347 }
2348 }
2349
2350 FreePool (OutputString);
2351 if (Temp2 != 0) {
2352 Temp2--;
2353 }
2354 }
2355
2356 MenuOption->Row = OriginalRow;
2357
2358 }
2359 }
2360
2361 //
2362 // Clear reverse attribute
2363 //
2364 gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());
2365 }
2366 break;
2367
2368 case CfUpdateHelpString:
2369 ControlFlag = CfPrepareToReadKey;
2370 if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
2371 break;
2372 }
2373
2374 if (Repaint || NewLine) {
2375 //
2376 // Don't print anything if it is a NULL help token
2377 //
2378 ASSERT(MenuOption != NULL);
2379 HelpInfo = ((EFI_IFR_STATEMENT_HEADER *) ((CHAR8 *)MenuOption->ThisTag->OpCode + sizeof (EFI_IFR_OP_HEADER)))->Help;
2380 if (HelpInfo == 0 || !IsSelectable (MenuOption)) {
2381 StringPtr = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);
2382 } else {
2383 StringPtr = GetToken (HelpInfo, gFormData->HiiHandle);
2384 }
2385
2386 RowCount = BottomRow - TopRow + 1;
2387 HelpPageIndex = 0;
2388 //
2389 // 1.Calculate how many line the help string need to print.
2390 //
2391 if (HelpString != NULL) {
2392 FreePool (HelpString);
2393 HelpString = NULL;
2394 }
2395 HelpLine = ProcessHelpString (StringPtr, &HelpString, &EachLineWidth, RowCount);
2396 FreePool (StringPtr);
2397
2398 if (HelpLine > RowCount) {
2399 MultiHelpPage = TRUE;
2400 StringPtr = GetToken (STRING_TOKEN(ADJUST_HELP_PAGE_UP), gHiiHandle);
2401 if (HelpHeaderString != NULL) {
2402 FreePool (HelpHeaderString);
2403 HelpHeaderString = NULL;
2404 }
2405 HelpHeaderLine = ProcessHelpString (StringPtr, &HelpHeaderString, &HeaderLineWidth, 0);
2406 FreePool (StringPtr);
2407 StringPtr = GetToken (STRING_TOKEN(ADJUST_HELP_PAGE_DOWN), gHiiHandle);
2408 if (HelpBottomString != NULL) {
2409 FreePool (HelpBottomString);
2410 HelpBottomString = NULL;
2411 }
2412 HelpBottomLine = ProcessHelpString (StringPtr, &HelpBottomString, &BottomLineWidth, 0);
2413 FreePool (StringPtr);
2414 //
2415 // Calculate the help page count.
2416 //
2417 if (HelpLine > 2 * RowCount - 2) {
2418 HelpPageCount = (HelpLine - RowCount + 1) / (RowCount - 2) + 1;
2419 if ((HelpLine - RowCount + 1) % (RowCount - 2) > 1) {
2420 HelpPageCount += 1;
2421 }
2422 } else {
2423 HelpPageCount = 2;
2424 }
2425 } else {
2426 MultiHelpPage = FALSE;
2427 }
2428 }
2429
2430 //
2431 // Check whether need to show the 'More(U/u)' at the begin.
2432 // Base on current direct info, here shows aligned to the right side of the column.
2433 // If the direction is multi line and aligned to right side may have problem, so
2434 // add ASSERT code here.
2435 //
2436 if (HelpPageIndex > 0) {
2437 gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
2438 for (Index = 0; Index < HelpHeaderLine; Index++) {
2439 ASSERT (HelpHeaderLine == 1);
2440 ASSERT (GetStringWidth (HelpHeaderString) / 2 < (UINTN) (gHelpBlockWidth - 1));
2441 PrintStringAtWithWidth (
2442 gStatementDimensions.RightColumn - gHelpBlockWidth,
2443 Index + TopRow,
2444 gEmptyString,
2445 gHelpBlockWidth
2446 );
2447 PrintStringAt (
2448 gStatementDimensions.RightColumn - GetStringWidth (HelpHeaderString) / 2 - 1,
2449 Index + TopRow,
2450 &HelpHeaderString[Index * HeaderLineWidth]
2451 );
2452 }
2453 }
2454
2455 gST->ConOut->SetAttribute (gST->ConOut, GetHelpTextColor ());
2456 //
2457 // Print the help string info.
2458 //
2459 if (!MultiHelpPage) {
2460 for (Index = 0; Index < HelpLine; Index++) {
2461 PrintStringAtWithWidth (
2462 gStatementDimensions.RightColumn - gHelpBlockWidth,
2463 Index + TopRow,
2464 &HelpString[Index * EachLineWidth],
2465 gHelpBlockWidth
2466 );
2467 }
2468 for (; Index < RowCount; Index ++) {
2469 PrintStringAtWithWidth (
2470 gStatementDimensions.RightColumn - gHelpBlockWidth,
2471 Index + TopRow,
2472 gEmptyString,
2473 gHelpBlockWidth
2474 );
2475 }
2476 gST->ConOut->SetCursorPosition(gST->ConOut, gStatementDimensions.RightColumn-1, BottomRow);
2477 } else {
2478 if (HelpPageIndex == 0) {
2479 for (Index = 0; Index < RowCount - HelpBottomLine; Index++) {
2480 PrintStringAtWithWidth (
2481 gStatementDimensions.RightColumn - gHelpBlockWidth,
2482 Index + TopRow,
2483 &HelpString[Index * EachLineWidth],
2484 gHelpBlockWidth
2485 );
2486 }
2487 } else {
2488 for (Index = 0; (Index < RowCount - HelpBottomLine - HelpHeaderLine) &&
2489 (Index + HelpPageIndex * (RowCount - 2) + 1 < HelpLine); Index++) {
2490 PrintStringAtWithWidth (
2491 gStatementDimensions.RightColumn - gHelpBlockWidth,
2492 Index + TopRow + HelpHeaderLine,
2493 &HelpString[(Index + HelpPageIndex * (RowCount - 2) + 1)* EachLineWidth],
2494 gHelpBlockWidth
2495 );
2496 }
2497 if (HelpPageIndex == HelpPageCount - 1) {
2498 for (; Index < RowCount - HelpHeaderLine; Index ++) {
2499 PrintStringAtWithWidth (
2500 gStatementDimensions.RightColumn - gHelpBlockWidth,
2501 Index + TopRow + HelpHeaderLine,
2502 gEmptyString,
2503 gHelpBlockWidth
2504 );
2505 }
2506 gST->ConOut->SetCursorPosition(gST->ConOut, gStatementDimensions.RightColumn-1, BottomRow);
2507 }
2508 }
2509 }
2510
2511 //
2512 // Check whether need to print the 'More(D/d)' at the bottom.
2513 // Base on current direct info, here shows aligned to the right side of the column.
2514 // If the direction is multi line and aligned to right side may have problem, so
2515 // add ASSERT code here.
2516 //
2517 if (HelpPageIndex < HelpPageCount - 1 && MultiHelpPage) {
2518 gST->ConOut->SetAttribute (gST->ConOut, GetInfoTextColor ());
2519 for (Index = 0; Index < HelpBottomLine; Index++) {
2520 ASSERT (HelpBottomLine == 1);
2521 ASSERT (GetStringWidth (HelpBottomString) / 2 < (UINTN) (gHelpBlockWidth - 1));
2522 PrintStringAtWithWidth (
2523 gStatementDimensions.RightColumn - gHelpBlockWidth,
2524 BottomRow + Index - HelpBottomLine + 1,
2525 gEmptyString,
2526 gHelpBlockWidth
2527 );
2528 PrintStringAt (
2529 gStatementDimensions.RightColumn - GetStringWidth (HelpBottomString) / 2 - 1,
2530 BottomRow + Index - HelpBottomLine + 1,
2531 &HelpBottomString[Index * BottomLineWidth]
2532 );
2533 }
2534 }
2535 //
2536 // Reset this flag every time we finish using it.
2537 //
2538 Repaint = FALSE;
2539 NewLine = FALSE;
2540 break;
2541
2542 case CfPrepareToReadKey:
2543 ControlFlag = CfReadKey;
2544 ScreenOperation = UiNoOperation;
2545 break;
2546
2547 case CfReadKey:
2548 ControlFlag = CfScreenOperation;
2549
2550 //
2551 // Wait for user's selection
2552 //
2553 while (TRUE) {
2554 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2555 if (!EFI_ERROR (Status)) {
2556 EventType = UIEventKey;
2557 break;
2558 }
2559
2560 //
2561 // If we encounter error, continue to read another key in.
2562 //
2563 if (Status != EFI_NOT_READY) {
2564 continue;
2565 }
2566
2567 EventType = UiWaitForEvent(gST->ConIn->WaitForKey);
2568 if (EventType == UIEventKey) {
2569 gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
2570 }
2571 break;
2572 }
2573
2574 if (EventType == UIEventDriver) {
2575 gUserInput->Action = BROWSER_ACTION_NONE;
2576 ControlFlag = CfExit;
2577 break;
2578 }
2579
2580 if (EventType == UIEventTimeOut) {
2581 gUserInput->Action = BROWSER_ACTION_FORM_EXIT;
2582 ControlFlag = CfExit;
2583 break;
2584 }
2585
2586 switch (Key.UnicodeChar) {
2587 case CHAR_CARRIAGE_RETURN:
2588 if(MenuOption == NULL || MenuOption->GrayOut || MenuOption->ReadOnly) {
2589 ControlFlag = CfReadKey;
2590 break;
2591 }
2592
2593 ScreenOperation = UiSelect;
2594 gDirection = 0;
2595 break;
2596
2597 //
2598 // We will push the adjustment of these numeric values directly to the input handler
2599 // NOTE: we won't handle manual input numeric
2600 //
2601 case '+':
2602 case '-':
2603 //
2604 // If the screen has no menu items, and the user didn't select UiReset
2605 // ignore the selection and go back to reading keys.
2606 //
2607 if(IsListEmpty (&gMenuOption) || MenuOption->GrayOut || MenuOption->ReadOnly) {
2608 ControlFlag = CfReadKey;
2609 break;
2610 }
2611
2612 ASSERT(MenuOption != NULL);
2613 Statement = MenuOption->ThisTag;
2614 if ((Statement->OpCode->OpCode == EFI_IFR_DATE_OP)
2615 || (Statement->OpCode->OpCode == EFI_IFR_TIME_OP)
2616 || ((Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP) && (GetFieldFromNum(Statement->OpCode) != 0))
2617 ){
2618 if (Key.UnicodeChar == '+') {
2619 gDirection = SCAN_RIGHT;
2620 } else {
2621 gDirection = SCAN_LEFT;
2622 }
2623
2624 Status = ProcessOptions (MenuOption, TRUE, &OptionString, TRUE);
2625 if (OptionString != NULL) {
2626 FreePool (OptionString);
2627 }
2628 if (EFI_ERROR (Status)) {
2629 //
2630 // Repaint to clear possible error prompt pop-up
2631 //
2632 Repaint = TRUE;
2633 NewLine = TRUE;
2634 } else {
2635 ControlFlag = CfExit;
2636 }
2637 }
2638 break;
2639
2640 case '^':
2641 ScreenOperation = UiUp;
2642 break;
2643
2644 case 'V':
2645 case 'v':
2646 ScreenOperation = UiDown;
2647 break;
2648
2649 case ' ':
2650 if(IsListEmpty (&gMenuOption)) {
2651 ControlFlag = CfReadKey;
2652 break;
2653 }
2654
2655 ASSERT(MenuOption != NULL);
2656 if (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut && !MenuOption->ReadOnly) {
2657 ScreenOperation = UiSelect;
2658 }
2659 break;
2660
2661 case 'D':
2662 case 'd':
2663 if (!MultiHelpPage) {
2664 ControlFlag = CfReadKey;
2665 break;
2666 }
2667 ControlFlag = CfUpdateHelpString;
2668 HelpPageIndex = HelpPageIndex < HelpPageCount - 1 ? HelpPageIndex + 1 : HelpPageCount - 1;
2669 break;
2670
2671 case 'U':
2672 case 'u':
2673 if (!MultiHelpPage) {
2674 ControlFlag = CfReadKey;
2675 break;
2676 }
2677 ControlFlag = CfUpdateHelpString;
2678 HelpPageIndex = HelpPageIndex > 0 ? HelpPageIndex - 1 : 0;
2679 break;
2680
2681 case CHAR_NULL:
2682 for (Index = 0; Index < mScanCodeNumber; Index++) {
2683 if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {
2684 ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;
2685 break;
2686 }
2687 }
2688
2689 if (((FormData->Attribute & HII_DISPLAY_MODAL) != 0) && (Key.ScanCode == SCAN_ESC || Index == mScanCodeNumber)) {
2690 //
2691 // ModalForm has no ESC key and Hot Key.
2692 //
2693 ControlFlag = CfReadKey;
2694 } else if (Index == mScanCodeNumber) {
2695 //
2696 // Check whether Key matches the registered hot key.
2697 //
2698 HotKey = NULL;
2699 HotKey = GetHotKeyFromRegisterList (&Key);
2700 if (HotKey != NULL) {
2701 ScreenOperation = UiHotKey;
2702 }
2703 }
2704 break;
2705 }
2706 break;
2707
2708 case CfScreenOperation:
2709 if (ScreenOperation != UiReset) {
2710 //
2711 // If the screen has no menu items, and the user didn't select UiReset
2712 // ignore the selection and go back to reading keys.
2713 //
2714 if (IsListEmpty (&gMenuOption)) {
2715 ControlFlag = CfReadKey;
2716 break;
2717 }
2718 }
2719
2720 for (Index = 0;
2721 Index < sizeof (gScreenOperationToControlFlag) / sizeof (gScreenOperationToControlFlag[0]);
2722 Index++
2723 ) {
2724 if (ScreenOperation == gScreenOperationToControlFlag[Index].ScreenOperation) {
2725 ControlFlag = gScreenOperationToControlFlag[Index].ControlFlag;
2726 break;
2727 }
2728 }
2729 break;
2730
2731 case CfUiSelect:
2732 ControlFlag = CfRepaint;
2733
2734 ASSERT(MenuOption != NULL);
2735 Statement = MenuOption->ThisTag;
2736 if (Statement->OpCode->OpCode == EFI_IFR_TEXT_OP) {
2737 break;
2738 }
2739
2740 switch (Statement->OpCode->OpCode) {
2741 case EFI_IFR_REF_OP:
2742 case EFI_IFR_ACTION_OP:
2743 case EFI_IFR_RESET_BUTTON_OP:
2744 ControlFlag = CfExit;
2745 break;
2746
2747 default:
2748 //
2749 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password
2750 //
2751 RefreshKeyHelp (gFormData, Statement, TRUE);
2752 Status = ProcessOptions (MenuOption, TRUE, &OptionString, TRUE);
2753
2754 if (OptionString != NULL) {
2755 FreePool (OptionString);
2756 }
2757
2758 if (EFI_ERROR (Status)) {
2759 Repaint = TRUE;
2760 NewLine = TRUE;
2761 RefreshKeyHelp (gFormData, Statement, FALSE);
2762 break;
2763 } else {
2764 ControlFlag = CfExit;
2765 break;
2766 }
2767 }
2768 break;
2769
2770 case CfUiReset:
2771 //
2772 // We come here when someone press ESC
2773 // If the policy is not exit front page when user press ESC, process here.
2774 //
2775 if (!FormExitPolicy()) {
2776 Repaint = TRUE;
2777 NewLine = TRUE;
2778 ControlFlag = CfRepaint;
2779 break;
2780 }
2781
2782 //
2783 // When user press ESC, it will try to show another menu, should clean the gSequence info.
2784 //
2785 if (gSequence != 0) {
2786 gSequence = 0;
2787 }
2788
2789 gUserInput->Action = BROWSER_ACTION_FORM_EXIT;
2790 ControlFlag = CfExit;
2791 break;
2792
2793 case CfUiHotKey:
2794 ControlFlag = CfRepaint;
2795
2796 gUserInput->Action = HotKey->Action;
2797 ControlFlag = CfExit;
2798 break;
2799
2800 case CfUiLeft:
2801 ControlFlag = CfRepaint;
2802 ASSERT(MenuOption != NULL);
2803 if ((MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_TIME_OP)) {
2804 if (MenuOption->Sequence != 0) {
2805 //
2806 // In the middle or tail of the Date/Time op-code set, go left.
2807 //
2808 ASSERT(NewPos != NULL);
2809 NewPos = NewPos->BackLink;
2810 }
2811 }
2812 break;
2813
2814 case CfUiRight:
2815 ControlFlag = CfRepaint;
2816 ASSERT(MenuOption != NULL);
2817 if ((MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_TIME_OP)) {
2818 if (MenuOption->Sequence != 2) {
2819 //
2820 // In the middle or tail of the Date/Time op-code set, go left.
2821 //
2822 ASSERT(NewPos != NULL);
2823 NewPos = NewPos->ForwardLink;
2824 }
2825 }
2826 break;
2827
2828 case CfUiUp:
2829 ControlFlag = CfRepaint;
2830
2831 SavedListEntry = NewPos;
2832
2833 ASSERT(NewPos != NULL);
2834 //
2835 // Adjust Date/Time position before we advance forward.
2836 //
2837 AdjustDateAndTimePosition (TRUE, &NewPos);
2838 if (NewPos->BackLink != &gMenuOption) {
2839 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
2840 ASSERT (MenuOption != NULL);
2841 NewLine = TRUE;
2842 NewPos = NewPos->BackLink;
2843
2844 PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos);
2845 if (PreviousMenuOption->Row == 0) {
2846 UpdateOptionSkipLines (PreviousMenuOption);
2847 }
2848 DistanceValue = PreviousMenuOption->Skip;
2849 Difference = 0;
2850 if (MenuOption->Row >= DistanceValue + TopRow) {
2851 Difference = MoveToNextStatement (TRUE, &NewPos, MenuOption->Row - TopRow - DistanceValue);
2852 }
2853 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);
2854
2855 if (Difference < 0) {
2856 //
2857 // We hit the begining MenuOption that can be focused
2858 // so we simply scroll to the top.
2859 //
2860 if (TopOfScreen != gMenuOption.ForwardLink) {
2861 TopOfScreen = gMenuOption.ForwardLink;
2862 Repaint = TRUE;
2863 } else {
2864 //
2865 // Scroll up to the last page when we have arrived at top page.
2866 //
2867 NewPos = &gMenuOption;
2868 TopOfScreen = &gMenuOption;
2869 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
2870 ScreenOperation = UiPageUp;
2871 ControlFlag = CfScreenOperation;
2872 break;
2873 }
2874 } else if (MenuOption->Row < TopRow + DistanceValue + Difference) {
2875 //
2876 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll
2877 //
2878 TopOfScreen = NewPos;
2879 Repaint = TRUE;
2880 SkipValue = 0;
2881 } else if (!IsSelectable (NextMenuOption)) {
2882 //
2883 // Continue to go up until scroll to next page or the selectable option is found.
2884 //
2885 ScreenOperation = UiUp;
2886 ControlFlag = CfScreenOperation;
2887 }
2888
2889 //
2890 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
2891 //
2892 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
2893 AdjustDateAndTimePosition (TRUE, &NewPos);
2894 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
2895 UpdateStatusBar (INPUT_ERROR, FALSE);
2896 } else {
2897 if (NewPos->ForwardLink == &gMenuOption) {
2898 NewLine = FALSE;
2899 Repaint = FALSE;
2900 break;
2901 }
2902 //
2903 // Scroll up to the last page.
2904 //
2905 NewPos = &gMenuOption;
2906 TopOfScreen = &gMenuOption;
2907 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
2908 ScreenOperation = UiPageUp;
2909 ControlFlag = CfScreenOperation;
2910 SkipValue = 0;
2911 }
2912 break;
2913
2914 case CfUiPageUp:
2915 //
2916 // SkipValue means lines is skipped when show the top menu option.
2917 //
2918 ControlFlag = CfRepaint;
2919
2920 ASSERT(NewPos != NULL);
2921 //
2922 // Already at the first menu option, Check the skip value.
2923 //
2924 if (NewPos->BackLink == &gMenuOption) {
2925 if (SkipValue == 0) {
2926 NewLine = FALSE;
2927 Repaint = FALSE;
2928 } else {
2929 NewLine = TRUE;
2930 Repaint = TRUE;
2931 SkipValue = 0;
2932 }
2933 break;
2934 }
2935
2936 NewLine = TRUE;
2937 Repaint = TRUE;
2938
2939 //
2940 // SkipValue > (BottomRow - TopRow + 1) means current menu has more than one
2941 // form of options to be show, so just update the SkipValue to show the next
2942 // parts of options.
2943 //
2944 if (SkipValue > (INTN) (BottomRow - TopRow + 1)) {
2945 SkipValue -= BottomRow - TopRow + 1;
2946 break;
2947 }
2948
2949 Link = TopOfScreen;
2950 //
2951 // First minus the menu of the top screen, it's value is SkipValue.
2952 //
2953 Index = (BottomRow + 1) - SkipValue;
2954 while ((Index > TopRow) && (Link->BackLink != &gMenuOption)) {
2955 Link = Link->BackLink;
2956 PreviousMenuOption = MENU_OPTION_FROM_LINK (Link);
2957 if (PreviousMenuOption->Row == 0) {
2958 UpdateOptionSkipLines (PreviousMenuOption);
2959 }
2960 if (Index < PreviousMenuOption->Skip) {
2961 break;
2962 }
2963 Index = Index - PreviousMenuOption->Skip;
2964 }
2965
2966 if ((Link->BackLink == &gMenuOption) && (Index >= TopRow)) {
2967 if (TopOfScreen == &gMenuOption) {
2968 TopOfScreen = gMenuOption.ForwardLink;
2969 NewPos = gMenuOption.BackLink;
2970 MoveToNextStatement (TRUE, &NewPos, BottomRow - TopRow);
2971 if (Index < PreviousMenuOption->Skip) {
2972 Repaint = TRUE;
2973 SkipValue = PreviousMenuOption->Skip - (Index - TopRow);
2974 } else {
2975 Repaint = FALSE;
2976 SkipValue = 0;
2977 }
2978 } else if (TopOfScreen != Link) {
2979 TopOfScreen = Link;
2980 NewPos = Link;
2981 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);
2982 SkipValue = 0;
2983 } else {
2984 //
2985 // Finally we know that NewPos is the last MenuOption can be focused.
2986 //
2987 if (SkipValue == 0) {
2988 Repaint = FALSE;
2989 }
2990 NewPos = Link;
2991 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);
2992 SkipValue = 0;
2993 }
2994 } else {
2995 if (Index > TopRow) {
2996 //
2997 // At here, only case "Index < PreviousMenuOption->Skip" can reach here.
2998 //
2999 SkipValue = PreviousMenuOption->Skip - (Index - TopRow);
3000 } else if (Index == TopRow) {
3001 SkipValue = 0;
3002 } else {
3003 SkipValue = TopRow - Index;
3004 }
3005
3006 //
3007 // Move to the option in Next page.
3008 //
3009 if (TopOfScreen == &gMenuOption) {
3010 NewPos = gMenuOption.BackLink;
3011 MoveToNextStatement (TRUE, &NewPos, BottomRow - TopRow);
3012 } else {
3013 NewPos = Link;
3014 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);
3015 }
3016
3017 //
3018 // There are more MenuOption needing scrolling up.
3019 //
3020 TopOfScreen = Link;
3021 MenuOption = NULL;
3022 }
3023
3024 //
3025 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
3026 // Don't do this when we are already in the first page.
3027 //
3028 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3029 AdjustDateAndTimePosition (TRUE, &NewPos);
3030 break;
3031
3032 case CfUiPageDown:
3033 //
3034 // SkipValue means lines is skipped when show the top menu option.
3035 //
3036 ControlFlag = CfRepaint;
3037
3038 ASSERT (NewPos != NULL);
3039 if (NewPos->ForwardLink == &gMenuOption) {
3040 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
3041 if (SkipValue + BottomRow - TopRow + 1 < MenuOption->Skip) {
3042 SkipValue += BottomRow - TopRow + 1;
3043 NewLine = TRUE;
3044 Repaint = TRUE;
3045 break;
3046 }
3047 NewLine = FALSE;
3048 Repaint = FALSE;
3049 break;
3050 }
3051
3052 NewLine = TRUE;
3053 Repaint = TRUE;
3054 Link = TopOfScreen;
3055 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
3056 Index = TopRow + NextMenuOption->Skip - SkipValue;
3057 //
3058 // Count to the menu option which will show at the top of the next form.
3059 //
3060 while ((Index <= BottomRow + 1) && (Link->ForwardLink != &gMenuOption)) {
3061 Link = Link->ForwardLink;
3062 NextMenuOption = MENU_OPTION_FROM_LINK (Link);
3063 Index = Index + NextMenuOption->Skip;
3064 }
3065
3066 if ((Link->ForwardLink == &gMenuOption) && (Index <= BottomRow + 1)) {
3067 //
3068 // Finally we know that NewPos is the last MenuOption can be focused.
3069 //
3070 Repaint = FALSE;
3071 MoveToNextStatement (TRUE, &Link, Index - TopRow);
3072 } else {
3073 //
3074 // Calculate the skip line for top of screen menu.
3075 //
3076 if (Link == TopOfScreen) {
3077 //
3078 // The top of screen menu option occupies the entire form.
3079 //
3080 SkipValue += BottomRow - TopRow + 1;
3081 } else {
3082 SkipValue = NextMenuOption->Skip - (Index - (BottomRow + 1));
3083 }
3084
3085 TopOfScreen = Link;
3086 MenuOption = NULL;
3087 //
3088 // Move to the Next selectable menu.
3089 //
3090 MoveToNextStatement (FALSE, &Link, BottomRow - TopRow);
3091 }
3092
3093 //
3094 // Save the menu as the next highlight menu.
3095 //
3096 NewPos = Link;
3097
3098 //
3099 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.
3100 // Don't do this when we are already in the last page.
3101 //
3102 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3103 AdjustDateAndTimePosition (TRUE, &NewPos);
3104 break;
3105
3106 case CfUiDown:
3107 //
3108 // SkipValue means lines is skipped when show the top menu option.
3109 // NewPos points to the menu which is highlighted now.
3110 //
3111 ControlFlag = CfRepaint;
3112
3113 //
3114 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended
3115 // to be one that progresses to the next set of op-codes, we need to advance to the last
3116 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate
3117 // checking can be done. The only other logic we need to introduce is that if a Date/Time
3118 // op-code is the last entry in the menu, we need to rewind back to the first op-code of
3119 // the Date/Time op-code.
3120 //
3121 SavedListEntry = NewPos;
3122 AdjustDateAndTimePosition (FALSE, &NewPos);
3123
3124 if (NewPos->ForwardLink != &gMenuOption) {
3125 if (NewPos == TopOfScreen) {
3126 Temp2 = SkipValue;
3127 } else {
3128 Temp2 = 0;
3129 }
3130
3131 MenuOption = MENU_OPTION_FROM_LINK (NewPos);
3132 NewLine = TRUE;
3133 NewPos = NewPos->ForwardLink;
3134
3135 Difference = 0;
3136 //
3137 // Current menu not at the bottom of the form.
3138 //
3139 if (BottomRow >= MenuOption->Row + MenuOption->Skip - Temp2) {
3140 //
3141 // Find the next selectable menu.
3142 //
3143 Difference = MoveToNextStatement (FALSE, &NewPos, BottomRow - MenuOption->Row - MenuOption->Skip + Temp2);
3144 //
3145 // We hit the end of MenuOption that can be focused
3146 // so we simply scroll to the first page.
3147 //
3148 if (Difference < 0) {
3149 //
3150 // Scroll to the first page.
3151 //
3152 if (TopOfScreen != gMenuOption.ForwardLink) {
3153 TopOfScreen = gMenuOption.ForwardLink;
3154 Repaint = TRUE;
3155 MenuOption = NULL;
3156 } else {
3157 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
3158 }
3159 NewPos = gMenuOption.ForwardLink;
3160 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);
3161
3162 SkipValue = 0;
3163 //
3164 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
3165 //
3166 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3167 AdjustDateAndTimePosition (TRUE, &NewPos);
3168 break;
3169 }
3170 }
3171 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);
3172 if (NextMenuOption->Row == 0) {
3173 UpdateOptionSkipLines (NextMenuOption);
3174 }
3175 DistanceValue = Difference + NextMenuOption->Skip - Temp2;
3176
3177 Temp = MenuOption->Row + MenuOption->Skip + DistanceValue - 1;
3178 if ((MenuOption->Row + MenuOption->Skip - Temp2 == BottomRow + 1) &&
3179 (NextMenuOption->ThisTag->OpCode->OpCode == EFI_IFR_DATE_OP ||
3180 NextMenuOption->ThisTag->OpCode->OpCode == EFI_IFR_TIME_OP)
3181 ) {
3182 Temp ++;
3183 }
3184
3185 //
3186 // If we are going to scroll, update TopOfScreen
3187 //
3188 if (Temp > BottomRow) {
3189 do {
3190 //
3191 // Is the current top of screen a zero-advance op-code?
3192 // If so, keep moving forward till we hit a >0 advance op-code
3193 //
3194 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
3195
3196 //
3197 // If bottom op-code is more than one line or top op-code is more than one line
3198 //
3199 if ((DistanceValue > 1) || (SavedMenuOption->Skip > 1)) {
3200 //
3201 // Is the bottom op-code greater than or equal in size to the top op-code?
3202 //
3203 if ((Temp - BottomRow) >= (SavedMenuOption->Skip - SkipValue)) {
3204 //
3205 // Skip the top op-code
3206 //
3207 TopOfScreen = TopOfScreen->ForwardLink;
3208 Difference = (Temp - BottomRow) - (SavedMenuOption->Skip - SkipValue);
3209
3210 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
3211
3212 //
3213 // If we have a remainder, skip that many more op-codes until we drain the remainder
3214 //
3215 while (Difference >= (INTN) SavedMenuOption->Skip) {
3216 //
3217 // Since the Difference is greater than or equal to this op-code's skip value, skip it
3218 //
3219 Difference = Difference - (INTN) SavedMenuOption->Skip;
3220 TopOfScreen = TopOfScreen->ForwardLink;
3221 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);
3222 }
3223 //
3224 // Since we will act on this op-code in the next routine, and increment the
3225 // SkipValue, set the skips to one less than what is required.
3226 //
3227 SkipValue = Difference - 1;
3228 } else {
3229 //
3230 // Since we will act on this op-code in the next routine, and increment the
3231 // SkipValue, set the skips to one less than what is required.
3232 //
3233 SkipValue += (Temp - BottomRow) - 1;
3234 }
3235 } else {
3236 if ((SkipValue + 1) == (INTN) SavedMenuOption->Skip) {
3237 TopOfScreen = TopOfScreen->ForwardLink;
3238 break;
3239 }
3240 }
3241 //
3242 // If the op-code at the top of the screen is more than one line, let's not skip it yet
3243 // Let's set a skip flag to smoothly scroll the top of the screen.
3244 //
3245 if (SavedMenuOption->Skip > 1) {
3246 if (SavedMenuOption == NextMenuOption) {
3247 SkipValue = 0;
3248 } else {
3249 SkipValue++;
3250 }
3251 } else if (SavedMenuOption->Skip == 1) {
3252 SkipValue = 0;
3253 } else {
3254 SkipValue = 0;
3255 TopOfScreen = TopOfScreen->ForwardLink;
3256 }
3257 } while (SavedMenuOption->Skip == 0);
3258
3259 Repaint = TRUE;
3260 } else if (!IsSelectable (NextMenuOption)) {
3261 //
3262 // Continue to go down until scroll to next page or the selectable option is found.
3263 //
3264 ScreenOperation = UiDown;
3265 ControlFlag = CfScreenOperation;
3266 }
3267
3268 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
3269
3270 UpdateStatusBar (INPUT_ERROR, FALSE);
3271
3272 } else {
3273 //
3274 // Scroll to the first page.
3275 //
3276 if (TopOfScreen != gMenuOption.ForwardLink || SkipValue != 0) {
3277 TopOfScreen = gMenuOption.ForwardLink;
3278 Repaint = TRUE;
3279 MenuOption = NULL;
3280 } else {
3281 //
3282 // Need to remove the current highlight menu.
3283 // MenuOption saved the last highlight menu info.
3284 //
3285 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);
3286 }
3287
3288 SkipValue = 0;
3289 NewLine = TRUE;
3290 //
3291 // Get the next highlight menu.
3292 //
3293 NewPos = gMenuOption.ForwardLink;
3294 MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);
3295 }
3296
3297 //
3298 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.
3299 //
3300 AdjustDateAndTimePosition (TRUE, &TopOfScreen);
3301 AdjustDateAndTimePosition (TRUE, &NewPos);
3302 break;
3303
3304 case CfUiNoOperation:
3305 ControlFlag = CfRepaint;
3306 break;
3307
3308 case CfExit:
3309 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
3310 if (HelpString != NULL) {
3311 FreePool (HelpString);
3312 }
3313 if (HelpHeaderString != NULL) {
3314 FreePool (HelpHeaderString);
3315 }
3316 if (HelpBottomString != NULL) {
3317 FreePool (HelpBottomString);
3318 }
3319 return EFI_SUCCESS;
3320
3321 default:
3322 break;
3323 }
3324 }
3325 }
3326
3327 /**
3328
3329 Base on the browser status info to show an pop up message.
3330
3331 **/
3332 VOID
3333 BrowserStatusProcess (
3334 VOID
3335 )
3336 {
3337 CHAR16 *ErrorInfo;
3338 EFI_INPUT_KEY Key;
3339
3340 if (gFormData->BrowserStatus == BROWSER_SUCCESS) {
3341 return;
3342 }
3343
3344 if (gFormData->ErrorString != NULL) {
3345 ErrorInfo = gFormData->ErrorString;
3346 } else {
3347 switch (gFormData->BrowserStatus) {
3348 case BROWSER_SUBMIT_FAIL:
3349 ErrorInfo = gSaveFailed;
3350 break;
3351
3352 case BROWSER_NO_SUBMIT_IF:
3353 ErrorInfo = gNoSubmitIf;
3354 break;
3355
3356 case BROWSER_FORM_NOT_FOUND:
3357 ErrorInfo = gFormNotFound;
3358 break;
3359
3360 case BROWSER_FORM_SUPPRESS:
3361 ErrorInfo = gFormSuppress;
3362 break;
3363
3364 case BROWSER_PROTOCOL_NOT_FOUND:
3365 ErrorInfo = gProtocolNotFound;
3366 break;
3367
3368 default:
3369 ErrorInfo = gBrwoserError;
3370 break;
3371 }
3372 }
3373
3374 //
3375 // Error occur, prompt error message.
3376 //
3377 do {
3378 CreateDialog (&Key, gEmptyString, ErrorInfo, gPressEnter, gEmptyString, NULL);
3379 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);
3380 }
3381
3382 /**
3383 Display one form, and return user input.
3384
3385 @param FormData Form Data to be shown.
3386 @param UserInputData User input data.
3387
3388 @retval EFI_SUCCESS 1.Form Data is shown, and user input is got.
3389 2.Error info has show and return.
3390 @retval EFI_INVALID_PARAMETER The input screen dimension is not valid
3391 @retval EFI_NOT_FOUND New form data has some error.
3392 **/
3393 EFI_STATUS
3394 EFIAPI
3395 FormDisplay (
3396 IN FORM_DISPLAY_ENGINE_FORM *FormData,
3397 OUT USER_INPUT *UserInputData
3398 )
3399 {
3400 EFI_STATUS Status;
3401
3402 ASSERT (FormData != NULL);
3403 if (FormData == NULL) {
3404 return EFI_INVALID_PARAMETER;
3405 }
3406
3407 gUserInput = UserInputData;
3408 gFormData = FormData;
3409
3410 //
3411 // Process the status info first.
3412 //
3413 BrowserStatusProcess();
3414 if (UserInputData == NULL) {
3415 //
3416 // UserInputData == NULL, means only need to print the error info, return here.
3417 //
3418 return EFI_SUCCESS;
3419 }
3420
3421 ConvertStatementToMenu();
3422
3423 Status = DisplayPageFrame (FormData, &gStatementDimensions);
3424 if (EFI_ERROR (Status)) {
3425 return Status;
3426 }
3427
3428 //
3429 // Check whether layout is changed.
3430 //
3431 if (mIsFirstForm
3432 || (gOldFormEntry.HiiHandle != FormData->HiiHandle)
3433 || (!CompareGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid))
3434 || (gOldFormEntry.FormId != FormData->FormId)) {
3435 mStatementLayoutIsChanged = TRUE;
3436 } else {
3437 mStatementLayoutIsChanged = FALSE;
3438 }
3439
3440 Status = UiDisplayMenu(FormData);
3441
3442 //
3443 // Backup last form info.
3444 //
3445 mIsFirstForm = FALSE;
3446 gOldFormEntry.HiiHandle = FormData->HiiHandle;
3447 CopyGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid);
3448 gOldFormEntry.FormId = FormData->FormId;
3449
3450 return Status;
3451 }
3452
3453 /**
3454 Clear Screen to the initial state.
3455 **/
3456 VOID
3457 EFIAPI
3458 DriverClearDisplayPage (
3459 VOID
3460 )
3461 {
3462 ClearDisplayPage ();
3463 mIsFirstForm = TRUE;
3464 }
3465
3466 /**
3467 Set Buffer to Value for Size bytes.
3468
3469 @param Buffer Memory to set.
3470 @param Size Number of bytes to set
3471 @param Value Value of the set operation.
3472
3473 **/
3474 VOID
3475 SetUnicodeMem (
3476 IN VOID *Buffer,
3477 IN UINTN Size,
3478 IN CHAR16 Value
3479 )
3480 {
3481 CHAR16 *Ptr;
3482
3483 Ptr = Buffer;
3484 while ((Size--) != 0) {
3485 *(Ptr++) = Value;
3486 }
3487 }
3488
3489 /**
3490 Initialize Setup Browser driver.
3491
3492 @param ImageHandle The image handle.
3493 @param SystemTable The system table.
3494
3495 @retval EFI_SUCCESS The Setup Browser module is initialized correctly..
3496 @return Other value if failed to initialize the Setup Browser module.
3497
3498 **/
3499 EFI_STATUS
3500 EFIAPI
3501 InitializeDisplayEngine (
3502 IN EFI_HANDLE ImageHandle,
3503 IN EFI_SYSTEM_TABLE *SystemTable
3504 )
3505 {
3506 EFI_STATUS Status;
3507 EFI_INPUT_KEY HotKey;
3508 EFI_STRING NewString;
3509 EDKII_FORM_BROWSER_EXTENSION2_PROTOCOL *FormBrowserEx2;
3510
3511 //
3512 // Publish our HII data
3513 //
3514 gHiiHandle = HiiAddPackages (
3515 &gDisplayEngineGuid,
3516 ImageHandle,
3517 DisplayEngineStrings,
3518 NULL
3519 );
3520 ASSERT (gHiiHandle != NULL);
3521
3522 //
3523 // Install Form Display protocol
3524 //
3525 Status = gBS->InstallProtocolInterface (
3526 &mPrivateData.Handle,
3527 &gEdkiiFormDisplayEngineProtocolGuid,
3528 EFI_NATIVE_INTERFACE,
3529 &mPrivateData.FromDisplayProt
3530 );
3531 ASSERT_EFI_ERROR (Status);
3532
3533 InitializeDisplayStrings();
3534
3535 ZeroMem (&gHighligthMenuInfo, sizeof (gHighligthMenuInfo));
3536 ZeroMem (&gOldFormEntry, sizeof (gOldFormEntry));
3537
3538 //
3539 // Use BrowserEx2 protocol to register HotKey.
3540 //
3541 Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **) &FormBrowserEx2);
3542 if (!EFI_ERROR (Status)) {
3543 //
3544 // Register the default HotKey F9 and F10 again.
3545 //
3546 HotKey.UnicodeChar = CHAR_NULL;
3547 HotKey.ScanCode = SCAN_F10;
3548 NewString = HiiGetString (gHiiHandle, STRING_TOKEN (FUNCTION_TEN_STRING), NULL);
3549 ASSERT (NewString != NULL);
3550 FormBrowserEx2->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);
3551
3552 HotKey.ScanCode = SCAN_F9;
3553 NewString = HiiGetString (gHiiHandle, STRING_TOKEN (FUNCTION_NINE_STRING), NULL);
3554 ASSERT (NewString != NULL);
3555 FormBrowserEx2->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);
3556 }
3557
3558 return EFI_SUCCESS;
3559 }
3560
3561 /**
3562 This is the default unload handle for display core drivers.
3563
3564 @param[in] ImageHandle The drivers' driver image.
3565
3566 @retval EFI_SUCCESS The image is unloaded.
3567 @retval Others Failed to unload the image.
3568
3569 **/
3570 EFI_STATUS
3571 EFIAPI
3572 UnloadDisplayEngine (
3573 IN EFI_HANDLE ImageHandle
3574 )
3575 {
3576 HiiRemovePackages(gHiiHandle);
3577
3578 FreeDisplayStrings ();
3579
3580 return EFI_SUCCESS;
3581 }