]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
Add code check to avoid access violation.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
index 44b4d774b7dd9ba1bfe9ca14e702ac49fedf2d1f..1c3a7f6ba441f54879fd2864b3208231b8b3091e 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Utility functions for User Interface functions.\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -50,26 +50,16 @@ SCAN_CODE_TO_SCREEN_OPERATION     gScanCodeToOperation[] = {
   {\r
     SCAN_RIGHT,\r
     UiRight,\r
-  },\r
-  {\r
-    SCAN_F9,\r
-    UiDefault,\r
-  },\r
-  {\r
-    SCAN_F10,\r
-    UiSave\r
   }\r
 };\r
 \r
+UINTN mScanCodeNumber = sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]);\r
+\r
 SCREEN_OPERATION_T0_CONTROL_FLAG  gScreenOperationToControlFlag[] = {\r
   {\r
     UiNoOperation,\r
     CfUiNoOperation,\r
   },\r
-  {\r
-    UiDefault,\r
-    CfUiDefault,\r
-  },\r
   {\r
     UiSelect,\r
     CfUiSelect,\r
@@ -94,10 +84,6 @@ SCREEN_OPERATION_T0_CONTROL_FLAG  gScreenOperationToControlFlag[] = {
     UiReset,\r
     CfUiReset,\r
   },\r
-  {\r
-    UiSave,\r
-    CfUiSave,\r
-  },\r
   {\r
     UiPageUp,\r
     CfUiPageUp,\r
@@ -105,6 +91,10 @@ SCREEN_OPERATION_T0_CONTROL_FLAG  gScreenOperationToControlFlag[] = {
   {\r
     UiPageDown,\r
     CfUiPageDown\r
+  }, \r
+  {\r
+    UiHotKey,\r
+    CfUiHotKey\r
   }\r
 };\r
 \r
@@ -185,6 +175,7 @@ UiFreeMenu (
   of the given parent menu.\r
 \r
   @param  Parent                 The parent of menu to be added.\r
+  @param  HiiHandle              Hii handle related to this formset.\r
   @param  FormSetGuid            The Formset Guid of menu to be added.\r
   @param  FormId                 The Form ID of menu to be added.\r
 \r
@@ -194,6 +185,7 @@ UiFreeMenu (
 UI_MENU_LIST *\r
 UiAddMenuList (\r
   IN OUT UI_MENU_LIST     *Parent,\r
+  IN EFI_HII_HANDLE       HiiHandle,\r
   IN EFI_GUID             *FormSetGuid,\r
   IN UINT16               FormId\r
   )\r
@@ -208,6 +200,7 @@ UiAddMenuList (
   MenuList->Signature = UI_MENU_LIST_SIGNATURE;\r
   InitializeListHead (&MenuList->ChildListHead);\r
 \r
+  MenuList->HiiHandle = HiiHandle;\r
   CopyMem (&MenuList->FormSetGuid, FormSetGuid, sizeof (EFI_GUID));\r
   MenuList->FormId = FormId;\r
   MenuList->Parent = Parent;\r
@@ -226,9 +219,10 @@ UiAddMenuList (
 \r
 \r
 /**\r
-  Search Menu with given FormId in the parent menu and all its child menus.\r
+  Search Menu with given FormId and FormSetGuid in all cached menu list.\r
 \r
   @param  Parent                 The parent of menu to search.\r
+  @param  FormSetGuid            The Formset GUID of the menu to search.  \r
   @param  FormId                 The Form ID of menu to search.\r
 \r
   @return A pointer to menu found or NULL if not found.\r
@@ -237,6 +231,7 @@ UiAddMenuList (
 UI_MENU_LIST *\r
 UiFindChildMenuList (\r
   IN UI_MENU_LIST         *Parent,\r
+  IN EFI_GUID             *FormSetGuid, \r
   IN UINT16               FormId\r
   )\r
 {\r
@@ -244,7 +239,9 @@ UiFindChildMenuList (
   UI_MENU_LIST    *Child;\r
   UI_MENU_LIST    *MenuList;\r
 \r
-  if (Parent->FormId == FormId) {\r
+  ASSERT (Parent != NULL);\r
+\r
+  if (Parent->FormId == FormId && CompareGuid (FormSetGuid, &Parent->FormSetGuid)) {\r
     return Parent;\r
   }\r
 \r
@@ -252,7 +249,7 @@ UiFindChildMenuList (
   while (!IsNull (&Parent->ChildListHead, Link)) {\r
     Child = UI_MENU_LIST_FROM_LINK (Link);\r
 \r
-    MenuList = UiFindChildMenuList (Child, FormId);\r
+    MenuList = UiFindChildMenuList (Child, FormSetGuid, FormId);\r
     if (MenuList != NULL) {\r
       return MenuList;\r
     }\r
@@ -287,14 +284,9 @@ UiFindMenuList (
   while (!IsNull (&gMenuList, Link)) {\r
     MenuList = UI_MENU_LIST_FROM_LINK (Link);\r
 \r
-    if (CompareGuid (FormSetGuid, &MenuList->FormSetGuid)) {\r
-      //\r
-      // This is the formset we are looking for, find the form in this formset\r
-      //\r
-      Child = UiFindChildMenuList (MenuList, FormId);\r
-      if (Child != NULL) {\r
-        return Child;\r
-      }\r
+    Child = UiFindChildMenuList(MenuList, FormSetGuid, FormId);\r
+    if (Child != NULL) {\r
+      return Child;\r
     }\r
 \r
     Link = GetNextNode (&gMenuList, Link);\r
@@ -332,6 +324,102 @@ UiFreeRefreshList (
 }\r
 \r
 \r
+/**\r
+  Process option string for date/time opcode.\r
+\r
+  @param  MenuOption              Menu option point to date/time.\r
+  @param  OptionString            Option string input for process.\r
+  @param  AddOptCol               Whether need to update MenuOption->OptCol. \r
+\r
+**/\r
+VOID \r
+ProcessStringForDateTime (\r
+  UI_MENU_OPTION                  *MenuOption,\r
+  CHAR16                          *OptionString,\r
+  BOOLEAN                         AddOptCol\r
+  )\r
+{\r
+  UINTN Index;\r
+  UINTN Count;\r
+  FORM_BROWSER_STATEMENT          *Statement;\r
+\r
+  ASSERT (MenuOption != NULL && OptionString != NULL);\r
+  \r
+  Statement = MenuOption->ThisTag;\r
+  \r
+  //\r
+  // If leading spaces on OptionString - remove the spaces\r
+  //\r
+  for (Index = 0; OptionString[Index] == L' '; Index++) {\r
+    //\r
+    // Base on the blockspace to get the option column info.\r
+    //\r
+    if (AddOptCol) {\r
+      MenuOption->OptCol++;\r
+    }\r
+  }\r
+  \r
+  for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
+    OptionString[Count] = OptionString[Index];\r
+    Count++;\r
+  }\r
+  OptionString[Count] = CHAR_NULL;\r
+  \r
+  //\r
+  // Enable to suppress field in the opcode base on the flag.\r
+  //\r
+  if (Statement->Operand == EFI_IFR_DATE_OP) {\r
+    //\r
+    // OptionString format is: <**:  **: ****>\r
+    //                        |month|day|year|\r
+    //                          4     3    5\r
+    //\r
+    if ((Statement->Flags & EFI_QF_DATE_MONTH_SUPPRESS) && (MenuOption->Sequence == 0)) {\r
+      //\r
+      // At this point, only "<**:" in the optionstring. \r
+      // Clean the day's ** field, after clean, the format is "<  :"\r
+      //\r
+      SetUnicodeMem (&OptionString[1], 2, L' ');\r
+    } else if ((Statement->Flags & EFI_QF_DATE_DAY_SUPPRESS) && (MenuOption->Sequence == 1)) {\r
+      //\r
+      // At this point, only "**:" in the optionstring. \r
+      // Clean the month's "**" field, after clean, the format is "  :"\r
+      //                \r
+      SetUnicodeMem (&OptionString[0], 2, L' ');\r
+    } else if ((Statement->Flags & EFI_QF_DATE_YEAR_SUPPRESS) && (MenuOption->Sequence == 2)) {\r
+      //\r
+      // At this point, only "****>" in the optionstring. \r
+      // Clean the year's "****" field, after clean, the format is "  >"\r
+      //                \r
+      SetUnicodeMem (&OptionString[0], 4, L' ');\r
+    }\r
+  } else if (Statement->Operand == EFI_IFR_TIME_OP) {\r
+    //\r
+    // OptionString format is: <**:  **:    **>\r
+    //                        |hour|minute|second|\r
+    //                          4     3      3\r
+    //\r
+    if ((Statement->Flags & QF_TIME_HOUR_SUPPRESS) && (MenuOption->Sequence == 0)) {\r
+      //\r
+      // At this point, only "<**:" in the optionstring. \r
+      // Clean the hour's ** field, after clean, the format is "<  :"\r
+      //\r
+      SetUnicodeMem (&OptionString[1], 2, L' ');\r
+    } else if ((Statement->Flags & QF_TIME_MINUTE_SUPPRESS) && (MenuOption->Sequence == 1)) {\r
+      //\r
+      // At this point, only "**:" in the optionstring. \r
+      // Clean the minute's "**" field, after clean, the format is "  :"\r
+      //                \r
+      SetUnicodeMem (&OptionString[0], 2, L' ');\r
+    } else if ((Statement->Flags & QF_TIME_SECOND_SUPPRESS) && (MenuOption->Sequence == 2)) {\r
+      //\r
+      // At this point, only "**>" in the optionstring. \r
+      // Clean the second's "**" field, after clean, the format is "  >"\r
+      //                \r
+      SetUnicodeMem (&OptionString[0], 2, L' ');\r
+    }\r
+  }\r
+}\r
 \r
 /**\r
   Refresh question.\r
@@ -344,7 +432,6 @@ RefreshQuestion (
   )\r
 {\r
   CHAR16                          *OptionString;\r
-  UINTN                           Index;\r
   EFI_STATUS                      Status;\r
   UI_MENU_SELECTION               *Selection;\r
   FORM_BROWSER_STATEMENT          *Question;\r
@@ -361,12 +448,6 @@ RefreshQuestion (
   ProcessOptions (Selection, MenuRefreshEntry->MenuOption, FALSE, &OptionString);\r
 \r
   if (OptionString != NULL) {\r
-    //\r
-    // If leading spaces on OptionString - remove the spaces\r
-    //\r
-    for (Index = 0; OptionString[Index] == L' '; Index++)\r
-      ;\r
-\r
     //\r
     // If old Text is longer than new string, need to clean the old string before paint the newer.\r
     // This option is no need for time/date opcode, because time/data opcode has fixed string length.\r
@@ -383,7 +464,8 @@ RefreshQuestion (
     }\r
 \r
     gST->ConOut->SetAttribute (gST->ConOut, MenuRefreshEntry->CurrentAttribute);\r
-    PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, &OptionString[Index]);\r
+    ProcessStringForDateTime(MenuRefreshEntry->MenuOption, OptionString, FALSE);\r
+    PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, OptionString);\r
     FreePool (OptionString);\r
   }\r
 \r
@@ -585,6 +667,7 @@ UiWaitForSingleEvent (
 \r
   @param  String                 String description for this option.\r
   @param  Handle                 Hii handle for the package list.\r
+  @param  Form                   The form this statement belong to.\r
   @param  Statement              Statement of this Menu Option.\r
   @param  NumberOfLines          Display lines for this Menu Option.\r
   @param  MenuItemCount          The index for this Option in the Menu.\r
@@ -596,6 +679,7 @@ UI_MENU_OPTION *
 UiAddMenuOption (\r
   IN CHAR16                  *String,\r
   IN EFI_HII_HANDLE          Handle,\r
+  IN FORM_BROWSER_FORM       *Form,\r
   IN FORM_BROWSER_STATEMENT  *Statement,\r
   IN UINT16                  NumberOfLines,\r
   IN UINT16                  MenuItemCount\r
@@ -647,10 +731,19 @@ UiAddMenuOption (
     }\r
     MenuOption->Sequence = Index;\r
 \r
-    if (Statement->GrayOutExpression != NULL) {\r
-      MenuOption->GrayOut = Statement->GrayOutExpression->Result.Value.b;\r
+    if (EvaluateExpressionList(Statement->Expression, FALSE, NULL, NULL) == ExpressGrayOut ) {\r
+      MenuOption->GrayOut = TRUE;\r
+    } else {\r
+      MenuOption->GrayOut = FALSE;\r
     }\r
 \r
+    //\r
+    // If the form or the question has the lock attribute, deal same as grayout.\r
+    //\r
+    if (Form->Locked || Statement->Locked) {\r
+      MenuOption->GrayOut = TRUE;\r
+    }\r
+    \r
     switch (Statement->Operand) {\r
     case EFI_IFR_ORDERED_LIST_OP:\r
     case EFI_IFR_ONE_OF_OP:\r
@@ -759,8 +852,6 @@ CreateDialog (
   ASSERT (TempString);\r
   ASSERT (BufferedString);\r
 \r
-  VA_START (Marker, KeyValue);\r
-\r
   //\r
   // Zero the outgoing buffer\r
   //\r
@@ -782,6 +873,8 @@ CreateDialog (
 \r
   LargestString = 0;\r
 \r
+  VA_START (Marker, KeyValue);\r
+\r
   //\r
   // Determine the largest string in the dialog box\r
   // Notice we are starting with 1 since String is the first string\r
@@ -1057,7 +1150,10 @@ UpdateStatusBar (
   UINTN           Index;\r
   CHAR16          *NvUpdateMessage;\r
   CHAR16          *InputErrorMessage;\r
-\r
+  LIST_ENTRY              *Link;\r
+  FORM_BROWSER_FORMSET    *LocalFormSet;\r
+  FORM_BROWSER_STATEMENT  *Question;\r
+  \r
   NvUpdateMessage   = GetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), gHiiHandle);\r
   InputErrorMessage = GetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), gHiiHandle);\r
 \r
@@ -1082,32 +1178,38 @@ UpdateStatusBar (
     break;\r
 \r
   case NV_UPDATE_REQUIRED:\r
-    if ((gClassOfVfr & FORMSET_CLASS_FRONT_PAGE) != FORMSET_CLASS_FRONT_PAGE) {\r
-      if (State) {\r
+    //\r
+    // Global setting support. Show configuration change on every form.\r
+    //\r
+    if (State) {\r
+      gResetRequired    = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED));\r
+\r
+      if (Selection != NULL && Selection->Statement != NULL) {\r
+        Question = Selection->Statement;\r
+        if (Question->Storage != NULL || Question->Operand == EFI_IFR_DATE_OP || Question->Operand == EFI_IFR_TIME_OP) {\r
+          //\r
+          // Update only for Question value that need to be saved into Storage.\r
+          //\r
+          Selection->Form->NvUpdateRequired = TRUE;\r
+        }\r
+      }\r
+      \r
+      if (Selection == NULL || IsNvUpdateRequired (Selection->FormSet)) {\r
         gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT);\r
         PrintStringAt (\r
           gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth,\r
           gScreenDimensions.BottomRow - 1,\r
           NvUpdateMessage\r
           );\r
-        gResetRequired    = (BOOLEAN) (gResetRequired | ((Flags & EFI_IFR_FLAG_RESET_REQUIRED) == EFI_IFR_FLAG_RESET_REQUIRED));\r
-\r
-        if (Selection != NULL) {\r
-          Selection->Form->NvUpdateRequired = TRUE;\r
-        }\r
-      } else {\r
-        gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextHighlightColor));\r
-        for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) {\r
-          PrintAt (\r
-            (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index),\r
-            gScreenDimensions.BottomRow - 1,\r
-            L"  "\r
-            );\r
-        }\r
-\r
-        if (Selection != NULL) {\r
-          Selection->Form->NvUpdateRequired = FALSE;\r
-        }\r
+      }\r
+    } else {\r
+      gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextHighlightColor));\r
+      for (Index = 0; Index < (GetStringWidth (NvUpdateMessage) - 2) / 2; Index++) {\r
+        PrintAt (\r
+          (gScreenDimensions.LeftColumn + gPromptBlockWidth + gOptionBlockWidth + Index),\r
+          gScreenDimensions.BottomRow - 1,\r
+          L"  "\r
+          );\r
       }\r
     }\r
     break;\r
@@ -1117,9 +1219,28 @@ UpdateStatusBar (
       UpdateStatusBar (Selection, INPUT_ERROR, Flags, TRUE);\r
     }\r
 \r
-    if (IsNvUpdateRequired(Selection->FormSet)) {\r
-      UpdateStatusBar (NULL, NV_UPDATE_REQUIRED, Flags, TRUE);\r
+    switch (gBrowserSettingScope) {\r
+    case SystemLevel:\r
+      //\r
+      // Check the maintain list to see whether there is any change.\r
+      //\r
+      Link = GetFirstNode (&gBrowserFormSetList);\r
+      while (!IsNull (&gBrowserFormSetList, Link)) {\r
+        LocalFormSet = FORM_BROWSER_FORMSET_FROM_LINK (Link);\r
+        if (IsNvUpdateRequired(LocalFormSet)) {\r
+          UpdateStatusBar (NULL, NV_UPDATE_REQUIRED, Flags, TRUE);\r
+          break;\r
+        }\r
+        Link = GetNextNode (&gBrowserFormSetList, Link);\r
+      }\r
+      break;\r
+    case FormSetLevel:\r
+    case FormLevel:\r
+      UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Flags, TRUE);\r
+    default:\r
+      break;\r
     }\r
+\r
     break;\r
 \r
   default:\r
@@ -1290,16 +1411,12 @@ GetLineByWidth (
 \r
   @param  Selection              The user's selection.\r
   @param  MenuOption             The MenuOption to be checked.\r
-  @param  OptionalString         The option string.\r
-  @param  SkipValue              The number of lins to skip.\r
 \r
 **/\r
 VOID\r
 UpdateOptionSkipLines (\r
   IN UI_MENU_SELECTION            *Selection,\r
-  IN UI_MENU_OPTION               *MenuOption,\r
-  OUT CHAR16                       **OptionalString,\r
-  IN UINTN                        SkipValue\r
+  IN UI_MENU_OPTION               *MenuOption\r
   )\r
 {\r
   UINTN   Index;\r
@@ -1310,9 +1427,7 @@ UpdateOptionSkipLines (
   CHAR16  *OptionString;\r
 \r
   Row           = 0;\r
-  OptionString  = *OptionalString;\r
-  OutputString  = NULL;\r
-\r
+  OptionString  = NULL;\r
   ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
 \r
   if (OptionString != NULL) {\r
@@ -1325,31 +1440,28 @@ UpdateOptionSkipLines (
       // If there is more string to process print on the next row and increment the Skip value\r
       //\r
       if (StrLen (&OptionString[Index]) != 0) {\r
-        if (SkipValue == 0) {\r
-          Row++;\r
-          //\r
-          // Since the Number of lines for this menu entry may or may not be reflected accurately\r
-          // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
-          // some testing to ensure we are keeping this in-sync.\r
-          //\r
-          // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
-          //\r
-          if ((Row - OriginalRow) >= MenuOption->Skip) {\r
-            MenuOption->Skip++;\r
-          }\r
+        Row++;\r
+        //\r
+        // Since the Number of lines for this menu entry may or may not be reflected accurately\r
+        // since the prompt might be 1 lines and option might be many, and vice versa, we need to do\r
+        // some testing to ensure we are keeping this in-sync.\r
+        //\r
+        // If the difference in rows is greater than or equal to the skip value, increase the skip value\r
+        //\r
+        if ((Row - OriginalRow) >= MenuOption->Skip) {\r
+          MenuOption->Skip++;\r
         }\r
       }\r
 \r
       FreePool (OutputString);\r
-      if (SkipValue != 0) {\r
-        SkipValue--;\r
-      }\r
     }\r
 \r
     Row = OriginalRow;\r
   }\r
 \r
-  *OptionalString = OptionString;\r
+  if (OptionString != NULL) {\r
+    FreePool (OptionString);\r
+  }\r
 }\r
 \r
 \r
@@ -1413,6 +1525,7 @@ ValueIsScroll (
 \r
   This is an internal function.\r
 \r
+  @param  Selection              Menu selection.\r
   @param  GoUp                   The navigation direction. TRUE: up, FALSE: down.\r
   @param  CurrentPosition        Current position.\r
   @param  GapToTop               Gap position to top or bottom.\r
@@ -1422,6 +1535,7 @@ ValueIsScroll (
 **/\r
 INTN\r
 MoveToNextStatement (\r
+  IN     UI_MENU_SELECTION         *Selection,\r
   IN     BOOLEAN                   GoUp,\r
   IN OUT LIST_ENTRY                **CurrentPosition,\r
   IN     UINTN                     GapToTop\r
@@ -1438,6 +1552,10 @@ MoveToNextStatement (
 \r
   while (TRUE) {\r
     NextMenuOption = MENU_OPTION_FROM_LINK (Pos);\r
+    if (NextMenuOption->Row == 0) {\r
+      UpdateOptionSkipLines (Selection, NextMenuOption);\r
+    }\r
+    \r
     if (GoUp && (PreMenuOption != NextMenuOption)) {\r
       //\r
       // Current Position doesn't need to be caculated when go up.\r
@@ -1649,6 +1767,112 @@ DevicePathToHiiHandle (
   return HiiHandle;\r
 }\r
 \r
+/**\r
+  Find HII Handle in the HII database associated with given form set guid.\r
+\r
+  If FormSetGuid is NULL, then ASSERT.\r
+\r
+  @param  ComparingGuid          FormSet Guid associated with the HII package list\r
+                                 handle.\r
+\r
+  @retval Handle                 HII package list Handle associated with the Device\r
+                                        Path.\r
+  @retval NULL                   Hii Package list handle is not found.\r
+\r
+**/\r
+EFI_HII_HANDLE\r
+FormSetGuidToHiiHandle (\r
+  EFI_GUID     *ComparingGuid\r
+  )\r
+{\r
+  EFI_HII_HANDLE               *HiiHandles;\r
+  UINTN                        Index;\r
+  EFI_HII_PACKAGE_LIST_HEADER  *HiiPackageList;\r
+  UINTN                        BufferSize;\r
+  UINT32                       Offset;\r
+  UINT32                       Offset2;\r
+  UINT32                       PackageListLength;\r
+  EFI_HII_PACKAGE_HEADER       PackageHeader;\r
+  UINT8                        *Package;\r
+  UINT8                        *OpCodeData;\r
+  EFI_STATUS                   Status;\r
+  EFI_HII_HANDLE               HiiHandle;\r
+\r
+  ASSERT (ComparingGuid != NULL);\r
+\r
+  HiiHandle  = NULL;\r
+  //\r
+  // Get all the Hii handles\r
+  //\r
+  HiiHandles = HiiGetHiiHandles (NULL);\r
+  ASSERT (HiiHandles != NULL);\r
+\r
+  //\r
+  // Search for formset of each class type\r
+  //\r
+  for (Index = 0; HiiHandles[Index] != NULL; Index++) {\r
+    BufferSize = 0;\r
+    HiiPackageList = NULL;\r
+    Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, HiiHandles[Index], &BufferSize, HiiPackageList);\r
+    if (Status == EFI_BUFFER_TOO_SMALL) {\r
+      HiiPackageList = AllocatePool (BufferSize);\r
+      ASSERT (HiiPackageList != NULL);\r
+\r
+      Status = mHiiDatabase->ExportPackageLists (mHiiDatabase, HiiHandles[Index], &BufferSize, HiiPackageList);\r
+    }\r
+    if (EFI_ERROR (Status) || HiiPackageList == NULL) {\r
+      return NULL;\r
+    }\r
+\r
+    //\r
+    // Get Form package from this HII package List\r
+    //\r
+    Offset = sizeof (EFI_HII_PACKAGE_LIST_HEADER);\r
+    Offset2 = 0;\r
+    CopyMem (&PackageListLength, &HiiPackageList->PackageLength, sizeof (UINT32)); \r
+\r
+    while (Offset < PackageListLength) {\r
+      Package = ((UINT8 *) HiiPackageList) + Offset;\r
+      CopyMem (&PackageHeader, Package, sizeof (EFI_HII_PACKAGE_HEADER));\r
+\r
+      if (PackageHeader.Type == EFI_HII_PACKAGE_FORMS) {\r
+        //\r
+        // Search FormSet in this Form Package\r
+        //\r
+        Offset2 = sizeof (EFI_HII_PACKAGE_HEADER);\r
+        while (Offset2 < PackageHeader.Length) {\r
+          OpCodeData = Package + Offset2;\r
+\r
+          if (((EFI_IFR_OP_HEADER *) OpCodeData)->OpCode == EFI_IFR_FORM_SET_OP) {\r
+            //\r
+            // Try to compare against formset GUID\r
+            //\r
+            if (CompareGuid (ComparingGuid, (EFI_GUID *)(OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {\r
+              HiiHandle = HiiHandles[Index];\r
+              break;\r
+            }\r
+          }\r
+\r
+          Offset2 += ((EFI_IFR_OP_HEADER *) OpCodeData)->Length;\r
+        }\r
+      }\r
+      if (HiiHandle != NULL) {\r
+        break;\r
+      }\r
+      Offset += PackageHeader.Length;\r
+    }\r
+    \r
+    FreePool (HiiPackageList);\r
+       if (HiiHandle != NULL) {\r
+               break;\r
+       }\r
+  }\r
+\r
+  FreePool (HiiHandles);\r
+\r
+  return HiiHandle;\r
+}\r
+\r
 /**\r
   Process the goto op code, update the info in the selection structure.\r
 \r
@@ -1669,6 +1893,7 @@ ProcessGotoOpCode (
   )\r
 {\r
   CHAR16                          *StringPtr;\r
+  UINTN                           StringLen;\r
   UINTN                           BufferSize;\r
   EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
   CHAR16                          TemStr[2];\r
@@ -1679,10 +1904,27 @@ ProcessGotoOpCode (
   EFI_INPUT_KEY                   Key;\r
   EFI_STATUS                      Status;\r
   UI_MENU_LIST                    *MenuList;\r
+  BOOLEAN                         UpdateFormInfo;\r
   \r
   Status = EFI_SUCCESS;\r
+  UpdateFormInfo = TRUE;\r
+  StringPtr = NULL;\r
+  StringLen = 0;\r
 \r
+  //\r
+  // Prepare the device path check, get the device path info first.\r
+  //\r
   if (Statement->HiiValue.Value.ref.DevicePath != 0) {\r
+    StringPtr = GetToken (Statement->HiiValue.Value.ref.DevicePath, Selection->FormSet->HiiHandle);\r
+    if (StringPtr != NULL) {\r
+      StringLen = StrLen (StringPtr);\r
+    }\r
+  }\r
+\r
+  //\r
+  // Check whether the device path string is a valid string.\r
+  //\r
+  if (Statement->HiiValue.Value.ref.DevicePath != 0 && StringPtr != NULL && StringLen != 0) {\r
     if (Selection->Form->ModalForm) {\r
       return Status;\r
     }\r
@@ -1690,16 +1932,6 @@ ProcessGotoOpCode (
     // Goto another Hii Package list\r
     //\r
     Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
-\r
-    StringPtr = GetToken (Statement->HiiValue.Value.ref.DevicePath, Selection->FormSet->HiiHandle);\r
-    if (StringPtr == NULL) {\r
-      //\r
-      // No device path string not found, exit\r
-      //\r
-      Selection->Action = UI_ACTION_EXIT;\r
-      Selection->Statement = NULL;\r
-      return Status;\r
-    }\r
     BufferSize = StrLen (StringPtr) / 2;\r
     DevicePath = AllocatePool (BufferSize);\r
     ASSERT (DevicePath != NULL);\r
@@ -1723,8 +1955,11 @@ ProcessGotoOpCode (
         DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
       }\r
     }\r
+    FreePool (StringPtr);\r
 \r
     Selection->Handle = DevicePathToHiiHandle (DevicePath);\r
+    FreePool (DevicePath);\r
+\r
     if (Selection->Handle == NULL) {\r
       //\r
       // If target Hii Handle not found, exit\r
@@ -1734,9 +1969,6 @@ ProcessGotoOpCode (
       return Status;\r
     }\r
 \r
-    FreePool (StringPtr);\r
-    FreePool (DevicePath);\r
-\r
     CopyMem (&Selection->FormSetGuid,&Statement->HiiValue.Value.ref.FormSetGuid, sizeof (EFI_GUID));\r
     Selection->FormId = Statement->HiiValue.Value.ref.FormId;\r
     Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId;\r
@@ -1748,6 +1980,16 @@ ProcessGotoOpCode (
     // Goto another Formset, check for uncommitted data\r
     //\r
     Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
+    \r
+    Selection->Handle = FormSetGuidToHiiHandle(&Statement->HiiValue.Value.ref.FormSetGuid);\r
+    if (Selection->Handle == NULL) {\r
+      //\r
+      // If target Hii Handle not found, exit\r
+      //\r
+      Selection->Action = UI_ACTION_EXIT;\r
+      Selection->Statement = NULL;\r
+      return Status;\r
+    } \r
 \r
     CopyMem (&Selection->FormSetGuid, &Statement->HiiValue.Value.ref.FormSetGuid, sizeof (EFI_GUID));\r
     Selection->FormId = Statement->HiiValue.Value.ref.FormId;\r
@@ -1759,12 +2001,7 @@ ProcessGotoOpCode (
     RefForm = IdToForm (Selection->FormSet, Statement->HiiValue.Value.ref.FormId);\r
 \r
     if ((RefForm != NULL) && (RefForm->SuppressExpression != NULL)) {\r
-      Status = EvaluateExpression (Selection->FormSet, RefForm, RefForm->SuppressExpression);\r
-      if (EFI_ERROR (Status)) {\r
-        return Status;\r
-      }\r
-\r
-      if (RefForm->SuppressExpression->Result.Value.b) {\r
+      if (EvaluateExpressionList(RefForm->SuppressExpression, TRUE, Selection->FormSet, RefForm) != ExpressFalse) {\r
         //\r
         // Form is suppressed. \r
         //\r
@@ -1783,14 +2020,6 @@ ProcessGotoOpCode (
     //\r
     Selection->Action = UI_ACTION_REFRESH_FORM;\r
 \r
-    //\r
-    // Link current form so that we can always go back when someone hits the ESC\r
-    //\r
-    MenuList = UiFindMenuList (&Selection->FormSetGuid, Statement->HiiValue.Value.ref.FormId);\r
-    if (MenuList == NULL && Selection->CurrentMenu != NULL) {\r
-      MenuList = UiAddMenuList (Selection->CurrentMenu, &Selection->FormSetGuid, Statement->HiiValue.Value.ref.FormId);\r
-    }\r
-\r
     Selection->FormId = Statement->HiiValue.Value.ref.FormId;\r
     Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId;\r
   } else if (Statement->HiiValue.Value.ref.QuestionId != 0) {\r
@@ -1809,10 +2038,22 @@ ProcessGotoOpCode (
         *NewLine = TRUE;\r
       }\r
     }\r
+    UpdateFormInfo = FALSE;\r
   } else {\r
     if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
       Selection->Action = UI_ACTION_REFRESH_FORM;\r
     }\r
+    UpdateFormInfo = FALSE;\r
+  }\r
+\r
+  if (UpdateFormInfo) {\r
+    //\r
+    // Link current form so that we can always go back when someone hits the ESC\r
+    //\r
+    MenuList = UiFindMenuList (&Selection->FormSetGuid, Selection->FormId);\r
+    if (MenuList == NULL && Selection->CurrentMenu != NULL) {\r
+      MenuList = UiAddMenuList (Selection->CurrentMenu, Selection->Handle, &Selection->FormSetGuid, Selection->FormId);\r
+    }\r
   }\r
 \r
   return Status;\r
@@ -1845,7 +2086,6 @@ UiDisplayMenu (
   UINTN                           BottomRow;\r
   UINTN                           OriginalRow;\r
   UINTN                           Index;\r
-  UINT32                          Count;\r
   UINT16                          Width;\r
   CHAR16                          *StringPtr;\r
   CHAR16                          *OptionString;\r
@@ -1877,6 +2117,7 @@ UiDisplayMenu (
   FORM_BROWSER_STATEMENT          *Statement;\r
   UI_MENU_LIST                    *CurrentMenu;\r
   UINTN                           ModalSkipColumn;\r
+  BROWSER_HOT_KEY                 *HotKey;\r
 \r
   CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
 \r
@@ -1898,6 +2139,7 @@ UiDisplayMenu (
   NextMenuOption      = NULL;\r
   PreviousMenuOption  = NULL;\r
   SavedMenuOption     = NULL;\r
+  HotKey              = NULL;\r
   ModalSkipColumn     = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 6;\r
 \r
   ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r
@@ -1916,7 +2158,7 @@ UiDisplayMenu (
     Col = LocalScreen.LeftColumn + LEFT_SKIPPED_COLUMNS;\r
   }\r
 \r
-  BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - FOOTER_HEIGHT - SCROLL_ARROW_HEIGHT - 1;\r
+  BottomRow = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight - SCROLL_ARROW_HEIGHT - 1;\r
 \r
   Selection->TopRow = TopRow;\r
   Selection->BottomRow = BottomRow;\r
@@ -1936,7 +2178,7 @@ UiDisplayMenu (
     //\r
     // Current menu not found, add it to the menu tree\r
     //\r
-    CurrentMenu = UiAddMenuList (NULL, &Selection->FormSetGuid, Selection->FormId);\r
+    CurrentMenu = UiAddMenuList (NULL, Selection->Handle, &Selection->FormSetGuid, Selection->FormId);\r
   }\r
   ASSERT (CurrentMenu != NULL);\r
   Selection->CurrentMenu = CurrentMenu;\r
@@ -2085,19 +2327,7 @@ UiDisplayMenu (
 \r
           if (OptionString != NULL) {\r
             if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {\r
-              //\r
-              // If leading spaces on OptionString - remove the spaces\r
-              //\r
-              for (Index = 0; OptionString[Index] == L' '; Index++) {\r
-                MenuOption->OptCol++;\r
-              }\r
-\r
-              for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
-                OptionString[Count] = OptionString[Index];\r
-                Count++;\r
-              }\r
-\r
-              OptionString[Count] = CHAR_NULL;\r
+              ProcessStringForDateTime(MenuOption, OptionString, TRUE);\r
             }\r
 \r
             Width       = (UINT16) gOptionBlockWidth;\r
@@ -2304,7 +2534,7 @@ UiDisplayMenu (
       ControlFlag = CfUpdateHelpString;\r
       if (InitializedFlag) {\r
         InitializedFlag = FALSE;\r
-        MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);\r
+        MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow);\r
       }\r
 \r
       //\r
@@ -2333,20 +2563,79 @@ UiDisplayMenu (
           for (Index = TopRow; Index <= BottomRow && Link != NewPos;) {\r
             SavedMenuOption = MENU_OPTION_FROM_LINK (Link);\r
             Index += SavedMenuOption->Skip;\r
+            if (Link == TopOfScreen) {\r
+              Index -= OldSkipValue;\r
+            }\r
             Link = Link->ForwardLink;\r
           }\r
+          if (NewPos == Link) {\r
+            SavedMenuOption = MENU_OPTION_FROM_LINK (Link);\r
+          }\r
 \r
-          if (Link != NewPos || Index > BottomRow) {\r
+          //\r
+          // Not find the selected menu in current show page.\r
+          // Have two case to enter this if:\r
+          // 1. Not find the menu at current page.\r
+          // 2. Find the menu in current page, but the menu shows at the bottom and not all info shows.\r
+          //    For case 2, has an exception: The menu can show more than one pages and now only this menu shows.\r
+          //\r
+          // Base on the selected menu will show at the bottom of the page,\r
+          // select the menu which will show at the top of the page.\r
+          //\r
+          if (Link != NewPos || Index > BottomRow || \r
+              (Link == NewPos && (SavedMenuOption->Row + SavedMenuOption->Skip - 1 > BottomRow) && (Link != TopOfScreen))) {\r
+            //\r
+            // Find the MenuOption which has the skip value for Date/Time opcode. \r
+            //\r
+            AdjustDateAndTimePosition(FALSE, &NewPos);\r
             //\r
             // NewPos is not in the current page, simply scroll page so that NewPos is in the end of the page\r
             //\r
+            SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
+            //\r
+            // SavedMenuOption->Row == 0 means the menu not show yet.\r
+            //\r
+            if (SavedMenuOption->Row == 0) {\r
+              UpdateOptionSkipLines (Selection, SavedMenuOption);\r
+            }\r
+\r
+            //\r
+            // Base on the selected menu will show at the bottome of next page, \r
+            // select the menu show at the top of the next page. \r
+            //\r
             Link    = NewPos;\r
-            for (Index = TopRow; Index <= BottomRow; ) {\r
+            for (Index = TopRow + SavedMenuOption->Skip; Index <= BottomRow + 1; ) {            \r
               Link = Link->BackLink;\r
               SavedMenuOption = MENU_OPTION_FROM_LINK (Link);\r
-              Index     += SavedMenuOption->Skip;\r
+              if (SavedMenuOption->Row == 0) {\r
+                UpdateOptionSkipLines (Selection, SavedMenuOption);\r
+              }\r
+              Index += SavedMenuOption->Skip;\r
+            }\r
+\r
+            //\r
+            // Found the menu which will show at the top of the page.\r
+            //\r
+            if (Link == NewPos) {\r
+              //\r
+              // The menu can show more than one pages, just show the menu at the top of the page.\r
+              //\r
+              SkipValue    = 0;\r
+              TopOfScreen  = Link;\r
+              OldSkipValue = SkipValue;\r
+            } else {\r
+              //\r
+              // Check whether need to skip some line for menu shows at the top of the page.\r
+              //\r
+              SkipValue = Index - BottomRow - 1;\r
+              if (SkipValue > 0 && SkipValue < (INTN) SavedMenuOption->Skip) {\r
+                TopOfScreen     = Link;\r
+                OldSkipValue    = SkipValue;\r
+              } else {\r
+                SkipValue       = 0;\r
+                TopOfScreen     = Link->ForwardLink;\r
+              }\r
             }\r
-            TopOfScreen     = Link->ForwardLink;\r
 \r
             Repaint = TRUE;\r
             NewLine = TRUE;\r
@@ -2375,18 +2664,7 @@ UiDisplayMenu (
             if ((MenuOption->ThisTag->Operand == EFI_IFR_DATE_OP) ||\r
                 (MenuOption->ThisTag->Operand == EFI_IFR_TIME_OP)\r
                ) {\r
-              //\r
-              // If leading spaces on OptionString - remove the spaces\r
-              //\r
-              for (Index = 0; OptionString[Index] == L' '; Index++)\r
-                ;\r
-\r
-              for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
-                OptionString[Count] = OptionString[Index];\r
-                Count++;\r
-              }\r
-\r
-              OptionString[Count] = CHAR_NULL;\r
+              ProcessStringForDateTime(MenuOption, OptionString, FALSE);\r
             }\r
 \r
             Width               = (UINT16) gOptionBlockWidth;\r
@@ -2485,18 +2763,7 @@ UiDisplayMenu (
         ProcessOptions (Selection, MenuOption, FALSE, &OptionString);\r
         if (OptionString != NULL) {\r
           if (Statement->Operand == EFI_IFR_DATE_OP || Statement->Operand == EFI_IFR_TIME_OP) {\r
-            //\r
-            // If leading spaces on OptionString - remove the spaces\r
-            //\r
-            for (Index = 0; OptionString[Index] == L' '; Index++)\r
-              ;\r
-\r
-            for (Count = 0; OptionString[Index] != CHAR_NULL; Index++) {\r
-              OptionString[Count] = OptionString[Index];\r
-              Count++;\r
-            }\r
-\r
-            OptionString[Count] = CHAR_NULL;\r
+            ProcessStringForDateTime(MenuOption, OptionString, FALSE);\r
           }\r
           Width               = (UINT16) gOptionBlockWidth;\r
 \r
@@ -2620,8 +2887,9 @@ UiDisplayMenu (
         //\r
         // IFR is updated in Callback of refresh opcode, re-parse it\r
         //\r
+        ControlFlag = CfCheckSelection;\r
         Selection->Statement = NULL;\r
-        return EFI_SUCCESS;\r
+        break;\r
       }\r
 \r
       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
@@ -2635,6 +2903,11 @@ UiDisplayMenu (
 \r
       switch (Key.UnicodeChar) {\r
       case CHAR_CARRIAGE_RETURN:\r
+        if(MenuOption->GrayOut || MenuOption->ReadOnly) {\r
+          ControlFlag = CfReadKey;\r
+          break;\r
+        }\r
+\r
         ScreenOperation = UiSelect;\r
         gDirection      = 0;\r
         break;\r
@@ -2649,7 +2922,7 @@ UiDisplayMenu (
         // If the screen has no menu items, and the user didn't select UiReset\r
         // ignore the selection and go back to reading keys.\r
         //\r
-        if(IsListEmpty (&gMenuOption)) {\r
+        if(IsListEmpty (&gMenuOption) || MenuOption->GrayOut || MenuOption->ReadOnly) {\r
           ControlFlag = CfReadKey;\r
           break;\r
         }\r
@@ -2702,37 +2975,35 @@ UiDisplayMenu (
           }\r
           \r
           ASSERT(MenuOption != NULL);\r
-          if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut) {\r
+          if (MenuOption->ThisTag->Operand == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut && !MenuOption->ReadOnly) {\r
             ScreenOperation = UiSelect;\r
           }\r
         }\r
         break;\r
 \r
       case CHAR_NULL:\r
-        if (((Key.ScanCode == SCAN_F9) && ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE)) ||\r
-            ((Key.ScanCode == SCAN_F10) && ((gFunctionKeySetting & FUNCTION_TEN) != FUNCTION_TEN))\r
-            ) {\r
+        for (Index = 0; Index < mScanCodeNumber; Index++) {\r
+          if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {\r
+            ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;\r
+            break;\r
+          }\r
+        }\r
+        \r
+        if (Selection->Form->ModalForm && (Key.ScanCode == SCAN_ESC || Index == mScanCodeNumber)) {\r
           //\r
-          // If the function key has been disabled, just ignore the key.\r
+          // ModalForm has no ESC key and Hot Key.\r
           //\r
-        } else {\r
-          for (Index = 0; Index < sizeof (gScanCodeToOperation) / sizeof (gScanCodeToOperation[0]); Index++) {\r
-            if (Selection->Form->ModalForm && \r
-              (Key.ScanCode == SCAN_F9 || Key.ScanCode == SCAN_F10 || Key.ScanCode == SCAN_ESC)) {\r
-              ControlFlag = CfReadKey;\r
-              break;\r
-            }\r
-\r
-            if (Key.ScanCode == gScanCodeToOperation[Index].ScanCode) {\r
-              if (Key.ScanCode == SCAN_F9) {\r
-                //\r
-                // Reset to standard default\r
-                //\r
-                DefaultId = EFI_HII_DEFAULT_CLASS_STANDARD;\r
-              }\r
-              ScreenOperation = gScanCodeToOperation[Index].ScreenOperation;\r
-              break;\r
-            }\r
+          ControlFlag = CfReadKey;\r
+        } else if (Index == mScanCodeNumber) {\r
+          //\r
+          // Check whether Key matches the registered hot key.\r
+          //\r
+          HotKey = NULL;\r
+          if ((gBrowserSettingScope == SystemLevel) || (gFunctionKeySetting != NONE_FUNCTION_KEY_SETTING)) {\r
+            HotKey = GetHotKeyFromRegisterList (&Key);\r
+          }\r
+          if (HotKey != NULL) {\r
+            ScreenOperation = UiHotKey;\r
           }\r
         }\r
         break;\r
@@ -2832,9 +3103,7 @@ UiDisplayMenu (
       // We come here when someone press ESC\r
       //\r
       ControlFlag = CfCheckSelection;\r
-      if (FindNextMenu (Selection, &Repaint, &NewLine)) {\r
-        return EFI_SUCCESS;\r
-      } \r
+      FindNextMenu (Selection, &Repaint, &NewLine);\r
       break;\r
 \r
     case CfUiLeft:\r
@@ -2882,10 +3151,13 @@ UiDisplayMenu (
         NewPos     = NewPos->BackLink;\r
 \r
         PreviousMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
+        if (PreviousMenuOption->Row == 0) {\r
+          UpdateOptionSkipLines (Selection, PreviousMenuOption);\r
+        }\r
         DistanceValue = PreviousMenuOption->Skip;\r
         Difference    = 0;\r
         if (MenuOption->Row >= DistanceValue + TopRow) {\r
-          Difference = MoveToNextStatement (TRUE, &NewPos, MenuOption->Row - TopRow - DistanceValue);\r
+          Difference = MoveToNextStatement (Selection, TRUE, &NewPos, MenuOption->Row - TopRow - DistanceValue);\r
         }\r
         NextMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
        \r
@@ -2960,6 +3232,9 @@ UiDisplayMenu (
       while ((Index >= TopRow) && (Link->BackLink != &gMenuOption)) {\r
         Link = Link->BackLink;\r
         PreviousMenuOption = MENU_OPTION_FROM_LINK (Link);\r
+        if (PreviousMenuOption->Row == 0) {\r
+          UpdateOptionSkipLines (Selection, PreviousMenuOption);\r
+        }        \r
         if (Index < PreviousMenuOption->Skip) {\r
           Index = 0;\r
           break;\r
@@ -2971,19 +3246,19 @@ UiDisplayMenu (
         if (TopOfScreen == &gMenuOption) {\r
           TopOfScreen = gMenuOption.ForwardLink;\r
           NewPos      = gMenuOption.BackLink;\r
-          MoveToNextStatement (TRUE, &NewPos, BottomRow - TopRow);\r
+          MoveToNextStatement (Selection, TRUE, &NewPos, BottomRow - TopRow);\r
           Repaint = FALSE;\r
         } else if (TopOfScreen != Link) {\r
           TopOfScreen = Link;\r
           NewPos      = Link;\r
-          MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);\r
+          MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow);\r
         } else {\r
           //\r
           // Finally we know that NewPos is the last MenuOption can be focused.\r
           //\r
           Repaint = FALSE;\r
           NewPos  = Link;\r
-          MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);\r
+          MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow);\r
         }\r
       } else {\r
         if (Index + 1 < TopRow) {\r
@@ -2998,10 +3273,10 @@ UiDisplayMenu (
         //\r
         if (TopOfScreen == &gMenuOption) {\r
           NewPos = gMenuOption.BackLink;\r
-          MoveToNextStatement (TRUE, &NewPos, BottomRow - TopRow);\r
+          MoveToNextStatement (Selection, TRUE, &NewPos, BottomRow - TopRow);\r
         } else {\r
           NewPos = Link;\r
-          MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);\r
+          MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow);\r
         }\r
 \r
         //\r
@@ -3045,7 +3320,7 @@ UiDisplayMenu (
         // Finally we know that NewPos is the last MenuOption can be focused.\r
         //\r
         Repaint = FALSE;\r
-        MoveToNextStatement (TRUE, &Link, Index - TopRow);\r
+        MoveToNextStatement (Selection, TRUE, &Link, Index - TopRow);\r
       } else {\r
         if (Index - 1 > BottomRow) {\r
           //\r
@@ -3061,7 +3336,7 @@ UiDisplayMenu (
         //\r
         // Move to the option in Next page.\r
         //\r
-        MoveToNextStatement (FALSE, &Link, BottomRow - TopRow);\r
+        MoveToNextStatement (Selection, FALSE, &Link, BottomRow - TopRow);\r
       }\r
 \r
       //\r
@@ -3093,7 +3368,7 @@ UiDisplayMenu (
 \r
         Difference      = 0;\r
         if (BottomRow >= MenuOption->Row + MenuOption->Skip) {\r
-          Difference    = MoveToNextStatement (FALSE, &NewPos, BottomRow - MenuOption->Row - MenuOption->Skip);\r
+          Difference    = MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - MenuOption->Row - MenuOption->Skip);\r
           //\r
           // We hit the end of MenuOption that can be focused\r
           // so we simply scroll to the first page.\r
@@ -3110,7 +3385,7 @@ UiDisplayMenu (
               MenuOption = MENU_OPTION_FROM_LINK (SavedListEntry);\r
             }\r
             NewPos        = gMenuOption.ForwardLink;\r
-            MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);\r
+            MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow);\r
     \r
             //\r
             // If we are at the end of the list and sitting on a Date/Time op, rewind to the head.\r
@@ -3125,7 +3400,7 @@ UiDisplayMenu (
         //\r
         // An option might be multi-line, so we need to reflect that data in the overall skip value\r
         //\r
-        UpdateOptionSkipLines (Selection, NextMenuOption, &OptionString, (UINTN) SkipValue);\r
+        UpdateOptionSkipLines (Selection, NextMenuOption);\r
         DistanceValue  = Difference + NextMenuOption->Skip;\r
 \r
         Temp = MenuOption->Row + MenuOption->Skip + DistanceValue - 1;\r
@@ -3242,7 +3517,7 @@ UiDisplayMenu (
         }\r
         NewLine       = TRUE;\r
         NewPos        = gMenuOption.ForwardLink;\r
-        MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow);\r
+        MoveToNextStatement (Selection, FALSE, &NewPos, BottomRow - TopRow);\r
       }\r
 \r
       //\r
@@ -3252,43 +3527,120 @@ UiDisplayMenu (
       AdjustDateAndTimePosition (TRUE, &NewPos);\r
       break;\r
 \r
-    case CfUiSave:\r
+    case CfUiHotKey:\r
       ControlFlag = CfCheckSelection;\r
-\r
+      \r
+      Status = EFI_SUCCESS;\r
       //\r
-      // Submit the form\r
+      // Discard changes. After it, no NV flag is showed.\r
       //\r
-      Status = SubmitForm (Selection->FormSet, Selection->Form, FALSE);\r
+      if ((HotKey->Action & BROWSER_ACTION_DISCARD) == BROWSER_ACTION_DISCARD) {\r
+        Status = DiscardForm (Selection->FormSet, Selection->Form, gBrowserSettingScope);\r
+        if (!EFI_ERROR (Status)) {\r
+          Selection->Action = UI_ACTION_REFRESH_FORM;\r
+          Selection->Statement = NULL;\r
+          gResetRequired = FALSE;\r
+        } else {\r
+          do {\r
+            CreateDialog (4, TRUE, 0, NULL, &Key, HotKey->HelpString, gDiscardFailed, gPressEnter, gEmptyString);\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+          //\r
+          // Still show current page.\r
+          //\r
+          Selection->Action = UI_ACTION_NONE;\r
+          Repaint = TRUE;\r
+          NewLine = TRUE;\r
+          break;\r
+        }\r
+      }\r
 \r
-      if (!EFI_ERROR (Status)) {\r
-        ASSERT(MenuOption != NULL);\r
-        UpdateStatusBar (Selection, INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);\r
-        UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE);\r
-      } else {\r
-        do {\r
-          CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gSaveFailed, gPressEnter, gEmptyString);\r
-        } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+      //\r
+      // Reterieve default setting. After it. NV flag will be showed.\r
+      //\r
+      if ((HotKey->Action & BROWSER_ACTION_DEFAULT) == BROWSER_ACTION_DEFAULT) {\r
+        Status = ExtractDefault (Selection->FormSet, Selection->Form, HotKey->DefaultId, gBrowserSettingScope);\r
+        if (!EFI_ERROR (Status)) {\r
+          Selection->Action = UI_ACTION_REFRESH_FORM;\r
+          Selection->Statement = NULL;\r
+          gResetRequired = TRUE;\r
+        } else {\r
+          do {\r
+            CreateDialog (4, TRUE, 0, NULL, &Key, HotKey->HelpString, gDefaultFailed, gPressEnter, gEmptyString);\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+          //\r
+          // Still show current page.\r
+          //\r
+          Selection->Action = UI_ACTION_NONE;\r
+          Repaint = TRUE;\r
+          NewLine = TRUE;\r
+          break;\r
+        }\r
+      }\r
 \r
-        Repaint = TRUE;\r
-        NewLine = TRUE;\r
+      //\r
+      // Save changes. After it, no NV flag is showed.\r
+      //\r
+      if ((HotKey->Action & BROWSER_ACTION_SUBMIT) == BROWSER_ACTION_SUBMIT) {\r
+        Status = SubmitForm (Selection->FormSet, Selection->Form, gBrowserSettingScope);\r
+        if (!EFI_ERROR (Status)) {\r
+          ASSERT(MenuOption != NULL);\r
+          UpdateStatusBar (Selection, INPUT_ERROR, MenuOption->ThisTag->QuestionFlags, FALSE);\r
+          UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, MenuOption->ThisTag->QuestionFlags, FALSE);\r
+        } else {\r
+          do {\r
+            CreateDialog (4, TRUE, 0, NULL, &Key, HotKey->HelpString, gSaveFailed, gPressEnter, gEmptyString);\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+          //\r
+          // Still show current page.\r
+          //\r
+          Selection->Action = UI_ACTION_NONE;\r
+          Repaint = TRUE;\r
+          NewLine = TRUE;\r
+          break;\r
+        }\r
+      }\r
+      \r
+      //\r
+      // Set Reset required Flag\r
+      //\r
+      if ((HotKey->Action & BROWSER_ACTION_RESET) == BROWSER_ACTION_RESET) {\r
+        gResetRequired = TRUE;\r
+      }\r
+      \r
+      //\r
+      // Exit Action\r
+      //\r
+      if ((HotKey->Action & BROWSER_ACTION_EXIT) == BROWSER_ACTION_EXIT) {\r
+        //\r
+        // Form Exit without saving, Similar to ESC Key.\r
+        // FormSet Exit without saving, Exit SendForm.\r
+        // System Exit without saving, CallExitHandler and Exit SendForm.\r
+        //\r
+        DiscardForm (Selection->FormSet, Selection->Form, gBrowserSettingScope);\r
+        if (gBrowserSettingScope == FormLevel) {\r
+          ControlFlag = CfUiReset;\r
+        } else if (gBrowserSettingScope == FormSetLevel) {\r
+          Selection->Action = UI_ACTION_EXIT;\r
+        } else if (gBrowserSettingScope == SystemLevel) {\r
+          if (ExitHandlerFunction != NULL) {\r
+            ExitHandlerFunction ();\r
+          }\r
+          Selection->Action = UI_ACTION_EXIT;\r
+        }\r
+        Selection->Statement = NULL;\r
       }\r
       break;\r
 \r
     case CfUiDefault:\r
       ControlFlag = CfCheckSelection;\r
       //\r
-      // Reset to default values for the whole formset\r
+      // Reset to default value for all forms in the whole system.\r
       //\r
-      Status = ExtractFormSetDefault (Selection->FormSet, DefaultId);\r
+      Status = ExtractDefault (Selection->FormSet, NULL, DefaultId, FormSetLevel);\r
 \r
       if (!EFI_ERROR (Status)) {\r
         Selection->Action = UI_ACTION_REFRESH_FORM;\r
         Selection->Statement = NULL;\r
-\r
-        //\r
-        // Show NV update flag on status bar\r
-        //\r
-        UpdateNvInfoInForm(Selection->FormSet, TRUE);\r
         gResetRequired = TRUE;\r
       }\r
       break;\r