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