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