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