]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
rename
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
CommitLineData
7936fb6a 1/** @file\r
2Utility functions for User Interface functions.\r
3\r
4Copyright (c) 2004 - 2007, Intel Corporation\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Ui.h"\r
16#include "Setup.h"\r
17\r
18LIST_ENTRY Menu;\r
19LIST_ENTRY gMenuList;\r
20MENU_REFRESH_ENTRY *gMenuRefreshHead;\r
21\r
22//\r
23// Search table for UiDisplayMenu()\r
24//\r
25SCAN_CODE_TO_SCREEN_OPERATION gScanCodeToOperation[] = {\r
26 {\r
27 SCAN_UP,\r
28 UiUp,\r
29 },\r
30 {\r
31 SCAN_DOWN,\r
32 UiDown,\r
33 },\r
34 {\r
35 SCAN_PAGE_UP,\r
36 UiPageUp,\r
37 },\r
38 {\r
39 SCAN_PAGE_DOWN,\r
40 UiPageDown,\r
41 },\r
42 {\r
43 SCAN_ESC,\r
44 UiReset,\r
45 },\r
46 {\r
47 SCAN_F2,\r
48 UiPrevious,\r
49 },\r
50 {\r
51 SCAN_LEFT,\r
52 UiLeft,\r
53 },\r
54 {\r
55 SCAN_RIGHT,\r
56 UiRight,\r
57 },\r
58 {\r
59 SCAN_F9,\r
60 UiDefault,\r
61 },\r
62 {\r
63 SCAN_F10,\r
64 UiSave\r
65 }\r
66};\r
67\r
68SCREEN_OPERATION_T0_CONTROL_FLAG gScreenOperationToControlFlag[] = {\r
69 {\r
70 UiNoOperation,\r
71 CfUiNoOperation,\r
72 },\r
73 {\r
74 UiDefault,\r
75 CfUiDefault,\r
76 },\r
77 {\r
78 UiSelect,\r
79 CfUiSelect,\r
80 },\r
81 {\r
82 UiUp,\r
83 CfUiUp,\r
84 },\r
85 {\r
86 UiDown,\r
87 CfUiDown,\r
88 },\r
89 {\r
90 UiLeft,\r
91 CfUiLeft,\r
92 },\r
93 {\r
94 UiRight,\r
95 CfUiRight,\r
96 },\r
97 {\r
98 UiReset,\r
99 CfUiReset,\r
100 },\r
101 {\r
102 UiSave,\r
103 CfUiSave,\r
104 },\r
105 {\r
106 UiPrevious,\r
107 CfUiPrevious,\r
108 },\r
109 {\r
110 UiPageUp,\r
111 CfUiPageUp,\r
112 },\r
113 {\r
114 UiPageDown,\r
115 CfUiPageDown\r
116 }\r
117};\r
118\r
119\r
120/**\r
121 Set Buffer to Value for Size bytes.\r
122\r
123 @param Buffer Memory to set.\r
124 @param Size Number of bytes to set\r
125 @param Value Value of the set operation.\r
126\r
127**/\r
128VOID\r
129SetUnicodeMem (\r
130 IN VOID *Buffer,\r
131 IN UINTN Size,\r
132 IN CHAR16 Value\r
133 )\r
134{\r
135 CHAR16 *Ptr;\r
136\r
137 Ptr = Buffer;\r
138 while ((Size--) != 0) {\r
139 *(Ptr++) = Value;\r
140 }\r
141}\r
142\r
143\r
144/**\r
145 Initialize Menu option list.\r
146\r
147**/\r
148VOID\r
149UiInitMenu (\r
150 VOID\r
151 )\r
152{\r
153 InitializeListHead (&Menu);\r
154}\r
155\r
156\r
157/**\r
158 Initialize Menu option list.\r
159\r
160**/\r
161VOID\r
162UiInitMenuList (\r
163 VOID\r
164 )\r
165{\r
166 InitializeListHead (&gMenuList);\r
167}\r
168\r
169\r
170/**\r
171 Remove a Menu in list, and return FormId/QuestionId for previous Menu.\r
172\r
173 @param Selection Menu selection.\r
174\r
175**/\r
176VOID\r
177UiRemoveMenuListEntry (\r
178 OUT UI_MENU_SELECTION *Selection\r
179 )\r
180{\r
181 UI_MENU_LIST *UiMenuList;\r
182\r
183 if (!IsListEmpty (&gMenuList)) {\r
184 UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);\r
185\r
186 Selection->FormId = UiMenuList->FormId;\r
187 Selection->QuestionId = UiMenuList->QuestionId;\r
188 RemoveEntryList (&UiMenuList->MenuLink);\r
189 gBS->FreePool (UiMenuList);\r
190 }\r
191}\r
192\r
193\r
194/**\r
195 Free Menu option linked list.\r
196\r
197**/\r
198VOID\r
199UiFreeMenuList (\r
200 VOID\r
201 )\r
202{\r
203 UI_MENU_LIST *UiMenuList;\r
204\r
205 while (!IsListEmpty (&gMenuList)) {\r
206 UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);\r
207 RemoveEntryList (&UiMenuList->MenuLink);\r
208 gBS->FreePool (UiMenuList);\r
209 }\r
210}\r
211\r
212\r
213/**\r
214 Add one menu entry to the linked lst\r
215\r
216 @param Selection Menu selection.\r
217\r
218**/\r
219VOID\r
220UiAddMenuListEntry (\r
221 IN UI_MENU_SELECTION *Selection\r
222 )\r
223{\r
224 UI_MENU_LIST *UiMenuList;\r
225\r
226 UiMenuList = AllocateZeroPool (sizeof (UI_MENU_LIST));\r
227 ASSERT (UiMenuList != NULL);\r
228\r
229 UiMenuList->Signature = UI_MENU_LIST_SIGNATURE;\r
230 UiMenuList->FormId = Selection->FormId;\r
231 UiMenuList->QuestionId = Selection->QuestionId;\r
232\r
233 InsertHeadList (&gMenuList, &UiMenuList->MenuLink);\r
234}\r
235\r
236\r
237/**\r
238 Free Menu option linked list.\r
239\r
240**/\r
241VOID\r
242UiFreeMenu (\r
243 VOID\r
244 )\r
245{\r
246 UI_MENU_OPTION *MenuOption;\r
247\r
248 while (!IsListEmpty (&Menu)) {\r
249 MenuOption = MENU_OPTION_FROM_LINK (Menu.ForwardLink);\r
250 RemoveEntryList (&MenuOption->Link);\r
251\r
252 //\r
253 // We allocated space for this description when we did a GetToken, free it here\r
254 //\r
255 if (MenuOption->Skip != 0) {\r
256 //\r
257 // For date/time, MenuOption->Description is shared by three Menu Options\r
258 // Data format : [01/02/2004] [11:22:33]\r
259 // Line number : 0 0 1 0 0 1\r
260 //\r
261 gBS->FreePool (MenuOption->Description);\r
262 }\r
263 gBS->FreePool (MenuOption);\r
264 }\r
265}\r
266\r
267\r
268/**\r
269 Free Menu option linked list.\r
270\r
271**/\r
272VOID\r
273UiFreeRefreshList (\r
274 VOID\r
275 )\r
276{\r
277 MENU_REFRESH_ENTRY *OldMenuRefreshEntry;\r
278\r
279 while (gMenuRefreshHead != NULL) {\r
280 OldMenuRefreshEntry = gMenuRefreshHead->Next;\r
281 gBS->FreePool (gMenuRefreshHead);\r
282 gMenuRefreshHead = OldMenuRefreshEntry;\r
283 }\r
284\r
285 gMenuRefreshHead = NULL;\r
286}\r
287\r
288\r
289\r
290/**\r
291 Refresh screen.\r
292\r
293**/\r
294VOID\r
295RefreshForm (\r
296 VOID\r
297 )\r
298{\r
299 CHAR16 *OptionString;\r
300 MENU_REFRESH_ENTRY *MenuRefreshEntry;\r
301 UINTN Index;\r
302 UINTN Loop;\r
303 EFI_STATUS Status;\r
304 UI_MENU_SELECTION *Selection;\r
305 FORM_BROWSER_STATEMENT *Question;\r
306\r
307 OptionString = NULL;\r
308\r
309 if (gMenuRefreshHead != NULL) {\r
310\r
311 MenuRefreshEntry = gMenuRefreshHead;\r
312\r
313 do {\r
314 gST->ConOut->SetAttribute (gST->ConOut, MenuRefreshEntry->CurrentAttribute);\r
315\r
316 Selection = MenuRefreshEntry->Selection;\r
317 Question = MenuRefreshEntry->MenuOption->ThisTag;\r
318\r
319 //\r
320 // Don't update Question being edited\r
321 //\r
322 if (Question != MenuRefreshEntry->Selection->Statement) {\r
323\r
324 Status = GetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);\r
325 if (EFI_ERROR (Status)) {\r
326 return;\r
327 }\r
328\r
329 ProcessOptions (Selection, MenuRefreshEntry->MenuOption, FALSE, &OptionString);\r
330\r
331 if (OptionString != NULL) {\r
332 //\r
333 // If leading spaces on OptionString - remove the spaces\r
334 //\r
335 for (Index = 0; OptionString[Index] == L' '; Index++)\r
336 ;\r
337\r
338 for (Loop = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
339 OptionString[Loop] = OptionString[Index];\r
340 Loop++;\r
341 }\r
342\r
343 OptionString[Loop] = CHAR_NULL;\r
344\r
345 PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, OptionString);\r
346 gBS->FreePool (OptionString);\r
347 }\r
348 }\r
349\r
350 MenuRefreshEntry = MenuRefreshEntry->Next;\r
351\r
352 } while (MenuRefreshEntry != NULL);\r
353 }\r
354}\r
355\r
356\r
357/**\r
358 Wait for a given event to fire, or for an optional timeout to expire.\r
359\r
360 @param Event The event to wait for\r
361 @param Timeout An optional timeout value in 100 ns units.\r
362 @param RefreshInterval Menu refresh interval (in seconds).\r
363\r
364 @retval EFI_SUCCESS Event fired before Timeout expired.\r
365 @retval EFI_TIME_OUT Timout expired before Event fired.\r
366\r
367**/\r
368EFI_STATUS\r
369UiWaitForSingleEvent (\r
370 IN EFI_EVENT Event,\r
371 IN UINT64 Timeout, OPTIONAL\r
372 IN UINT8 RefreshInterval OPTIONAL\r
373 )\r
374{\r
375 EFI_STATUS Status;\r
376 UINTN Index;\r
377 EFI_EVENT TimerEvent;\r
378 EFI_EVENT WaitList[2];\r
379\r
380 if (Timeout != 0) {\r
381 //\r
382 // Create a timer event\r
383 //\r
384 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
385 if (!EFI_ERROR (Status)) {\r
386 //\r
387 // Set the timer event\r
388 //\r
389 gBS->SetTimer (\r
390 TimerEvent,\r
391 TimerRelative,\r
392 Timeout\r
393 );\r
394\r
395 //\r
396 // Wait for the original event or the timer\r
397 //\r
398 WaitList[0] = Event;\r
399 WaitList[1] = TimerEvent;\r
400 Status = gBS->WaitForEvent (2, WaitList, &Index);\r
401 gBS->CloseEvent (TimerEvent);\r
402\r
403 //\r
404 // If the timer expired, change the return to timed out\r
405 //\r
406 if (!EFI_ERROR (Status) && Index == 1) {\r
407 Status = EFI_TIMEOUT;\r
408 }\r
409 }\r
410 } else {\r
411 //\r
412 // Update screen every second\r
413 //\r
414 if (RefreshInterval == 0) {\r
415 Timeout = ONE_SECOND;\r
416 } else {\r
417 Timeout = RefreshInterval * ONE_SECOND;\r
418 }\r
419\r
420 do {\r
421 Status = gBS->CreateEvent (EVT_TIMER, 0, NULL, NULL, &TimerEvent);\r
422\r
423 //\r
424 // Set the timer event\r
425 //\r
426 gBS->SetTimer (\r
427 TimerEvent,\r
428 TimerRelative,\r
429 Timeout\r
430 );\r
431\r
432 //\r
433 // Wait for the original event or the timer\r
434 //\r
435 WaitList[0] = Event;\r
436 WaitList[1] = TimerEvent;\r
437 Status = gBS->WaitForEvent (2, WaitList, &Index);\r
438\r
439 //\r
440 // If the timer expired, update anything that needs a refresh and keep waiting\r
441 //\r
442 if (!EFI_ERROR (Status) && Index == 1) {\r
443 Status = EFI_TIMEOUT;\r
444 if (RefreshInterval != 0) {\r
445 RefreshForm ();\r
446 }\r
447 }\r
448\r
449 gBS->CloseEvent (TimerEvent);\r
450 } while (Status == EFI_TIMEOUT);\r
451 }\r
452\r
453 return Status;\r
454}\r
455\r
456\r
457/**\r
458 Add one menu option by specified description and context.\r
459\r
460 @param String String description for this option.\r
461 @param Handle Hii handle for the package list.\r
462 @param Statement Statement of this Menu Option.\r
463 @param NumberOfLines Display lines for this Menu Option.\r
464 @param MenuItemCount The index for this Option in the Menu.\r
465\r
466**/\r
467VOID\r
468UiAddMenuOption (\r
469 IN CHAR16 *String,\r
470 IN EFI_HII_HANDLE Handle,\r
471 IN FORM_BROWSER_STATEMENT *Statement,\r
472 IN UINT16 NumberOfLines,\r
473 IN UINT16 MenuItemCount\r
474 )\r
475{\r
476 UI_MENU_OPTION *MenuOption;\r
477 UINTN Index;\r
478 UINTN Count;\r
479\r
480 Count = 1;\r
481\r
482 if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {\r
483 //\r
484 // Add three MenuOptions for Date/Time\r
485 // Data format : [01/02/2004] [11:22:33]\r
486 // Line number : 0 0 1 0 0 1\r
487 //\r
488 NumberOfLines = 0;\r
489 Count = 3;\r
490\r
491 if (Statement->Storage == NULL) {\r
492 //\r
493 // For RTC type of date/time, set default refresh interval to be 1 second\r
494 //\r
495 if (Statement->RefreshInterval == 0) {\r
496 Statement->RefreshInterval = 1;\r
497 }\r
498 }\r
499 }\r
500\r
501 for (Index = 0; Index < Count; Index++) {\r
502 MenuOption = AllocateZeroPool (sizeof (UI_MENU_OPTION));\r
503 ASSERT (MenuOption);\r
504\r
505 MenuOption->Signature = UI_MENU_OPTION_SIGNATURE;\r
506 MenuOption->Description = String;\r
507 MenuOption->Handle = Handle;\r
508 MenuOption->ThisTag = Statement;\r
509 MenuOption->EntryNumber = MenuItemCount;\r
510\r
511 if (Index == 2) {\r
512 //\r
513 // Override LineNumber for the MenuOption in Date/Time sequence\r
514 //\r
515 MenuOption->Skip = 1;\r
516 } else {\r
517 MenuOption->Skip = NumberOfLines;\r
518 }\r
519 MenuOption->Sequence = Index;\r
520\r
521 if (Statement->GrayOutExpression != NULL) {\r
522 MenuOption->GrayOut = Statement->GrayOutExpression->Result.Value.b;\r
523 }\r
524\r
525 if ((Statement->ValueExpression != NULL) ||\r
526 ((Statement->QuestionFlags & EFI_IFR_FLAG_READ_ONLY) != 0)) {\r
527 MenuOption->ReadOnly = TRUE;\r
528 }\r
529\r
530 InsertTailList (&Menu, &MenuOption->Link);\r
531 }\r
532}\r
533\r
534\r
535/**\r
536 Routine used to abstract a generic dialog interface and return the selected key or string\r
537\r
538 @param NumberOfLines The number of lines for the dialog box\r
539 @param HotKey Defines whether a single character is parsed\r
540 (TRUE) and returned in KeyValue or a string is\r
541 returned in StringBuffer. Two special characters\r
542 are considered when entering a string, a SCAN_ESC\r
543 and an CHAR_CARRIAGE_RETURN. SCAN_ESC terminates\r
544 string input and returns\r
545 @param MaximumStringSize The maximum size in bytes of a typed in string\r
546 (each character is a CHAR16) and the minimum\r
547 string returned is two bytes\r
548 @param StringBuffer The passed in pointer to the buffer which will\r
549 hold the typed in string if HotKey is FALSE\r
550 @param KeyValue The EFI_KEY value returned if HotKey is TRUE..\r
551 @param String Pointer to the first string in the list\r
552 @param ... A series of (quantity == NumberOfLines) text\r
553 strings which will be used to construct the dialog\r
554 box\r
555\r
556 @retval EFI_SUCCESS Displayed dialog and received user interaction\r
557 @retval EFI_INVALID_PARAMETER One of the parameters was invalid (e.g.\r
558 (StringBuffer == NULL) && (HotKey == FALSE))\r
559 @retval EFI_DEVICE_ERROR User typed in an ESC character to exit the routine\r
560\r
561**/\r
562EFI_STATUS\r
563CreateDialog (\r
564 IN UINTN NumberOfLines,\r
565 IN BOOLEAN HotKey,\r
566 IN UINTN MaximumStringSize,\r
567 OUT CHAR16 *StringBuffer,\r
568 OUT EFI_INPUT_KEY *KeyValue,\r
569 IN CHAR16 *String,\r
570 ...\r
571 )\r
572{\r
573 VA_LIST Marker;\r
574 UINTN Count;\r
575 EFI_INPUT_KEY Key;\r
576 UINTN LargestString;\r
577 CHAR16 *TempString;\r
578 CHAR16 *BufferedString;\r
579 CHAR16 *StackString;\r
580 CHAR16 KeyPad[2];\r
581 UINTN Start;\r
582 UINTN Top;\r
583 UINTN Index;\r
584 EFI_STATUS Status;\r
585 BOOLEAN SelectionComplete;\r
586 UINTN InputOffset;\r
587 UINTN CurrentAttribute;\r
588 UINTN DimensionsWidth;\r
589 UINTN DimensionsHeight;\r
590\r
591 DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
592 DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;\r
593\r
594 SelectionComplete = FALSE;\r
595 InputOffset = 0;\r
596 TempString = AllocateZeroPool (MaximumStringSize * 2);\r
597 BufferedString = AllocateZeroPool (MaximumStringSize * 2);\r
598 CurrentAttribute = gST->ConOut->Mode->Attribute;\r
599\r
600 ASSERT (TempString);\r
601 ASSERT (BufferedString);\r
602\r
603 VA_START (Marker, String);\r
604\r
605 //\r
606 // Zero the outgoing buffer\r
607 //\r
608 ZeroMem (StringBuffer, MaximumStringSize);\r
609\r
610 if (HotKey) {\r
611 if (KeyValue == NULL) {\r
612 return EFI_INVALID_PARAMETER;\r
613 }\r
614 } else {\r
615 if (StringBuffer == NULL) {\r
616 return EFI_INVALID_PARAMETER;\r
617 }\r
618 }\r
619 //\r
620 // Disable cursor\r
621 //\r
622 gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
623\r
624 LargestString = (GetStringWidth (String) / 2);\r
625\r
626 if (*String == L' ') {\r
627 InputOffset = 1;\r
628 }\r
629 //\r
630 // Determine the largest string in the dialog box\r
631 // Notice we are starting with 1 since String is the first string\r
632 //\r
633 for (Count = 1; Count < NumberOfLines; Count++) {\r
634 StackString = VA_ARG (Marker, CHAR16 *);\r
635\r
636 if (StackString[0] == L' ') {\r
637 InputOffset = Count + 1;\r
638 }\r
639\r
640 if ((GetStringWidth (StackString) / 2) > LargestString) {\r
641 //\r
642 // Size of the string visually and subtract the width by one for the null-terminator\r
643 //\r
644 LargestString = (GetStringWidth (StackString) / 2);\r
645 }\r
646 }\r
647\r
648 Start = (DimensionsWidth - LargestString - 2) / 2 + gScreenDimensions.LeftColumn + 1;\r
649 Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1;\r
650\r
651 Count = 0;\r
652\r
653 //\r
654 // Display the Popup\r
655 //\r
656 CreateSharedPopUp (LargestString, NumberOfLines, &String);\r
657\r
658 //\r
659 // Take the first key typed and report it back?\r
660 //\r
661 if (HotKey) {\r
662 Status = WaitForKeyStroke (&Key);\r
663 ASSERT_EFI_ERROR (Status);\r
664 CopyMem (KeyValue, &Key, sizeof (EFI_INPUT_KEY));\r
665\r
666 } else {\r
667 do {\r
668 Status = WaitForKeyStroke (&Key);\r
669\r
670 switch (Key.UnicodeChar) {\r
671 case CHAR_NULL:\r
672 switch (Key.ScanCode) {\r
673 case SCAN_ESC:\r
674 gBS->FreePool (TempString);\r
675 gBS->FreePool (BufferedString);\r
676 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
677 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
678 return EFI_DEVICE_ERROR;\r
679\r
680 default:\r
681 break;\r
682 }\r
683\r
684 break;\r
685\r
686 case CHAR_CARRIAGE_RETURN:\r
687 SelectionComplete = TRUE;\r
688 gBS->FreePool (TempString);\r
689 gBS->FreePool (BufferedString);\r
690 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
691 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
692 return EFI_SUCCESS;\r
693 break;\r
694\r
695 case CHAR_BACKSPACE:\r
696 if (StringBuffer[0] != CHAR_NULL) {\r
697 for (Index = 0; StringBuffer[Index] != CHAR_NULL; Index++) {\r
698 TempString[Index] = StringBuffer[Index];\r
699 }\r
700 //\r
701 // Effectively truncate string by 1 character\r
702 //\r
703 TempString[Index - 1] = CHAR_NULL;\r
704 StrCpy (StringBuffer, TempString);\r
705 }\r
706\r
707 default:\r
708 //\r
709 // If it is the beginning of the string, don't worry about checking maximum limits\r
710 //\r
711 if ((StringBuffer[0] == CHAR_NULL) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
712 StrnCpy (StringBuffer, &Key.UnicodeChar, 1);\r
713 StrnCpy (TempString, &Key.UnicodeChar, 1);\r
714 } else if ((GetStringWidth (StringBuffer) < MaximumStringSize) && (Key.UnicodeChar != CHAR_BACKSPACE)) {\r
715 KeyPad[0] = Key.UnicodeChar;\r
716 KeyPad[1] = CHAR_NULL;\r
717 StrCat (StringBuffer, KeyPad);\r
718 StrCat (TempString, KeyPad);\r
719 }\r
720 //\r
721 // If the width of the input string is now larger than the screen, we nee to\r
722 // adjust the index to start printing portions of the string\r
723 //\r
724 SetUnicodeMem (BufferedString, LargestString, L' ');\r
725\r
726 PrintStringAt (Start + 1, Top + InputOffset, BufferedString);\r
727\r
728 if ((GetStringWidth (StringBuffer) / 2) > (DimensionsWidth - 2)) {\r
729 Index = (GetStringWidth (StringBuffer) / 2) - DimensionsWidth + 2;\r
730 } else {\r
731 Index = 0;\r
732 }\r
733\r
734 for (Count = 0; Index + 1 < GetStringWidth (StringBuffer) / 2; Index++, Count++) {\r
735 BufferedString[Count] = StringBuffer[Index];\r
736 }\r
737\r
738 PrintStringAt (Start + 1, Top + InputOffset, BufferedString);\r
739 break;\r
740 }\r
741 } while (!SelectionComplete);\r
742 }\r
743\r
744 gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
745 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
746 return EFI_SUCCESS;\r
747}\r
748\r
749/**\r
750 Draw a pop up windows based on the dimension, number of lines and\r
751 strings specified.\r
752\r
753 @param RequestedWidth The width of the pop-up.\r
754 @param NumberOfLines The number of lines.\r
755 @param ArrayOfStrings The array of string to be printed.\r
756\r
757**/\r
758VOID\r
759CreateSharedPopUp (\r
760 IN UINTN RequestedWidth,\r
761 IN UINTN NumberOfLines,\r
762 IN CHAR16 **ArrayOfStrings\r
763 )\r
764{\r
765 UINTN Index;\r
766 UINTN Count;\r
767 CHAR16 Character;\r
768 UINTN Start;\r
769 UINTN End;\r
770 UINTN Top;\r
771 UINTN Bottom;\r
772 CHAR16 *String;\r
773 UINTN DimensionsWidth;\r
774 UINTN DimensionsHeight;\r
775\r
776 DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;\r
777 DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;\r
778\r
779 Count = 0;\r
780\r
781 gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
782\r
783 if ((RequestedWidth + 2) > DimensionsWidth) {\r
784 RequestedWidth = DimensionsWidth - 2;\r
785 }\r
786\r
787 //\r
788 // Subtract the PopUp width from total Columns, allow for one space extra on\r
789 // each end plus a border.\r
790 //\r
791 Start = (DimensionsWidth - RequestedWidth - 2) / 2 + gScreenDimensions.LeftColumn + 1;\r
792 End = Start + RequestedWidth + 1;\r
793\r
794 Top = ((DimensionsHeight - NumberOfLines - 2) / 2) + gScreenDimensions.TopRow - 1;\r
795 Bottom = Top + NumberOfLines + 2;\r
796\r
797 Character = BOXDRAW_DOWN_RIGHT;\r
798 PrintCharAt (Start, Top, Character);\r
799 Character = BOXDRAW_HORIZONTAL;\r
800 for (Index = Start; Index + 2 < End; Index++) {\r
801 PrintChar (Character);\r
802 }\r
803\r
804 Character = BOXDRAW_DOWN_LEFT;\r
805 PrintChar (Character);\r
806 Character = BOXDRAW_VERTICAL;\r
807 for (Index = Top; Index + 2 < Bottom; Index++) {\r
808 String = ArrayOfStrings[Count];\r
809 Count++;\r
810\r
811 //\r
812 // This will clear the background of the line - we never know who might have been\r
813 // here before us. This differs from the next clear in that it used the non-reverse\r
814 // video for normal printing.\r
815 //\r
816 if (GetStringWidth (String) / 2 > 1) {\r
817 ClearLines (Start, End, Index + 1, Index + 1, POPUP_TEXT | POPUP_BACKGROUND);\r
818 }\r
819\r
820 //\r
821 // Passing in a space results in the assumption that this is where typing will occur\r
822 //\r
823 if (String[0] == L' ') {\r
824 ClearLines (Start + 1, End - 1, Index + 1, Index + 1, POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND);\r
825 }\r
826\r
827 //\r
828 // Passing in a NULL results in a blank space\r
829 //\r
830 if (String[0] == CHAR_NULL) {\r
831 ClearLines (Start, End, Index + 1, Index + 1, POPUP_TEXT | POPUP_BACKGROUND);\r
832 }\r
833\r
834 PrintStringAt (\r
835 ((DimensionsWidth - GetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,\r
836 Index + 1,\r
837 String\r
838 );\r
839 gST->ConOut->SetAttribute (gST->ConOut, POPUP_TEXT | POPUP_BACKGROUND);\r
840 PrintCharAt (Start, Index + 1, Character);\r
841 PrintCharAt (End - 1, Index + 1, Character);\r
842 }\r
843\r
844 Character = BOXDRAW_UP_RIGHT;\r
845 PrintCharAt (Start, Bottom - 1, Character);\r
846 Character = BOXDRAW_HORIZONTAL;\r
847 for (Index = Start; Index + 2 < End; Index++) {\r
848 PrintChar (Character);\r
849 }\r
850\r
851 Character = BOXDRAW_UP_LEFT;\r
852 PrintChar (Character);\r
853}\r
854\r
855/**\r
856 Draw a pop up windows based on the dimension, number of lines and\r
857 strings specified.\r
858\r
859 @param RequestedWidth The width of the pop-up.\r
860 @param NumberOfLines The number of lines.\r
861 @param ArrayOfStrings The array of string to be printed.\r
862 @param ... A series of text strings that displayed in the pop-up.\r
863\r
864**/\r
865VOID\r
866CreatePopUp (\r
867 IN UINTN RequestedWidth,\r
868 IN UINTN NumberOfLines,\r
869 IN CHAR16 *ArrayOfStrings,\r
870 ...\r
871 )\r
872{\r
873 CreateSharedPopUp (RequestedWidth, NumberOfLines, &ArrayOfStrings);\r
874}\r
875\r
876\r
877/**\r
878 Update status bar on the bottom of menu.\r
879\r
880 @param MessageType The type of message to be shown.\r
881 @param Flags The flags in Question header.\r
882 @param State Set or clear.\r
883\r
884**/\r
885VOID\r
886UpdateStatusBar (\r
887 IN UINTN MessageType,\r
888 IN UINT8 Flags,\r
889 IN BOOLEAN State\r
890 )\r
891{\r
892 UINTN Index;\r
893 STATIC BOOLEAN InputError;\r
894 CHAR16 *NvUpdateMessage;\r
895 CHAR16 *InputErrorMessage;\r
896\r
897 NvUpdateMessage = GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), gHiiHandle);\r
898 InputErrorMessage = GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), gHiiHandle);\r
899\r
900 switch (MessageType) {\r
901 case INPUT_ERROR:\r
902 if (State) {\r
903 gST->ConOut->SetAttribute (gST->ConOut, ERROR_TEXT);\r
904 PrintStringAt (\r
905 gScreenDimensions.LeftColumn + gPromptBlockWidth,\r
906 gScreenDimensions.BottomRow - 1,\r
907 InputErrorMessage\r
908 );\r
909 InputError = TRUE;\r
910 } else {\r
911 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT);\r
912 for (Index = 0; Index < (GetStringWidth (InputErrorMessage) - 2) / 2; Index++) {\r
913 PrintAt (gScreenDimensions.LeftColumn + gPromptBlockWidth + Index, gScreenDimensions.BottomRow - 1, L" ");\r
914 }\r
915\r
916 InputError = FALSE;\r
917 }\r
918 break;\r
919\r
920 case NV_UPDATE_REQUIRED:\r
921 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {\r
922 if (State) {\r
923 gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT);\r
924 PrintStringAt (\r
925 gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth,\r
926 gScreenDimensions.BottomRow - 1,\r
927 NvUpdateMessage\r
928 );\r
929 gResetRequired = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED));\r
930\r
931 gNvUpdateRequired = TRUE;\r
932 } else {\r
933 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT);\r
934 for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) {\r
935 PrintAt (\r
936 (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index),\r
937 gScreenDimensions.BottomRow - 1,\r
938 L" "\r
939 );\r
940 }\r
941\r
942 gNvUpdateRequired = FALSE;\r
943 }\r
944 }\r
945 break;\r
946\r
947 case REFRESH_STATUS_BAR:\r
948 if (InputError) {\r
949 UpdateStatusBar (INPUT_ERROR, Flags, TRUE);\r
950 }\r
951\r
952 if (gNvUpdateRequired) {\r
953 UpdateStatusBar (NV_UPDATE_REQUIRED, Flags, TRUE);\r
954 }\r
955 break;\r
956\r
957 default:\r
958 break;\r
959 }\r
960\r
961 gBS->FreePool (InputErrorMessage);\r
962 gBS->FreePool (NvUpdateMessage);\r
963 return ;\r
964}\r
965\r
966\r
967/**\r
968 Get the supported width for a particular op-code\r
969\r
970 @param Statement The FORM_BROWSER_STATEMENT structure passed in.\r
971 @param Handle The handle in the HII database being used\r
972\r
973 @return Returns the number of CHAR16 characters that is support.\r
974\r
975**/\r
976UINT16\r
977GetWidth (\r
978 IN FORM_BROWSER_STATEMENT *Statement,\r
979 IN EFI_HII_HANDLE Handle\r
980 )\r
981{\r
982 CHAR16 *String;\r
983 UINTN Size;\r
984 UINT16 Width;\r
985\r
986 Size = 0;\r
987\r
988 //\r
989 // See if the second text parameter is really NULL\r
990 //\r
991 if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) {\r
992 String = GetToken (Statement->TextTwo, Handle);\r
993 Size = StrLen (String);\r
994 gBS->FreePool (String);\r
995 }\r
996\r
997 if ((Statement->Operand == EFI_IFR_SUBTITLE_OP) ||\r
998 (Statement->Operand == EFI_IFR_REF_OP) ||\r
999 (Statement->Operand == EFI_IFR_PASSWORD_OP) ||\r
1000 (Statement->Operand == EFI_IFR_ACTION_OP) ||\r
1001 (Statement->Operand == EFI_IFR_RESET_BUTTON_OP) ||\r
1002 //\r
1003 // Allow a wide display if text op-code and no secondary text op-code\r
1004 //\r
1005 ((Statement->Operand == EFI_IFR_TEXT_OP) && (Size == 0))\r
1006 ) {\r
1007 Width = (UINT16) (gPromptBlockWidth + gOptionBlockWidth);\r
1008 } else {\r
1009 Width = (UINT16) gPromptBlockWidth;\r
1010 }\r
1011\r
1012 if (Statement->InSubtitle) {\r
1013 Width -= SUBTITLE_INDENT;\r
1014 }\r
1015\r
1016 return Width;\r
1017}\r
1018\r
1019\r
1020STATIC BOOLEAN GetLineByWidthFinished = FALSE;\r
1021\r
1022/**\r
1023 Will copy LineWidth amount of a string in the OutputString buffer and return the\r
1024 number of CHAR16 characters that were copied into the OutputString buffer.\r
1025\r
1026 @param InputString String description for this option.\r
1027 @param LineWidth Width of the desired string to extract in CHAR16\r
1028 characters\r
1029 @param Index Where in InputString to start the copy process\r
1030 @param OutputString Buffer to copy the string into\r
1031\r
1032 @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.\r
1033\r
1034**/\r
1035UINT16\r
1036GetLineByWidth (\r
1037 IN CHAR16 *InputString,\r
1038 IN UINT16 LineWidth,\r
1039 IN OUT UINTN *Index,\r
1040 OUT CHAR16 **OutputString\r
1041 )\r
1042{\r
1043 UINT16 Count;\r
1044 UINT16 Count2;\r
1045\r
1046 if (GetLineByWidthFinished) {\r
1047 GetLineByWidthFinished = FALSE;\r
1048 return (UINT16) 0;\r
1049 }\r
1050\r
1051 Count = LineWidth;\r
1052 Count2 = 0;\r
1053\r
1054 *OutputString = AllocateZeroPool (((UINTN) (LineWidth + 1) * 2));\r
1055\r
1056 //\r
1057 // Ensure we have got a valid buffer\r
1058 //\r
1059 if (*OutputString != NULL) {\r
1060\r
1061 //\r
1062 //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
1063 //To avoid displaying this empty line in screen, just skip the two CHARs here.\r
1064 //\r
1065 if ((InputString[*Index] == NARROW_CHAR) && (InputString[*Index + 1] == CHAR_CARRIAGE_RETURN)) {\r
1066 *Index = *Index + 2;\r
1067 }\r
1068\r
1069 //\r
1070 // Fast-forward the string and see if there is a carriage-return in the string\r
1071 //\r
1072 for (; (InputString[*Index + Count2] != CHAR_CARRIAGE_RETURN) && (Count2 != LineWidth); Count2++)\r
1073 ;\r
1074\r
1075 //\r
1076 // Copy the desired LineWidth of data to the output buffer.\r
1077 // Also make sure that we don't copy more than the string.\r
1078 // Also make sure that if there are linefeeds, we account for them.\r
1079 //\r
1080 if ((StrSize (&InputString[*Index]) <= ((UINTN) (LineWidth + 1) * 2)) &&\r
1081 (StrSize (&InputString[*Index]) <= ((UINTN) (Count2 + 1) * 2))\r
1082 ) {\r
1083 //\r
1084 // Convert to CHAR16 value and show that we are done with this operation\r
1085 //\r
1086 LineWidth = (UINT16) ((StrSize (&InputString[*Index]) - 2) / 2);\r
1087 if (LineWidth != 0) {\r
1088 GetLineByWidthFinished = TRUE;\r
1089 }\r
1090 } else {\r
1091 if (Count2 == LineWidth) {\r
1092 //\r
1093 // Rewind the string from the maximum size until we see a space to break the line\r
1094 //\r
1095 for (; (InputString[*Index + LineWidth] != CHAR_SPACE) && (LineWidth != 0); LineWidth--)\r
1096 ;\r
1097 if (LineWidth == 0) {\r
1098 LineWidth = Count;\r
1099 }\r
1100 } else {\r
1101 LineWidth = Count2;\r
1102 }\r
1103 }\r
1104\r
1105 CopyMem (*OutputString, &InputString[*Index], LineWidth * 2);\r
1106\r
1107 //\r
1108 // If currently pointing to a space, increment the index to the first non-space character\r
1109 //\r
1110 for (;\r
1111 (InputString[*Index + LineWidth] == CHAR_SPACE) || (InputString[*Index + LineWidth] == CHAR_CARRIAGE_RETURN);\r
1112 (*Index)++\r
1113 )\r
1114 ;\r
1115 *Index = (UINT16) (*Index + LineWidth);\r
1116 return LineWidth;\r
1117 } else {\r
1118 return (UINT16) 0;\r
1119 }\r
1120}\r
1121\r
1122\r
1123/**\r
1124 Update display lines for a Menu Option.\r
1125\r
1126 @param Selection The user's selection.\r
1127 @param MenuOption The MenuOption to be checked.\r
1128 @param OptionalString The option string.\r
1129 @param SkipValue The number of lins to skip.\r
1130\r
1131 @retval TRUE This Menu Option is selectable.\r
1132 @retval FALSE This Menu Option could not be selected.\r
1133\r
1134**/\r
1135VOID\r
1136UpdateOptionSkipLines (\r
1137 IN UI_MENU_SELECTION *Selection,\r
1138 IN UI_MENU_OPTION *MenuOption,\r
1139 OUT CHAR16 **OptionalString,\r
1140 IN UINTN SkipValue\r
1141 )\r
1142{\r
1143 UINTN Index;\r
1144 UINT16 Width;\r
1145 UINTN Row;\r
1146 UINTN OriginalRow;\r
1147 CHAR16 *OutputString;\r
1148 CHAR16 *OptionString;\r
1149\r
1150 Row = 0;\r
1151 OptionString = *OptionalString;\r
1152 OutputString = NULL;\r
1153\r
1154 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
1155\r
1156 if (OptionString != NULL) {\r
1157 Width = (UINT16) gOptionBlockWidth;\r
1158\r
1159 OriginalRow = Row;\r
1160\r
1161 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
1162 //\r
1163 // If there is more string to process print on the next row and increment the Skip value\r
1164 //\r
1165 if (StrLen (&OptionString[Index])) {\r
1166 if (SkipValue == 0) {\r
1167 Row++;\r
1168 //\r
1169 // Since the Number of lines for this menu entry may or may not be reflected accurately\r
1170 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
1171 // some testing to ensure we are keeping this in-sync.\r
1172 //\r
1173 // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
1174 //\r
1175 if ((Row - OriginalRow) >= MenuOption->Skip) {\r
1176 MenuOption->Skip++;\r
1177 }\r
1178 }\r
1179 }\r
1180\r
1181 gBS->FreePool (OutputString);\r
1182 if (SkipValue != 0) {\r
1183 SkipValue--;\r
1184 }\r
1185 }\r
1186\r
1187 Row = OriginalRow;\r
1188 }\r
1189\r
1190 *OptionalString = OptionString;\r
1191}\r
1192\r
1193\r
1194/**\r
1195 Check whether this Menu Option could be highlighted.\r
1196\r
1197 This is an internal function.\r
1198\r
1199 @param MenuOption The MenuOption to be checked.\r
1200\r
1201 @retval TRUE This Menu Option is selectable.\r
1202 @retval FALSE This Menu Option could not be selected.\r
1203\r
1204**/\r
1205BOOLEAN\r
1206IsSelectable (\r
1207 UI_MENU_OPTION *MenuOption\r
1208 )\r
1209{\r
1210 if ((MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) ||\r
1211 MenuOption->GrayOut || MenuOption->ReadOnly) {\r
1212 return FALSE;\r
1213 } else {\r
1214 return TRUE;\r
1215 }\r
1216}\r
1217\r
1218\r
1219/**\r
1220 Determine if the menu is the last menu that can be selected.\r
1221\r
1222 This is an internal function.\r
1223 \r
1224 @param Direction The scroll direction. False is down. True is up.\r
1225 @param CurrentPos The current focus.\r
1226\r
1227 @return FALSE -- the menu isn't the last menu that can be selected.\r
1228 @return TRUE -- the menu is the last menu that can be selected.\r
1229\r
1230**/\r
1231BOOLEAN\r
1232ValueIsScroll (\r
1233 IN BOOLEAN Direction,\r
1234 IN LIST_ENTRY *CurrentPos\r
1235 )\r
1236{\r
1237 LIST_ENTRY *Temp;\r
1238 UI_MENU_OPTION *MenuOption;\r
1239\r
1240 Temp = Direction ? CurrentPos->BackLink : CurrentPos->ForwardLink;\r
1241\r
1242 if (Temp == &Menu) {\r
1243 return TRUE;\r
1244 }\r
1245\r
1246 for (; Temp != &Menu; Temp = Direction ? Temp->BackLink : Temp->ForwardLink) {\r
1247 MenuOption = MENU_OPTION_FROM_LINK (Temp);\r
1248 if (IsSelectable (MenuOption)) {\r
1249 return FALSE;\r
1250 }\r
1251 }\r
1252\r
1253 return TRUE;\r
1254}\r
1255\r
1256\r
1257/**\r
1258 Move to next selectable statement.\r
1259 \r
1260 This is an internal function.\r
1261 \r
1262 @param GoUp The navigation direction. TRUE: up, FALSE: down.\r
1263 @param CurrentPosition Current position.\r
1264\r
1265 @return The row distance from current MenuOption to next selectable MenuOption.\r
1266\r
1267**/\r
1268INTN\r
1269MoveToNextStatement (\r
1270 IN BOOLEAN GoUp,\r
1271 IN OUT LIST_ENTRY **CurrentPosition\r
1272 )\r
1273{\r
1274 INTN Distance;\r
1275 LIST_ENTRY *Pos;\r
1276 BOOLEAN HitEnd;\r
1277 UI_MENU_OPTION *NextMenuOption;\r
1278\r
1279 Distance = 0;\r
1280 Pos = *CurrentPosition;\r
1281 HitEnd = FALSE;\r
1282\r
1283 while (TRUE) {\r
1284 NextMenuOption = MENU_OPTION_FROM_LINK (Pos);\r
1285 if (IsSelectable (NextMenuOption)) {\r
1286 break;\r
1287 }\r
1288 if ((GoUp ? Pos->BackLink : Pos->ForwardLink) == &Menu) {\r
1289 HitEnd = TRUE;\r
1290 break;\r
1291 }\r
1292 Distance += NextMenuOption->Skip;\r
1293 Pos = (GoUp ? Pos->BackLink : Pos->ForwardLink);\r
1294 }\r
1295\r
1296 if (HitEnd) {\r
1297 //\r
1298 // If we hit end there is still no statement can be focused,\r
1299 // we go backwards to find the statement can be focused.\r
1300 //\r
1301 Distance = 0;\r
1302 Pos = *CurrentPosition;\r
1303\r
1304 while (TRUE) {\r
1305 NextMenuOption = MENU_OPTION_FROM_LINK (Pos);\r
1306 if (IsSelectable (NextMenuOption)) {\r
1307 break;\r
1308 }\r
1309 if ((!GoUp ? Pos->BackLink : Pos->ForwardLink) == &Menu) {\r
1310 ASSERT (FALSE);\r
1311 break;\r
1312 }\r
1313 Distance -= NextMenuOption->Skip;\r
1314 Pos = (!GoUp ? Pos->BackLink : Pos->ForwardLink);\r
1315 }\r
1316 }\r
1317\r
1318 *CurrentPosition = &NextMenuOption->Link;\r
1319 return Distance;\r
1320}\r
1321\r
1322\r
1323/**\r
1324 Adjust Data and Time position accordingly.\r
1325 Data format : [01/02/2004] [11:22:33]\r
1326 Line number : 0 0 1 0 0 1\r
1327 \r
1328 This is an internal function.\r
1329\r
1330 @param DirectionUp the up or down direction. False is down. True is\r
1331 up.\r
1332 @param CurrentPosition Current position. On return: Point to the last\r
1333 Option (Year or Second) if up; Point to the first\r
1334 Option (Month or Hour) if down.\r
1335\r
1336 @return Return line number to pad. It is possible that we stand on a zero-advance\r
1337 @return data or time opcode, so pad one line when we judge if we are going to scroll outside.\r
1338\r
1339**/\r
1340UINTN\r
1341AdjustDateAndTimePosition (\r
1342 IN BOOLEAN DirectionUp,\r
1343 IN OUT LIST_ENTRY **CurrentPosition\r
1344 )\r
1345{\r
1346 UINTN Count;\r
1347 LIST_ENTRY *NewPosition;\r
1348 UI_MENU_OPTION *MenuOption;\r
1349 UINTN PadLineNumber;\r
1350\r
1351 PadLineNumber = 0;\r
1352 NewPosition = *CurrentPosition;\r
1353 MenuOption = MENU_OPTION_FROM_LINK (NewPosition);\r
1354\r
1355 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||\r
1356 (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
1357 //\r
1358 // Calculate the distance from current position to the last Date/Time MenuOption\r
1359 //\r
1360 Count = 0;\r
1361 while (MenuOption->Skip == 0) {\r
1362 Count++;\r
1363 NewPosition = NewPosition->ForwardLink;\r
1364 MenuOption = MENU_OPTION_FROM_LINK (NewPosition);\r
1365 PadLineNumber = 1;\r
1366 }\r
1367\r
1368 NewPosition = *CurrentPosition;\r
1369 if (DirectionUp) {\r
1370 //\r
1371 // Since the behavior of hitting the up arrow on a Date/Time MenuOption is intended\r
1372 // to be one that back to the previous set of MenuOptions, we need to advance to the first\r
1373 // Date/Time MenuOption and leave the remaining logic in CfUiUp intact so the appropriate\r
1374 // checking can be done.\r
1375 //\r
1376 while (Count++ < 2) {\r
1377 NewPosition = NewPosition->BackLink;\r
1378 }\r
1379 } else {\r
1380 //\r
1381 // Since the behavior of hitting the down arrow on a Date/Time MenuOption is intended\r
1382 // to be one that progresses to the next set of MenuOptions, we need to advance to the last\r
1383 // Date/Time MenuOption and leave the remaining logic in CfUiDown intact so the appropriate\r
1384 // checking can be done.\r
1385 //\r
1386 while (Count-- > 0) {\r
1387 NewPosition = NewPosition->ForwardLink;\r
1388 }\r
1389 }\r
1390\r
1391 *CurrentPosition = NewPosition;\r
1392 }\r
1393\r
1394 return PadLineNumber;\r
1395}\r
1396\r
1397\r
1398/**\r
1399 Display menu and wait for user to select one menu option, then return it.\r
1400 If AutoBoot is enabled, then if user doesn't select any option,\r
1401 after period of time, it will automatically return the first menu option.\r
1402\r
1403 @param Selection Menu selection.\r
1404\r
1405 @retval EFI_SUCESSS This function always return successfully for now.\r
1406\r
1407**/\r
1408EFI_STATUS\r
1409UiDisplayMenu (\r
1410 IN OUT UI_MENU_SELECTION *Selection\r
1411 )\r
1412{\r
1413 INTN SkipValue;\r
1414 INTN Difference;\r
1415 INTN OldSkipValue;\r
1416 UINTN DistanceValue;\r
1417 UINTN Row;\r
1418 UINTN Col;\r
1419 UINTN Temp;\r
1420 UINTN Temp2;\r
1421 UINTN TopRow;\r
1422 UINTN BottomRow;\r
1423 UINTN OriginalRow;\r
1424 UINTN Index;\r
1425 UINT32 Count;\r
1426 UINT16 Width;\r
1427 CHAR16 *StringPtr;\r
1428 CHAR16 *OptionString;\r
1429 CHAR16 *OutputString;\r
1430 CHAR16 *FormattedString;\r
1431 CHAR16 YesResponse;\r
1432 CHAR16 NoResponse;\r
1433 BOOLEAN NewLine;\r
1434 BOOLEAN Repaint;\r
1435 BOOLEAN SavedValue;\r
1436 EFI_STATUS Status;\r
1437 EFI_INPUT_KEY Key;\r
1438 LIST_ENTRY *Link;\r
1439 LIST_ENTRY *NewPos;\r
1440 LIST_ENTRY *TopOfScreen;\r
1441 LIST_ENTRY *SavedListEntry;\r
1442 UI_MENU_OPTION *MenuOption;\r
1443 UI_MENU_OPTION *NextMenuOption;\r
1444 UI_MENU_OPTION *SavedMenuOption;\r
1445 UI_MENU_OPTION *PreviousMenuOption;\r
1446 UI_CONTROL_FLAG ControlFlag;\r
1447 EFI_SCREEN_DESCRIPTOR LocalScreen;\r
1448 MENU_REFRESH_ENTRY *MenuRefreshEntry;\r
1449 UI_SCREEN_OPERATION ScreenOperation;\r
1450 UINT8 MinRefreshInterval;\r
1451 UINTN BufferSize;\r
1452 UINT16 DefaultId;\r
1453 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
1454 FORM_BROWSER_STATEMENT *Statement;\r
1455\r
1456 CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
1457\r
1458 Status = EFI_SUCCESS;\r
1459 FormattedString = NULL;\r
1460 OptionString = NULL;\r
1461 ScreenOperation = UiNoOperation;\r
1462 NewLine = TRUE;\r
1463 MinRefreshInterval = 0;\r
1464 DefaultId = 0;\r
1465\r
1466 OutputString = NULL;\r
1467 gUpArrow = FALSE;\r
1468 gDownArrow = FALSE;\r
1469 SkipValue = 0;\r
1470 OldSkipValue = 0;\r
1471 MenuRefreshEntry = gMenuRefreshHead;\r
1472\r
1473 NextMenuOption = NULL;\r
1474 PreviousMenuOption = NULL;\r
1475 SavedMenuOption = NULL;\r
1476\r
1477 ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r
1478\r
1479 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {\r
1480 TopRow = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
1481 Row = LocalScreen.TopRow + FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
1482 } else {\r
1483 TopRow = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
1484 Row = LocalScreen.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT + SCROLL_ARROW_HEIGHT;\r
1485 }\r
1486\r
1487 Col = LocalScreen.LeftColumn;\r
1488 BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - SCROLL_ARROW_HEIGHT - 1;\r
1489\r
1490 Selection->TopRow = TopRow;\r
1491 Selection->BottomRow = BottomRow;\r
1492 Selection->PromptCol = Col;\r
1493 Selection->OptionCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn;\r
1494 Selection->Statement = NULL;\r
1495\r
1496 TopOfScreen = Menu.ForwardLink;\r
1497 Repaint = TRUE;\r
1498 MenuOption = NULL;\r
1499\r
1500 //\r
1501 // Get user's selection\r
1502 //\r
1503 NewPos = Menu.ForwardLink;\r
1504\r
1505 gST->ConOut->EnableCursor (gST->ConOut, FALSE);\r
1506 UpdateStatusBar (REFRESH_STATUS_BAR, (UINT8) 0, TRUE);\r
1507\r
1508 ControlFlag = CfInitialization;\r
1509 Selection->Action = UI_ACTION_NONE;\r
1510 while (TRUE) {\r
1511 switch (ControlFlag) {\r
1512 case CfInitialization:\r
1513 if (IsListEmpty (&Menu)) {\r
1514 ControlFlag = CfReadKey;\r
1515 } else {\r
1516 ControlFlag = CfCheckSelection;\r
1517 }\r
1518 break;\r
1519\r
1520 case CfCheckSelection:\r
1521 if (Selection->Action != UI_ACTION_NONE) {\r
1522 ControlFlag = CfExit;\r
1523 } else {\r
1524 ControlFlag = CfRepaint;\r
1525 }\r
1526 break;\r
1527\r
1528 case CfRepaint:\r
1529 ControlFlag = CfRefreshHighLight;\r
1530\r
1531 if (Repaint) {\r
1532 //\r
1533 // Display menu\r
1534 //\r
1535 gDownArrow = FALSE;\r
1536 gUpArrow = FALSE;\r
1537 Row = TopRow;\r
1538\r
1539 Temp = SkipValue;\r
1540 Temp2 = SkipValue;\r
1541\r
1542 ClearLines (\r
1543 LocalScreen.LeftColumn,\r
1544 LocalScreen.RightColumn,\r
1545 TopRow - SCROLL_ARROW_HEIGHT,\r
1546 BottomRow + SCROLL_ARROW_HEIGHT,\r
1547 FIELD_TEXT | FIELD_BACKGROUND\r
1548 );\r
1549\r
1550 UiFreeRefreshList ();\r
1551 MinRefreshInterval = 0;\r
1552\r
1553 for (Link = TopOfScreen; Link != &Menu; Link = Link->ForwardLink) {\r
1554 MenuOption = MENU_OPTION_FROM_LINK (Link);\r
1555 MenuOption->Row = Row;\r
1556 MenuOption->Col = Col;\r
1557 MenuOption->OptCol = gPromptBlockWidth + 1 + LocalScreen.LeftColumn;\r
1558\r
1559 Statement = MenuOption->ThisTag;\r
1560 if (Statement->InSubtitle) {\r
1561 MenuOption->Col += SUBTITLE_INDENT;\r
1562 }\r
1563\r
1564 if (MenuOption->GrayOut) {\r
1565 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND);\r
1566 } else {\r
1567 if (Statement->Operand == EFI_IFR_SUBTITLE_OP) {\r
1568 gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND);\r
1569 }\r
1570 }\r
1571\r
1572 Width = GetWidth (Statement, MenuOption->Handle);\r
1573 OriginalRow = Row;\r
1574\r
1575 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
1576 if ((Temp == 0) && (Row <= BottomRow)) {\r
1577 PrintStringAt (MenuOption->Col, Row, OutputString);\r
1578 }\r
1579 //\r
1580 // If there is more string to process print on the next row and increment the Skip value\r
1581 //\r
1582 if (StrLen (&MenuOption->Description[Index])) {\r
1583 if (Temp == 0) {\r
1584 Row++;\r
1585 }\r
1586 }\r
1587\r
1588 gBS->FreePool (OutputString);\r
1589 if (Temp != 0) {\r
1590 Temp--;\r
1591 }\r
1592 }\r
1593\r
1594 Temp = 0;\r
1595 Row = OriginalRow;\r
1596\r
1597 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
1598 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
1599\r
1600 if (OptionString != NULL) {\r
1601 if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {\r
1602 //\r
1603 // If leading spaces on OptionString - remove the spaces\r
1604 //\r
1605 for (Index = 0; OptionString[Index] == L' '; Index++) {\r
1606 MenuOption->OptCol++;\r
1607 }\r
1608\r
1609 for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
1610 OptionString[Count] = OptionString[Index];\r
1611 Count++;\r
1612 }\r
1613\r
1614 OptionString[Count] = CHAR_NULL;\r
1615 }\r
1616\r
1617 //\r
1618 // If Question request refresh, register the op-code\r
1619 //\r
1620 if (Statement->RefreshInterval != 0) {\r
1621 //\r
1622 // Menu will be refreshed at minimal interval of all Questions\r
1623 // which have refresh request\r
1624 //\r
1625 if (MinRefreshInterval == 0 || Statement->RefreshInterval < MinRefreshInterval) {\r
1626 MinRefreshInterval = Statement->RefreshInterval;\r
1627 }\r
1628\r
1629 if (gMenuRefreshHead == NULL) {\r
1630 MenuRefreshEntry = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));\r
1631 ASSERT (MenuRefreshEntry != NULL);\r
1632 MenuRefreshEntry->MenuOption = MenuOption;\r
1633 MenuRefreshEntry->Selection = Selection;\r
1634 MenuRefreshEntry->CurrentColumn = MenuOption->OptCol;\r
1635 MenuRefreshEntry->CurrentRow = MenuOption->Row;\r
1636 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;\r
1637 gMenuRefreshHead = MenuRefreshEntry;\r
1638 } else {\r
1639 //\r
1640 // Advance to the last entry\r
1641 //\r
1642 for (MenuRefreshEntry = gMenuRefreshHead;\r
1643 MenuRefreshEntry->Next != NULL;\r
1644 MenuRefreshEntry = MenuRefreshEntry->Next\r
1645 )\r
1646 ;\r
1647 MenuRefreshEntry->Next = AllocateZeroPool (sizeof (MENU_REFRESH_ENTRY));\r
1648 ASSERT (MenuRefreshEntry->Next != NULL);\r
1649 MenuRefreshEntry = MenuRefreshEntry->Next;\r
1650 MenuRefreshEntry->MenuOption = MenuOption;\r
1651 MenuRefreshEntry->Selection = Selection;\r
1652 MenuRefreshEntry->CurrentColumn = MenuOption->OptCol;\r
1653 MenuRefreshEntry->CurrentRow = MenuOption->Row;\r
1654 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;\r
1655 }\r
1656 }\r
1657\r
1658 Width = (UINT16) gOptionBlockWidth;\r
1659 OriginalRow = Row;\r
1660\r
1661 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
1662 if ((Temp2 == 0) && (Row <= BottomRow)) {\r
1663 PrintStringAt (MenuOption->OptCol, Row, OutputString);\r
1664 }\r
1665 //\r
1666 // If there is more string to process print on the next row and increment the Skip value\r
1667 //\r
1668 if (StrLen (&OptionString[Index])) {\r
1669 if (Temp2 == 0) {\r
1670 Row++;\r
1671 //\r
1672 // Since the Number of lines for this menu entry may or may not be reflected accurately\r
1673 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
1674 // some testing to ensure we are keeping this in-sync.\r
1675 //\r
1676 // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
1677 //\r
1678 if ((Row - OriginalRow) >= MenuOption->Skip) {\r
1679 MenuOption->Skip++;\r
1680 }\r
1681 }\r
1682 }\r
1683\r
1684 gBS->FreePool (OutputString);\r
1685 if (Temp2 != 0) {\r
1686 Temp2--;\r
1687 }\r
1688 }\r
1689\r
1690 Temp2 = 0;\r
1691 Row = OriginalRow;\r
1692\r
1693 gBS->FreePool (OptionString);\r
1694 }\r
1695 //\r
1696 // If this is a text op with secondary text information\r
1697 //\r
1698 if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) {\r
1699 StringPtr = GetToken (Statement->TextTwo, MenuOption->Handle);\r
1700\r
1701 Width = (UINT16) gOptionBlockWidth;\r
1702 OriginalRow = Row;\r
1703\r
1704 for (Index = 0; GetLineByWidth (StringPtr, Width, &Index, &OutputString) != 0x0000;) {\r
1705 if ((Temp == 0) && (Row <= BottomRow)) {\r
1706 PrintStringAt (MenuOption->OptCol, Row, OutputString);\r
1707 }\r
1708 //\r
1709 // If there is more string to process print on the next row and increment the Skip value\r
1710 //\r
1711 if (StrLen (&StringPtr[Index])) {\r
1712 if (Temp2 == 0) {\r
1713 Row++;\r
1714 //\r
1715 // Since the Number of lines for this menu entry may or may not be reflected accurately\r
1716 // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
1717 // some testing to ensure we are keeping this in-sync.\r
1718 //\r
1719 // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
1720 //\r
1721 if ((Row - OriginalRow) >= MenuOption->Skip) {\r
1722 MenuOption->Skip++;\r
1723 }\r
1724 }\r
1725 }\r
1726\r
1727 gBS->FreePool (OutputString);\r
1728 if (Temp2 != 0) {\r
1729 Temp2--;\r
1730 }\r
1731 }\r
1732\r
1733 Row = OriginalRow;\r
1734 gBS->FreePool (StringPtr);\r
1735 }\r
1736\r
1737 //\r
1738 // Need to handle the bottom of the display\r
1739 //\r
1740 if (MenuOption->Skip > 1) {\r
1741 Row += MenuOption->Skip - SkipValue;\r
1742 SkipValue = 0;\r
1743 } else {\r
1744 Row += MenuOption->Skip;\r
1745 }\r
1746\r
1747 if (Row > BottomRow) {\r
1748 if (!ValueIsScroll (FALSE, Link)) {\r
1749 gDownArrow = TRUE;\r
1750 }\r
1751\r
1752 Row = BottomRow + 1;\r
1753 break;\r
1754 }\r
1755 }\r
1756\r
1757 if (!ValueIsScroll (TRUE, TopOfScreen)) {\r
1758 gUpArrow = TRUE;\r
1759 }\r
1760\r
1761 if (gUpArrow) {\r
1762 gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND);\r
1763 PrintAt (\r
1764 LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,\r
1765 TopRow - SCROLL_ARROW_HEIGHT,\r
1766 L"%c",\r
1767 ARROW_UP\r
1768 );\r
1769 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
1770 }\r
1771\r
1772 if (gDownArrow) {\r
1773 gST->ConOut->SetAttribute (gST->ConOut, ARROW_TEXT | ARROW_BACKGROUND);\r
1774 PrintAt (\r
1775 LocalScreen.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + 1,\r
1776 BottomRow + SCROLL_ARROW_HEIGHT,\r
1777 L"%c",\r
1778 ARROW_DOWN\r
1779 );\r
1780 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
1781 }\r
1782\r
1783 MenuOption = NULL;\r
1784 }\r
1785 break;\r
1786\r
1787 case CfRefreshHighLight:\r
1788 //\r
1789 // MenuOption: Last menu option that need to remove hilight\r
1790 // MenuOption is set to NULL in Repaint\r
1791 // NewPos: Current menu option that need to hilight\r
1792 //\r
1793 ControlFlag = CfUpdateHelpString;\r
1794\r
1795 //\r
1796 // Repaint flag is normally reset when finish processing CfUpdateHelpString. Temporarily\r
1797 // reset Repaint flag because we may break halfway and skip CfUpdateHelpString processing.\r
1798 //\r
1799 SavedValue = Repaint;\r
1800 Repaint = FALSE;\r
1801\r
1802 if (Selection->QuestionId != 0) {\r
1803 NewPos = Menu.ForwardLink;\r
1804 SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
1805\r
1806 while (SavedMenuOption->ThisTag->QuestionId != Selection->QuestionId && NewPos->ForwardLink != &Menu) {\r
1807 NewPos = NewPos->ForwardLink;\r
1808 SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
1809 }\r
1810 if (SavedMenuOption->ThisTag->QuestionId == Selection->QuestionId) {\r
1811 //\r
1812 // Target Question found, find its MenuOption\r
1813 //\r
1814 Link = TopOfScreen;\r
1815\r
1816 for (Index = TopRow; Index <= BottomRow && Link != NewPos;) {\r
1817 SavedMenuOption = MENU_OPTION_FROM_LINK (Link);\r
1818 Index += SavedMenuOption->Skip;\r
1819 Link = Link->ForwardLink;\r
1820 }\r
1821\r
1822 if (Link != NewPos || Index > BottomRow) {\r
1823 //\r
1824 // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page\r
1825 //\r
1826 Link = NewPos;\r
1827 for (Index = TopRow; Index <= BottomRow; ) {\r
1828 Link = Link->BackLink;\r
1829 SavedMenuOption = MENU_OPTION_FROM_LINK (Link);\r
1830 Index += SavedMenuOption->Skip;\r
1831 }\r
1832 TopOfScreen = Link->ForwardLink;\r
1833\r
1834 Repaint = TRUE;\r
1835 NewLine = TRUE;\r
1836 ControlFlag = CfRepaint;\r
1837 break;\r
1838 }\r
1839 } else {\r
1840 //\r
1841 // Target Question not found, highlight the default menu option\r
1842 //\r
1843 NewPos = TopOfScreen;\r
1844 }\r
1845\r
1846 Selection->QuestionId = 0;\r
1847 }\r
1848\r
1849 if (NewPos != NULL && (MenuOption == NULL || NewPos != &MenuOption->Link)) {\r
1850 if (MenuOption != NULL) {\r
1851 //\r
1852 // Remove highlight on last Menu Option\r
1853 //\r
1854 gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);\r
1855 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
1856 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
1857 if (OptionString != NULL) {\r
1858 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||\r
1859 (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)\r
1860 ) {\r
1861 //\r
1862 // If leading spaces on OptionString - remove the spaces\r
1863 //\r
1864 for (Index = 0; OptionString[Index] == L' '; Index++)\r
1865 ;\r
1866\r
1867 for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
1868 OptionString[Count] = OptionString[Index];\r
1869 Count++;\r
1870 }\r
1871\r
1872 OptionString[Count] = CHAR_NULL;\r
1873 }\r
1874\r
1875 Width = (UINT16) gOptionBlockWidth;\r
1876 OriginalRow = MenuOption->Row;\r
1877\r
1878 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
1879 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
1880 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);\r
1881 }\r
1882 //\r
1883 // If there is more string to process print on the next row and increment the Skip value\r
1884 //\r
1885 if (StrLen (&OptionString[Index])) {\r
1886 MenuOption->Row++;\r
1887 }\r
1888\r
1889 gBS->FreePool (OutputString);\r
1890 }\r
1891\r
1892 MenuOption->Row = OriginalRow;\r
1893\r
1894 gBS->FreePool (OptionString);\r
1895 } else {\r
1896 if (NewLine) {\r
1897 if (MenuOption->GrayOut) {\r
1898 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_GRAYED | FIELD_BACKGROUND);\r
1899 } else if (MenuOption->ThisTag->Operand == EFI_IFR_SUBTITLE_OP) {\r
1900 gST->ConOut->SetAttribute (gST->ConOut, SUBTITLE_TEXT | FIELD_BACKGROUND);\r
1901 }\r
1902\r
1903 OriginalRow = MenuOption->Row;\r
1904 Width = GetWidth (MenuOption->ThisTag, MenuOption->Handle);\r
1905\r
1906 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
1907 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
1908 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);\r
1909 }\r
1910 //\r
1911 // If there is more string to process print on the next row and increment the Skip value\r
1912 //\r
1913 if (StrLen (&MenuOption->Description[Index])) {\r
1914 MenuOption->Row++;\r
1915 }\r
1916\r
1917 gBS->FreePool (OutputString);\r
1918 }\r
1919\r
1920 MenuOption->Row = OriginalRow;\r
1921 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
1922 }\r
1923 }\r
1924 }\r
1925\r
1926 //\r
1927 // This is only possible if we entered this page and the first menu option is\r
1928 // a "non-menu" item. In that case, force it UiDown\r
1929 //\r
1930 MenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
1931 if (!IsSelectable (MenuOption)) {\r
1932 ASSERT (ScreenOperation == UiNoOperation);\r
1933 ScreenOperation = UiDown;\r
1934 ControlFlag = CfScreenOperation;\r
1935 break;\r
1936 }\r
1937\r
1938 //\r
1939 // This is the current selected statement\r
1940 //\r
1941 Statement = MenuOption->ThisTag;\r
1942 Selection->Statement = Statement;\r
1943\r
1944 //\r
1945 // Set reverse attribute\r
1946 //\r
1947 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT);\r
1948 gST->ConOut->SetCursorPosition (gST->ConOut, MenuOption->Col, MenuOption->Row);\r
1949\r
1950 //\r
1951 // Assuming that we have a refresh linked-list created, lets annotate the\r
1952 // appropriate entry that we are highlighting with its new attribute. Just prior to this\r
1953 // lets reset all of the entries' attribute so we do not get multiple highlights in he refresh\r
1954 //\r
1955 if (gMenuRefreshHead != NULL) {\r
1956 for (MenuRefreshEntry = gMenuRefreshHead; MenuRefreshEntry != NULL; MenuRefreshEntry = MenuRefreshEntry->Next) {\r
1957 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT | FIELD_BACKGROUND;\r
1958 if (MenuRefreshEntry->MenuOption == MenuOption) {\r
1959 MenuRefreshEntry->CurrentAttribute = FIELD_TEXT_HIGHLIGHT | FIELD_BACKGROUND_HIGHLIGHT;\r
1960 }\r
1961 }\r
1962 }\r
1963\r
1964 ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
1965 if (OptionString != NULL) {\r
1966 if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {\r
1967 //\r
1968 // If leading spaces on OptionString - remove the spaces\r
1969 //\r
1970 for (Index = 0; OptionString[Index] == L' '; Index++)\r
1971 ;\r
1972\r
1973 for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
1974 OptionString[Count] = OptionString[Index];\r
1975 Count++;\r
1976 }\r
1977\r
1978 OptionString[Count] = CHAR_NULL;\r
1979 }\r
1980 Width = (UINT16) gOptionBlockWidth;\r
1981\r
1982 OriginalRow = MenuOption->Row;\r
1983\r
1984 for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
1985 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
1986 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);\r
1987 }\r
1988 //\r
1989 // If there is more string to process print on the next row and increment the Skip value\r
1990 //\r
1991 if (StrLen (&OptionString[Index])) {\r
1992 MenuOption->Row++;\r
1993 }\r
1994\r
1995 gBS->FreePool (OutputString);\r
1996 }\r
1997\r
1998 MenuOption->Row = OriginalRow;\r
1999\r
2000 gBS->FreePool (OptionString);\r
2001 } else {\r
2002 if (NewLine) {\r
2003 OriginalRow = MenuOption->Row;\r
2004\r
2005 Width = GetWidth (Statement, MenuOption->Handle);\r
2006\r
2007 for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
2008 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
2009 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);\r
2010 }\r
2011 //\r
2012 // If there is more string to process print on the next row and increment the Skip value\r
2013 //\r
2014 if (StrLen (&MenuOption->Description[Index])) {\r
2015 MenuOption->Row++;\r
2016 }\r
2017\r
2018 gBS->FreePool (OutputString);\r
2019 }\r
2020\r
2021 MenuOption->Row = OriginalRow;\r
2022\r
2023 }\r
2024 }\r
2025\r
2026 if (((NewPos->ForwardLink != &Menu) && (ScreenOperation == UiDown)) ||\r
2027 ((NewPos->BackLink != &Menu) && (ScreenOperation == UiUp)) ||\r
2028 (ScreenOperation == UiNoOperation)\r
2029 ) {\r
2030 UpdateKeyHelp (MenuOption, FALSE);\r
2031 }\r
2032 //\r
2033 // Clear reverse attribute\r
2034 //\r
2035 gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
2036 }\r
2037 //\r
2038 // Repaint flag will be used when process CfUpdateHelpString, so restore its value\r
2039 // if we didn't break halfway when process CfRefreshHighLight.\r
2040 //\r
2041 Repaint = SavedValue;\r
2042 break;\r
2043\r
2044 case CfUpdateHelpString:\r
2045 ControlFlag = CfPrepareToReadKey;\r
2046\r
2047 if ((Repaint || NewLine) && (gClassOfVfr != EFI_GENERAL_APPLICATION_SUBCLASS)) {\r
2048 //\r
2049 // Don't print anything if it is a NULL help token\r
2050 //\r
2051 if (MenuOption->ThisTag->Help == 0) {\r
2052 StringPtr = L"\0";\r
2053 } else {\r
2054 StringPtr = GetToken (MenuOption->ThisTag->Help, MenuOption->Handle);\r
2055 }\r
2056\r
2057 ProcessHelpString (StringPtr, &FormattedString, BottomRow - TopRow);\r
2058\r
2059 gST->ConOut->SetAttribute (gST->ConOut, HELP_TEXT | FIELD_BACKGROUND);\r
2060\r
2061 for (Index = 0; Index < BottomRow - TopRow; Index++) {\r
2062 //\r
2063 // Pad String with spaces to simulate a clearing of the previous line\r
2064 //\r
2065 for (; GetStringWidth (&FormattedString[Index * gHelpBlockWidth * 2]) / 2 < gHelpBlockWidth;) {\r
2066 StrCat (&FormattedString[Index * gHelpBlockWidth * 2], L" ");\r
2067 }\r
2068\r
2069 PrintStringAt (\r
2070 LocalScreen.RightColumn - gHelpBlockWidth,\r
2071 Index + TopRow,\r
2072 &FormattedString[Index * gHelpBlockWidth * 2]\r
2073 );\r
2074 }\r
2075 }\r
2076 //\r
2077 // Reset this flag every time we finish using it.\r
2078 //\r
2079 Repaint = FALSE;\r
2080 NewLine = FALSE;\r
2081 break;\r
2082\r
2083 case CfPrepareToReadKey:\r
2084 ControlFlag = CfReadKey;\r
2085 ScreenOperation = UiNoOperation;\r
2086 break;\r
2087\r
2088 case CfReadKey:\r
2089 ControlFlag = CfScreenOperation;\r
2090\r
2091 //\r
2092 // Wait for user's selection\r
2093 //\r
2094 do {\r
2095 Status = UiWaitForSingleEvent (gST->ConIn->WaitForKey, 0, MinRefreshInterval);\r
2096 } while (Status == EFI_TIMEOUT);\r
2097\r
2098 if (Status == EFI_TIMEOUT) {\r
2099 Key.UnicodeChar = CHAR_CARRIAGE_RETURN;\r
2100 } else {\r
2101 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
2102 //\r
2103 // if we encounter error, continue to read another key in.\r
2104 //\r
2105 if (EFI_ERROR (Status)) {\r
2106 ControlFlag = CfReadKey;\r
2107 continue;\r
2108 }\r
2109 }\r
2110\r
2111 if (IsListEmpty (&Menu) && Key.UnicodeChar != CHAR_NULL) {\r
2112 //\r
2113 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset\r
2114 //\r
2115 break;\r
2116 }\r
2117\r
2118 switch (Key.UnicodeChar) {\r
2119 case CHAR_CARRIAGE_RETURN:\r
2120 ScreenOperation = UiSelect;\r
2121 gDirection = 0;\r
2122 break;\r
2123\r
2124 //\r
2125 // We will push the adjustment of these numeric values directly to the input handler\r
2126 // NOTE: we won't handle manual input numeric\r
2127 //\r
2128 case '+':\r
2129 case '-':\r
2130 Statement = MenuOption->ThisTag;\r
2131 if ((Statement->Operand == EFI_IFR_DATE_OP)\r
2132 || (Statement->Operand == EFI_IFR_TIME_OP)\r
2133 || ((Statement->Operand == EFI_IFR_NUMERIC_OP) && (Statement->Step != 0))\r
2134 ){\r
2135 if (Key.UnicodeChar == '+') {\r
2136 gDirection = SCAN_RIGHT;\r
2137 } else {\r
2138 gDirection = SCAN_LEFT;\r
2139 }\r
2140 Status = ProcessOptions (Selection, MenuOption, TRUE, &OptionString);\r
2141 SafeFreePool (OptionString);\r
2142 }\r
2143 break;\r
2144\r
2145 case '^':\r
2146 ScreenOperation = UiUp;\r
2147 break;\r
2148\r
2149 case 'V':\r
2150 case 'v':\r
2151 ScreenOperation = UiDown;\r
2152 break;\r
2153\r
2154 case ' ':\r
2155 if (gClassOfVfr != EFI_FRONT_PAGE_SUBCLASS) {\r
2156 if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut) {\r
2157 ScreenOperation = UiSelect;\r
2158 }\r
2159 }\r
2160 break;\r
2161\r
2162 case CHAR_NULL:\r
2163 if (((Key.ScanCode == SCAN_F1) && ((gFunctionKeySetting & FUNCTION_ONE) != FUNCTION_ONE)) ||\r
2164 ((Key.ScanCode == SCAN_F2) && ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO)) ||\r
2165 ((Key.ScanCode == SCAN_F9) && ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE)) ||\r
2166 ((Key.ScanCode == SCAN_F10) && ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN))\r
2167 ) {\r
2168 //\r
2169 // If the function key has been disabled, just ignore the key.\r
2170 //\r
2171 } else {\r
2172 for (Index = 0; Index < sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]); Index++) {\r
2173 if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {\r
2174 if (Key.ScanCode == SCAN_F9) {\r
2175 //\r
2176 // Reset to standard default\r
2177 //\r
2178 DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
2179 }\r
2180 ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;\r
2181 break;\r
2182 }\r
2183 }\r
2184 }\r
2185 break;\r
2186 }\r
2187 break;\r
2188\r
2189 case CfScreenOperation:\r
2190 if (ScreenOperation != UiPrevious && ScreenOperation != UiReset) {\r
2191 //\r
2192 // If the screen has no menu items, and the user didn't select UiPrevious, or UiReset\r
2193 // ignore the selection and go back to reading keys.\r
2194 //\r
2195 if (IsListEmpty (&Menu)) {\r
2196 ControlFlag = CfReadKey;\r
2197 break;\r
2198 }\r
2199 //\r
2200 // if there is nothing logical to place a cursor on, just move on to wait for a key.\r
2201 //\r
2202 for (Link = Menu.ForwardLink; Link != &Menu; Link = Link->ForwardLink) {\r
2203 NextMenuOption = MENU_OPTION_FROM_LINK (Link);\r
2204 if (IsSelectable (NextMenuOption)) {\r
2205 break;\r
2206 }\r
2207 }\r
2208\r
2209 if (Link == &Menu) {\r
2210 ControlFlag = CfPrepareToReadKey;\r
2211 break;\r
2212 }\r
2213 } else if (ScreenOperation == UiReset) {\r
2214 //\r
2215 // Press ESC to exit FormSet\r
2216 //\r
2217 Selection->Action = UI_ACTION_EXIT;\r
2218 Selection->Statement = NULL;\r
2219 }\r
2220\r
2221 for (Index = 0;\r
2222 Index < sizeof (gScreenOperationToControlFlag) / sizeof (gScreenOperationToControlFlag[0]);\r
2223 Index++\r
2224 ) {\r
2225 if (ScreenOperation == gScreenOperationToControlFlag[Index].ScreenOperation) {\r
2226 ControlFlag = gScreenOperationToControlFlag[Index].ControlFlag;\r
2227 break;\r
2228 }\r
2229 }\r
2230 break;\r
2231\r
2232 case CfUiPrevious:\r
2233 ControlFlag = CfCheckSelection;\r
2234\r
2235 if (IsListEmpty (&gMenuList)) {\r
2236 Selection->Action = UI_ACTION_NONE;\r
2237 if (IsListEmpty (&Menu)) {\r
2238 ControlFlag = CfReadKey;\r
2239 }\r
2240 break;\r
2241 }\r
2242\r
2243 //\r
2244 // Remove the Cached page entry\r
2245 //\r
2246 UiRemoveMenuListEntry (Selection);\r
2247\r
2248 Selection->Action = UI_ACTION_REFRESH_FORM;\r
2249 Selection->Statement = NULL;\r
2250 break;\r
2251\r
2252 case CfUiSelect:\r
2253 ControlFlag = CfCheckSelection;\r
2254\r
2255 Statement = MenuOption->ThisTag;\r
2256 if ((Statement->Operand == EFI_IFR_TEXT_OP) ||\r
2257 (Statement->Operand == EFI_IFR_DATE_OP) ||\r
2258 (Statement->Operand == EFI_IFR_TIME_OP) ||\r
2259 (Statement->Operand == EFI_IFR_NUMERIC_OP && Statement->Step != 0)) {\r
2260 break;\r
2261 }\r
2262\r
2263 //\r
2264 // Keep highlight on current MenuOption\r
2265 //\r
2266 Selection->QuestionId = Statement->QuestionId;\r
2267\r
2268 switch (Statement->Operand) {\r
2269 case EFI_IFR_REF_OP:\r
2270 if (Statement->RefDevicePath != 0) {\r
2271 //\r
2272 // Goto another Hii Package list\r
2273 //\r
2274 ControlFlag = CfUiReset;\r
2275 Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
2276\r
2277 StringPtr = GetToken (Statement->RefDevicePath, Selection->FormSet->HiiHandle);\r
2278 if (StringPtr == NULL) {\r
2279 //\r
2280 // No device path string not found, exit\r
2281 //\r
2282 Selection->Action = UI_ACTION_EXIT;\r
2283 Selection->Statement = NULL;\r
2284 break;\r
2285 }\r
2286 BufferSize = StrLen (StringPtr) / 2;\r
2287 DevicePath = AllocatePool (BufferSize);\r
2288\r
2289 HexStringToBuffer ((UINT8 *) DevicePath, &BufferSize, StringPtr);\r
2290 Selection->Handle = HiiLibDevicePathToHiiHandle (DevicePath);\r
2291 if (Selection->Handle == NULL) {\r
2292 //\r
2293 // If target Hii Handle not found, exit\r
2294 //\r
2295 Selection->Action = UI_ACTION_EXIT;\r
2296 Selection->Statement = NULL;\r
2297 break;\r
2298 }\r
2299\r
2300 gBS->FreePool (StringPtr);\r
2301 gBS->FreePool (DevicePath);\r
2302\r
2303 CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));\r
2304 Selection->FormId = Statement->RefFormId;\r
2305 Selection->QuestionId = Statement->RefQuestionId;\r
2306 } else if (!CompareGuid (&Statement->RefFormSetId, &gZeroGuid)) {\r
2307 //\r
2308 // Goto another Formset, check for uncommitted data\r
2309 //\r
2310 ControlFlag = CfUiReset;\r
2311 Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
2312\r
2313 CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));\r
2314 Selection->FormId = Statement->RefFormId;\r
2315 Selection->QuestionId = Statement->RefQuestionId;\r
2316 } else if (Statement->RefFormId != 0) {\r
2317 //\r
2318 // Goto another form inside this formset,\r
2319 //\r
2320 Selection->Action = UI_ACTION_REFRESH_FORM;\r
2321\r
2322 //\r
2323 // Link current form so that we can always go back when someone hits the UiPrevious\r
2324 //\r
2325 UiAddMenuListEntry (Selection);\r
2326\r
2327 Selection->FormId = Statement->RefFormId;\r
2328 Selection->QuestionId = Statement->RefQuestionId;\r
2329 } else if (Statement->RefQuestionId != 0) {\r
2330 //\r
2331 // Goto another Question\r
2332 //\r
2333 Selection->QuestionId = Statement->RefQuestionId;\r
2334\r
2335 if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
2336 Selection->Action = UI_ACTION_REFRESH_FORM;\r
2337 } else {\r
2338 Repaint = TRUE;\r
2339 NewLine = TRUE;\r
2340 break;\r
2341 }\r
2342 }\r
2343 break;\r
2344\r
2345 case EFI_IFR_ACTION_OP:\r
2346 //\r
2347 // Process the Config string <ConfigResp>\r
2348 //\r
2349 Status = ProcessQuestionConfig (Selection, Statement);\r
2350\r
2351 if (EFI_ERROR (Status)) {\r
2352 break;\r
2353 }\r
2354\r
2355 //\r
2356 // The action button may change some Question value, so refresh the form\r
2357 //\r
2358 Selection->Action = UI_ACTION_REFRESH_FORM;\r
2359 break;\r
2360\r
2361 case EFI_IFR_RESET_BUTTON_OP:\r
2362 //\r
2363 // Reset Question to default value specified by DefaultId\r
2364 //\r
2365 ControlFlag = CfUiDefault;\r
2366 DefaultId = Statement->DefaultId;\r
2367 break;\r
2368\r
2369 default:\r
2370 //\r
2371 // Editable Questions: oneof, ordered list, checkbox, numeric, string, password\r
2372 //\r
2373 UpdateKeyHelp (MenuOption, TRUE);\r
2374 Status = ProcessOptions (Selection, MenuOption, TRUE, &OptionString);\r
2375\r
2376 if (EFI_ERROR (Status)) {\r
2377 Repaint = TRUE;\r
2378 NewLine = TRUE;\r
2379 break;\r
2380 }\r
2381\r
2382 if (OptionString != NULL) {\r
2383 PrintStringAt (LocalScreen.LeftColumn + gPromptBlockWidth + 1, MenuOption->Row, OptionString);\r
2384 gBS->FreePool (OptionString);\r
2385 }\r
2386\r
2387 Selection->Action = UI_ACTION_REFRESH_FORM;\r
2388 break;\r
2389 }\r
2390 break;\r
2391\r
2392 case CfUiReset:\r
2393 //\r
2394 // We are going to leave current FormSet, so check uncommited data in this FormSet\r
2395 //\r
2396 ControlFlag = CfCheckSelection;\r
2397\r
2398 if (gClassOfVfr == EFI_FRONT_PAGE_SUBCLASS) {\r
2399 //\r
2400 // There is no parent menu for FrontPage\r
2401 //\r
2402 Selection->Action = UI_ACTION_NONE;\r
2403 Selection->Statement = MenuOption->ThisTag;\r
2404 break;\r
2405 }\r
2406\r
2407 //\r
2408 // If NV flag is up, prompt user\r
2409 //\r
2410 if (gNvUpdateRequired) {\r
2411 Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
2412\r
2413 YesResponse = gYesResponse[0];\r
2414 NoResponse = gNoResponse[0];\r
2415\r
2416 do {\r
2417 CreateDialog (3, TRUE, 0, NULL, &Key, gEmptyString, gAreYouSure, gEmptyString);\r
2418 } while\r
2419 (\r
2420 (Key.ScanCode != SCAN_ESC) &&\r
2421 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&\r
2422 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))\r
2423 );\r
2424\r
2425 //\r
2426 // If the user hits the YesResponse key\r
2427 //\r
2428 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {\r
2429 } else {\r
2430 Repaint = TRUE;\r
2431 NewLine = TRUE;\r
2432\r
2433 Selection->Action = UI_ACTION_NONE;\r
2434 break;\r
2435 }\r
2436 }\r
2437\r
2438 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
2439 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
2440\r
2441 UiFreeMenuList ();\r
2442 gST->ConOut->ClearScreen (gST->ConOut);\r
2443 return EFI_SUCCESS;\r
2444\r
2445 case CfUiLeft:\r
2446 ControlFlag = CfCheckSelection;\r
2447 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
2448 if (MenuOption->Sequence != 0) {\r
2449 //\r
2450 // In the middle or tail of the Date/Time op-code set, go left.\r
2451 //\r
2452 NewPos = NewPos->BackLink;\r
2453 }\r
2454 }\r
2455 break;\r
2456\r
2457 case CfUiRight:\r
2458 ControlFlag = CfCheckSelection;\r
2459 if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) || (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)) {\r
2460 if (MenuOption->Sequence != 2) {\r
2461 //\r
2462 // In the middle or tail of the Date/Time op-code set, go left.\r
2463 //\r
2464 NewPos = NewPos->ForwardLink;\r
2465 }\r
2466 }\r
2467 break;\r
2468\r
2469 case CfUiUp:\r
2470 ControlFlag = CfCheckSelection;\r
2471\r
2472 SavedListEntry = TopOfScreen;\r
2473\r
2474 if (NewPos->BackLink != &Menu) {\r
2475 NewLine = TRUE;\r
2476 //\r
2477 // Adjust Date/Time position before we advance forward.\r
2478 //\r
2479 AdjustDateAndTimePosition (TRUE, &NewPos);\r
2480\r
2481 //\r
2482 // Caution that we have already rewind to the top, don't go backward in this situation.\r
2483 //\r
2484 if (NewPos->BackLink != &Menu) {\r
2485 NewPos = NewPos->BackLink;\r
2486 }\r
2487\r
2488 PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
2489 DistanceValue = PreviousMenuOption->Skip;\r
2490\r
2491 //\r
2492 // Since the behavior of hitting the up arrow on a Date/Time op-code is intended\r
2493 // to be one that back to the previous set of op-codes, we need to advance to the sencond\r
2494 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate\r
2495 // checking can be done.\r
2496 //\r
2497 DistanceValue += AdjustDateAndTimePosition (TRUE, &NewPos);\r
2498\r
2499 //\r
2500 // Check the previous menu entry to see if it was a zero-length advance. If it was,\r
2501 // don't worry about a redraw.\r
2502 //\r
2503 if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) {\r
2504 Repaint = TRUE;\r
2505 TopOfScreen = NewPos;\r
2506 }\r
2507\r
2508 Difference = MoveToNextStatement (TRUE, &NewPos);\r
2509 if ((INTN) MenuOption->Row - (INTN) DistanceValue < (INTN) TopRow) {\r
2510 if (Difference > 0) {\r
2511 //\r
2512 // Previous focus MenuOption is above the TopOfScreen, so we need to scroll\r
2513 //\r
2514 TopOfScreen = NewPos;\r
2515 Repaint = TRUE;\r
2516 }\r
2517 }\r
2518 if (Difference < 0) {\r
2519 //\r
2520 // We want to goto previous MenuOption, but finally we go down.\r
2521 // it means that we hit the begining MenuOption that can be focused\r
2522 // so we simply scroll to the top\r
2523 //\r
2524 if (SavedListEntry != Menu.ForwardLink) {\r
2525 TopOfScreen = Menu.ForwardLink;\r
2526 Repaint = TRUE;\r
2527 }\r
2528 }\r
2529\r
2530 //\r
2531 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.\r
2532 //\r
2533 AdjustDateAndTimePosition (TRUE, &TopOfScreen);\r
2534\r
2535 UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);\r
2536 } else {\r
2537 SavedMenuOption = MenuOption;\r
2538 MenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
2539 if (!IsSelectable (MenuOption)) {\r
2540 //\r
2541 // If we are at the end of the list and sitting on a text op, we need to more forward\r
2542 //\r
2543 ScreenOperation = UiDown;\r
2544 ControlFlag = CfScreenOperation;\r
2545 break;\r
2546 }\r
2547\r
2548 MenuOption = SavedMenuOption;\r
2549 }\r
2550 break;\r
2551\r
2552 case CfUiPageUp:\r
2553 ControlFlag = CfCheckSelection;\r
2554\r
2555 if (NewPos->BackLink == &Menu) {\r
2556 NewLine = FALSE;\r
2557 Repaint = FALSE;\r
2558 break;\r
2559 }\r
2560\r
2561 NewLine = TRUE;\r
2562 Repaint = TRUE;\r
2563 Link = TopOfScreen;\r
2564 PreviousMenuOption = MENU_OPTION_FROM_LINK (Link);\r
2565 Index = BottomRow;\r
2566 while ((Index >= TopRow) && (Link->BackLink != &Menu)) {\r
2567 Index = Index - PreviousMenuOption->Skip;\r
2568 Link = Link->BackLink;\r
2569 PreviousMenuOption = MENU_OPTION_FROM_LINK (Link);\r
2570 }\r
2571\r
2572 TopOfScreen = Link;\r
2573 Difference = MoveToNextStatement (TRUE, &Link);\r
2574 if (Difference > 0) {\r
2575 //\r
2576 // The focus MenuOption is above the TopOfScreen\r
2577 //\r
2578 TopOfScreen = Link;\r
2579 } else if (Difference < 0) {\r
2580 //\r
2581 // This happens when there is no MenuOption can be focused from\r
2582 // Current MenuOption to the first MenuOption\r
2583 //\r
2584 TopOfScreen = Menu.ForwardLink;\r
2585 }\r
2586 Index += Difference;\r
2587 if (Index < TopRow) {\r
2588 MenuOption = NULL;\r
2589 }\r
2590\r
2591 if (NewPos == Link) {\r
2592 Repaint = FALSE;\r
2593 NewLine = FALSE;\r
2594 } else {\r
2595 NewPos = Link;\r
2596 }\r
2597\r
2598 //\r
2599 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.\r
2600 // Don't do this when we are already in the first page.\r
2601 //\r
2602 AdjustDateAndTimePosition (TRUE, &TopOfScreen);\r
2603 AdjustDateAndTimePosition (TRUE, &NewPos);\r
2604 break;\r
2605\r
2606 case CfUiPageDown:\r
2607 ControlFlag = CfCheckSelection;\r
2608\r
2609 if (NewPos->ForwardLink == &Menu) {\r
2610 NewLine = FALSE;\r
2611 Repaint = FALSE;\r
2612 break;\r
2613 }\r
2614\r
2615 NewLine = TRUE;\r
2616 Repaint = TRUE;\r
2617 Link = TopOfScreen;\r
2618 NextMenuOption = MENU_OPTION_FROM_LINK (Link);\r
2619 Index = TopRow;\r
2620 while ((Index <= BottomRow) && (Link->ForwardLink != &Menu)) {\r
2621 Index = Index + NextMenuOption->Skip;\r
2622 Link = Link->ForwardLink;\r
2623 NextMenuOption = MENU_OPTION_FROM_LINK (Link);\r
2624 }\r
2625\r
2626 Index += MoveToNextStatement (FALSE, &Link);\r
2627 if (Index > BottomRow) {\r
2628 //\r
2629 // There are more MenuOption needing scrolling\r
2630 //\r
2631 TopOfScreen = Link;\r
2632 MenuOption = NULL;\r
2633 }\r
2634 if (NewPos == Link && Index <= BottomRow) {\r
2635 //\r
2636 // Finally we know that NewPos is the last MenuOption can be focused.\r
2637 //\r
2638 NewLine = FALSE;\r
2639 Repaint = FALSE;\r
2640 } else {\r
2641 NewPos = Link;\r
2642 }\r
2643\r
2644 //\r
2645 // If we encounter a Date/Time op-code set, rewind to the first op-code of the set.\r
2646 // Don't do this when we are already in the last page.\r
2647 //\r
2648 AdjustDateAndTimePosition (TRUE, &TopOfScreen);\r
2649 AdjustDateAndTimePosition (TRUE, &NewPos);\r
2650 break;\r
2651\r
2652 case CfUiDown:\r
2653 ControlFlag = CfCheckSelection;\r
2654 //\r
2655 // Since the behavior of hitting the down arrow on a Date/Time op-code is intended\r
2656 // to be one that progresses to the next set of op-codes, we need to advance to the last\r
2657 // Date/Time op-code and leave the remaining logic in UiDown intact so the appropriate\r
2658 // checking can be done. The only other logic we need to introduce is that if a Date/Time\r
2659 // op-code is the last entry in the menu, we need to rewind back to the first op-code of\r
2660 // the Date/Time op-code.\r
2661 //\r
2662 SavedListEntry = NewPos;\r
2663 DistanceValue = AdjustDateAndTimePosition (FALSE, &NewPos);\r
2664\r
2665 if (NewPos->ForwardLink != &Menu) {\r
2666 MenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
2667 NewLine = TRUE;\r
2668 NewPos = NewPos->ForwardLink;\r
2669 NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
2670\r
2671 DistanceValue += NextMenuOption->Skip;\r
2672 DistanceValue += MoveToNextStatement (FALSE, &NewPos);\r
2673 //\r
2674 // An option might be multi-line, so we need to reflect that data in the overall skip value\r
2675 //\r
2676 UpdateOptionSkipLines (Selection, NextMenuOption, &OptionString, SkipValue);\r
2677\r
2678 Temp = MenuOption->Row + MenuOption->Skip + DistanceValue - 1;\r
2679 if ((MenuOption->Row + MenuOption->Skip == BottomRow + 1) &&\r
2680 (NextMenuOption->ThisTag->Operand == EFI_IFR_DATE_OP ||\r
2681 NextMenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)\r
2682 ) {\r
2683 Temp ++;\r
2684 }\r
2685\r
2686 //\r
2687 // If we are going to scroll, update TopOfScreen\r
2688 //\r
2689 if (Temp > BottomRow) {\r
2690 do {\r
2691 //\r
2692 // Is the current top of screen a zero-advance op-code?\r
2693 // If so, keep moving forward till we hit a >0 advance op-code\r
2694 //\r
2695 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);\r
2696\r
2697 //\r
2698 // If bottom op-code is more than one line or top op-code is more than one line\r
2699 //\r
2700 if ((DistanceValue > 1) || (MenuOption->Skip > 1)) {\r
2701 //\r
2702 // Is the bottom op-code greater than or equal in size to the top op-code?\r
2703 //\r
2704 if ((Temp - BottomRow) >= (SavedMenuOption->Skip - OldSkipValue)) {\r
2705 //\r
2706 // Skip the top op-code\r
2707 //\r
2708 TopOfScreen = TopOfScreen->ForwardLink;\r
2709 Difference = (Temp - BottomRow) - (SavedMenuOption->Skip - OldSkipValue);\r
2710\r
2711 OldSkipValue = Difference;\r
2712\r
2713 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);\r
2714\r
2715 //\r
2716 // If we have a remainder, skip that many more op-codes until we drain the remainder\r
2717 //\r
2718 for (;\r
2719 Difference >= (INTN) SavedMenuOption->Skip;\r
2720 Difference = Difference - (INTN) SavedMenuOption->Skip\r
2721 ) {\r
2722 //\r
2723 // Since the Difference is greater than or equal to this op-code's skip value, skip it\r
2724 //\r
2725 TopOfScreen = TopOfScreen->ForwardLink;\r
2726 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);\r
2727 if (Difference < (INTN) SavedMenuOption->Skip) {\r
2728 Difference = SavedMenuOption->Skip - Difference - 1;\r
2729 break;\r
2730 } else {\r
2731 if (Difference == (INTN) SavedMenuOption->Skip) {\r
2732 TopOfScreen = TopOfScreen->ForwardLink;\r
2733 SavedMenuOption = MENU_OPTION_FROM_LINK (TopOfScreen);\r
2734 Difference = SavedMenuOption->Skip - Difference;\r
2735 break;\r
2736 }\r
2737 }\r
2738 }\r
2739 //\r
2740 // Since we will act on this op-code in the next routine, and increment the\r
2741 // SkipValue, set the skips to one less than what is required.\r
2742 //\r
2743 SkipValue = Difference - 1;\r
2744\r
2745 } else {\r
2746 //\r
2747 // Since we will act on this op-code in the next routine, and increment the\r
2748 // SkipValue, set the skips to one less than what is required.\r
2749 //\r
2750 SkipValue = OldSkipValue + (Temp - BottomRow) - 1;\r
2751 }\r
2752 } else {\r
2753 if ((OldSkipValue + 1) == (INTN) SavedMenuOption->Skip) {\r
2754 TopOfScreen = TopOfScreen->ForwardLink;\r
2755 break;\r
2756 } else {\r
2757 SkipValue = OldSkipValue;\r
2758 }\r
2759 }\r
2760 //\r
2761 // If the op-code at the top of the screen is more than one line, let's not skip it yet\r
2762 // Let's set a skip flag to smoothly scroll the top of the screen.\r
2763 //\r
2764 if (SavedMenuOption->Skip > 1) {\r
2765 if (SavedMenuOption == NextMenuOption) {\r
2766 SkipValue = 0;\r
2767 } else {\r
2768 SkipValue++;\r
2769 }\r
2770 } else {\r
2771 SkipValue = 0;\r
2772 TopOfScreen = TopOfScreen->ForwardLink;\r
2773 }\r
2774 } while (SavedMenuOption->Skip == 0);\r
2775\r
2776 Repaint = TRUE;\r
2777 OldSkipValue = SkipValue;\r
2778 }\r
2779\r
2780 MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);\r
2781\r
2782 UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);\r
2783\r
2784 } else {\r
2785 SavedMenuOption = MenuOption;\r
2786 MenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
2787 if (!IsSelectable (MenuOption)) {\r
2788 //\r
2789 // If we are at the end of the list and sitting on a text op, we need to more forward\r
2790 //\r
2791 ScreenOperation = UiUp;\r
2792 ControlFlag = CfScreenOperation;\r
2793 break;\r
2794 }\r
2795\r
2796 MenuOption = SavedMenuOption;\r
2797 //\r
2798 // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.\r
2799 //\r
2800 AdjustDateAndTimePosition (TRUE, &NewPos);\r
2801 }\r
2802 break;\r
2803\r
2804 case CfUiSave:\r
2805 ControlFlag = CfCheckSelection;\r
2806\r
2807 //\r
2808 // Submit the form\r
2809 //\r
2810 Status = SubmitForm (Selection->FormSet, Selection->Form);\r
2811\r
2812 if (!EFI_ERROR (Status)) {\r
2813 UpdateStatusBar (INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);\r
2814 UpdateStatusBar (NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE);\r
2815 } else {\r
2816 do {\r
2817 CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveFailed, gPressEnter, gEmptyString);\r
2818 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
2819\r
2820 Repaint = TRUE;\r
2821 NewLine = TRUE;\r
2822 }\r
2823 break;\r
2824\r
2825 case CfUiDefault:\r
2826 ControlFlag = CfCheckSelection;\r
2827\r
2828 Status = ExtractFormDefault (Selection->FormSet, Selection->Form, DefaultId);\r
2829\r
2830 if (!EFI_ERROR (Status)) {\r
2831 Selection->Action = UI_ACTION_REFRESH_FORM;\r
2832\r
2833 //\r
2834 // Show NV update flag on status bar\r
2835 //\r
2836 gNvUpdateRequired = TRUE;\r
2837 }\r
2838 break;\r
2839\r
2840 case CfUiNoOperation:\r
2841 ControlFlag = CfCheckSelection;\r
2842 break;\r
2843\r
2844 case CfExit:\r
2845 UiFreeRefreshList ();\r
2846\r
2847 gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));\r
2848 gST->ConOut->SetCursorPosition (gST->ConOut, 0, Row + 4);\r
2849 gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
2850 gST->ConOut->OutputString (gST->ConOut, L"\n");\r
2851\r
2852 return EFI_SUCCESS;\r
2853\r
2854 default:\r
2855 break;\r
2856 }\r
2857 }\r
2858}\r