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