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