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