]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
Return EFI_WRITE_PROTECTED when setting HwErrRecSupport Global Variable at runtime.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
index 755fb3b2bccb3e4ee9ff80e0363ba283edb382fd..d59109317df6cc3a86f769e22466806bd1e96e16 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
@@ -1187,101 +1308,174 @@ GetWidth (
 /**\r
   Will copy LineWidth amount of a string in the OutputString buffer and return the\r
   number of CHAR16 characters that were copied into the OutputString buffer.\r
+  The output string format is:\r
+    Glyph Info + String info + '\0'.\r
+\r
+  In the code, it deals \r,\n,\r\n same as \n\r, also it not process the \r or \g.\r
 \r
   @param  InputString            String description for this option.\r
   @param  LineWidth              Width of the desired string to extract in CHAR16\r
                                  characters\r
+  @param  GlyphWidth             The glyph width of the begin of the char in the string.\r
   @param  Index                  Where in InputString to start the copy process\r
   @param  OutputString           Buffer to copy the string into\r
 \r
-  @return Returns the number of CHAR16 characters that were copied into the OutputString buffer.\r
+  @return Returns the number of CHAR16 characters that were copied into the OutputString \r
+  buffer, include extra glyph info and '\0' info.\r
 \r
 **/\r
 UINT16\r
 GetLineByWidth (\r
   IN      CHAR16                      *InputString,\r
   IN      UINT16                      LineWidth,\r
+  IN OUT  UINT16                      *GlyphWidth,\r
   IN OUT  UINTN                       *Index,\r
   OUT     CHAR16                      **OutputString\r
   )\r
 {\r
-  UINT16          Count;\r
-  UINT16          Count2;\r
+  UINT16          StrOffset;\r
+  UINT16          GlyphOffset;\r
+  UINT16          OriginalGlyphWidth;\r
+  BOOLEAN         ReturnFlag;\r
+  UINT16          LastSpaceOffset;\r
+  UINT16          LastGlyphWidth;\r
+\r
+  if (InputString == NULL || Index == NULL || OutputString == NULL) {\r
+    return 0;\r
+  }\r
 \r
-  if (GetLineByWidthFinished) {\r
-    GetLineByWidthFinished = FALSE;\r
-    return (UINT16) 0;\r
+  if (LineWidth == 0 || *GlyphWidth == 0) {\r
+    return 0;\r
   }\r
 \r
-  Count         = LineWidth;\r
-  Count2        = 0;\r
+  //\r
+  // Save original glyph width.\r
+  //\r
+  OriginalGlyphWidth = *GlyphWidth;\r
+  LastGlyphWidth     = OriginalGlyphWidth;\r
+  ReturnFlag         = FALSE;\r
+  LastSpaceOffset    = 0;\r
 \r
-  *OutputString = AllocateZeroPool (((UINTN) (LineWidth + 1) * 2));\r
+  //\r
+  // 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
+  // To avoid displaying this  empty line in screen,  just skip  the two CHARs here.\r
+  //\r
+  if ((InputString[*Index] == NARROW_CHAR) && (InputString[*Index + 1] == CHAR_CARRIAGE_RETURN)) {\r
+    *Index = *Index + 2;\r
+  }\r
 \r
   //\r
-  // Ensure we have got a valid buffer\r
+  // Fast-forward the string and see if there is a carriage-return in the string\r
   //\r
-  if (*OutputString != NULL) {\r
+  for (StrOffset = 0, GlyphOffset = 0; GlyphOffset <= LineWidth; StrOffset++) {\r
+    switch (InputString[*Index + StrOffset]) {\r
+      case NARROW_CHAR:\r
+        *GlyphWidth = 1;\r
+        break;\r
 \r
-    //\r
-    //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
-    //To avoid displaying this  empty line in screen,  just skip  the two CHARs here.\r
-    //\r
-   if ((InputString[*Index] == NARROW_CHAR) && (InputString[*Index + 1] == CHAR_CARRIAGE_RETURN)) {\r
-     *Index = *Index + 2;\r
-   }\r
+      case WIDE_CHAR:\r
+        *GlyphWidth = 2;\r
+        break;\r
 \r
-    //\r
-    // Fast-forward the string and see if there is a carriage-return in the string\r
-    //\r
-    for (; (InputString[*Index + Count2] != CHAR_CARRIAGE_RETURN) && (Count2 != LineWidth); Count2++)\r
-      ;\r
+      case CHAR_CARRIAGE_RETURN:\r
+      case CHAR_LINEFEED:\r
+      case CHAR_NULL:\r
+        ReturnFlag = TRUE;\r
+        break;\r
+\r
+      default:\r
+        GlyphOffset = GlyphOffset + *GlyphWidth;\r
+\r
+        //\r
+        // Record the last space info in this line. Will be used in rewind.\r
+        //\r
+        if ((InputString[*Index + StrOffset] == CHAR_SPACE) && (GlyphOffset <= LineWidth)) {\r
+          LastSpaceOffset = StrOffset;\r
+          LastGlyphWidth  = *GlyphWidth;\r
+        }\r
+        break;\r
+    }\r
+\r
+    if (ReturnFlag) {\r
+      break;\r
+    }\r
+  } \r
 \r
+  //\r
+  // Rewind the string from the maximum size until we see a space to break the line\r
+  //\r
+  if (GlyphOffset > LineWidth) {\r
     //\r
-    // Copy the desired LineWidth of data to the output buffer.\r
-    // Also make sure that we don't copy more than the string.\r
-    // Also make sure that if there are linefeeds, we account for them.\r
+    // Rewind the string to last space char in this line.\r
     //\r
-    if ((StrSize (&InputString[*Index]) <= ((UINTN) (LineWidth + 1) * 2)) &&\r
-        (StrSize (&InputString[*Index]) <= ((UINTN) (Count2 + 1) * 2))\r
-        ) {\r
+    if (LastSpaceOffset != 0) {\r
+      StrOffset   = LastSpaceOffset;\r
+      *GlyphWidth = LastGlyphWidth;\r
+    } else {\r
       //\r
-      // Convert to CHAR16 value and show that we are done with this operation\r
+      // Roll back to last char in the line width.\r
       //\r
-      LineWidth = (UINT16) ((StrSize (&InputString[*Index]) - 2) / 2);\r
-      if (LineWidth != 0) {\r
-        GetLineByWidthFinished = TRUE;\r
-      }\r
-    } else {\r
-      if (Count2 == LineWidth) {\r
-        //\r
-        // Rewind the string from the maximum size until we see a space to break the line\r
-        //\r
-        for (; (InputString[*Index + LineWidth] != CHAR_SPACE) && (LineWidth != 0); LineWidth--)\r
-          ;\r
-        if (LineWidth == 0) {\r
-          LineWidth = Count;\r
-        }\r
-      } else {\r
-        LineWidth = Count2;\r
-      }\r
+      StrOffset--;\r
     }\r
+  }\r
+\r
+  //\r
+  // The CHAR_NULL has process last time, this time just return 0 to stand for the end.\r
+  //\r
+  if (StrOffset == 0 && (InputString[*Index + StrOffset] == CHAR_NULL)) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Need extra glyph info and '\0' info, so +2.\r
+  //\r
+  *OutputString = AllocateZeroPool (((UINTN) (StrOffset + 2) * sizeof(CHAR16)));\r
+  if (*OutputString == NULL) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Save the glyph info at the begin of the string, will used by Print function.\r
+  //\r
+  if (OriginalGlyphWidth == 1) {\r
+    *(*OutputString) = NARROW_CHAR;\r
+  } else  {\r
+    *(*OutputString) = WIDE_CHAR;\r
+  }\r
 \r
-    CopyMem (*OutputString, &InputString[*Index], LineWidth * 2);\r
+  CopyMem ((*OutputString) + 1, &InputString[*Index], StrOffset * sizeof(CHAR16));\r
 \r
+  if (InputString[*Index + StrOffset] == CHAR_SPACE) {\r
+    //\r
+    // Skip the space info at the begin of next line.\r
+    //  \r
+    *Index = (UINT16) (*Index + StrOffset + 1);\r
+  } else if ((InputString[*Index + StrOffset] == CHAR_LINEFEED)) {\r
+    //\r
+    // Skip the /n or /n/r info.\r
     //\r
-    // If currently pointing to a space, increment the index to the first non-space character\r
+    if (InputString[*Index + StrOffset + 1] == CHAR_CARRIAGE_RETURN) {\r
+      *Index = (UINT16) (*Index + StrOffset + 2);\r
+    } else {\r
+      *Index = (UINT16) (*Index + StrOffset + 1);\r
+    }\r
+  } else if ((InputString[*Index + StrOffset] == CHAR_CARRIAGE_RETURN)) {\r
     //\r
-    for (;\r
-         (InputString[*Index + LineWidth] == CHAR_SPACE) || (InputString[*Index + LineWidth] == CHAR_CARRIAGE_RETURN);\r
-         (*Index)++\r
-        )\r
-      ;\r
-    *Index = (UINT16) (*Index + LineWidth);\r
-    return LineWidth;\r
+    // Skip the /r or /r/n info.\r
+    //  \r
+    if (InputString[*Index + StrOffset + 1] == CHAR_LINEFEED) {\r
+      *Index = (UINT16) (*Index + StrOffset + 2);\r
+    } else {\r
+      *Index = (UINT16) (*Index + StrOffset + 1);\r
+    }\r
   } else {\r
-    return (UINT16) 0;\r
+    *Index = (UINT16) (*Index + StrOffset);\r
   }\r
+\r
+  //\r
+  // Include extra glyph info and '\0' info, so +2.\r
+  //\r
+  return StrOffset + 2;\r
 }\r
 \r
 \r
@@ -1290,16 +1484,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
@@ -1308,48 +1498,45 @@ UpdateOptionSkipLines (
   UINTN   OriginalRow;\r
   CHAR16  *OutputString;\r
   CHAR16  *OptionString;\r
+  UINT16  GlyphWidth;\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
     Width               = (UINT16) gOptionBlockWidth;\r
 \r
     OriginalRow         = Row;\r
+    GlyphWidth          = 1;\r
 \r
-    for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+    for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
       //\r
       // 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 +1600,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 +1610,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 +1627,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
@@ -1650,85 +1843,394 @@ DevicePathToHiiHandle (
 }\r
 \r
 /**\r
-  Display menu and wait for user to select one menu option, then return it.\r
-  If AutoBoot is enabled, then if user doesn't select any option,\r
-  after period of time, it will automatically return the first menu option.\r
+  Find HII Handle in the HII database associated with given form set guid.\r
 \r
-  @param  Selection              Menu selection.\r
+  If FormSetGuid is NULL, then ASSERT.\r
 \r
-  @retval EFI_SUCESSS            This function always return successfully for now.\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_STATUS\r
-UiDisplayMenu (\r
-  IN OUT UI_MENU_SELECTION           *Selection\r
+EFI_HII_HANDLE\r
+FormSetGuidToHiiHandle (\r
+  EFI_GUID     *ComparingGuid\r
   )\r
 {\r
-  INTN                            SkipValue;\r
-  INTN                            Difference;\r
-  INTN                            OldSkipValue;\r
-  UINTN                           DistanceValue;\r
-  UINTN                           Row;\r
-  UINTN                           Col;\r
-  UINTN                           Temp;\r
-  UINTN                           Temp2;\r
-  UINTN                           TopRow;\r
-  UINTN                           BottomRow;\r
-  UINTN                           OriginalRow;\r
-  UINTN                           Index;\r
-  UINT32                          Count;\r
-  UINT16                          Width;\r
-  CHAR16                          *StringPtr;\r
-  CHAR16                          *OptionString;\r
-  CHAR16                          *OutputString;\r
-  CHAR16                          *FormattedString;\r
-  BOOLEAN                         NewLine;\r
-  BOOLEAN                         Repaint;\r
-  BOOLEAN                         SavedValue;\r
-  BOOLEAN                         UpArrow;\r
-  BOOLEAN                         DownArrow;\r
-  BOOLEAN                         InitializedFlag;\r
-  EFI_STATUS                      Status;\r
-  EFI_INPUT_KEY                   Key;\r
-  LIST_ENTRY                      *Link;\r
-  LIST_ENTRY                      *NewPos;\r
-  LIST_ENTRY                      *TopOfScreen;\r
-  LIST_ENTRY                      *SavedListEntry;\r
-  UI_MENU_OPTION                  *MenuOption;\r
-  UI_MENU_OPTION                  *NextMenuOption;\r
-  UI_MENU_OPTION                  *SavedMenuOption;\r
-  UI_MENU_OPTION                  *PreviousMenuOption;\r
-  UI_CONTROL_FLAG                 ControlFlag;\r
-  EFI_SCREEN_DESCRIPTOR           LocalScreen;\r
-  MENU_REFRESH_ENTRY              *MenuRefreshEntry;\r
-  MENU_REFRESH_ENTRY              *MenuUpdateEntry;  \r
-  UI_SCREEN_OPERATION             ScreenOperation;\r
-  UINT8                           MinRefreshInterval;\r
-  UINTN                           BufferSize;\r
-  UINT16                          DefaultId;\r
-  EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
-  FORM_BROWSER_STATEMENT          *Statement;\r
-  CHAR16                          TemStr[2];\r
-  UINT8                           *DevicePathBuffer;\r
-  UINT8                           DigitUint8;\r
-  UI_MENU_LIST                    *CurrentMenu;\r
-  UI_MENU_LIST                    *MenuList;\r
-  FORM_BROWSER_FORM               *RefForm;\r
-  UINTN                           ModalSkipColumn;\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
-  CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\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
-  Status              = EFI_SUCCESS;\r
-  FormattedString     = NULL;\r
-  OptionString        = NULL;\r
-  ScreenOperation     = UiNoOperation;\r
-  NewLine             = TRUE;\r
-  MinRefreshInterval  = 0;\r
-  DefaultId           = 0;\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
-  OutputString        = NULL;\r
-  UpArrow             = FALSE;\r
-  DownArrow           = FALSE;\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
+  @param Statement    The statement belong to goto op code.\r
+  @param Selection    The selection info.\r
+  @param Repaint      Whether need to repaint the menu.\r
+  @param NewLine      Whether need to create new line.\r
+\r
+  @retval EFI_SUCCESS    The menu process successfully.\r
+  @return Other value if the process failed.\r
+**/\r
+EFI_STATUS\r
+ProcessGotoOpCode (\r
+  IN OUT   FORM_BROWSER_STATEMENT      *Statement,\r
+  IN OUT   UI_MENU_SELECTION           *Selection,\r
+  OUT      BOOLEAN                     *Repaint,\r
+  OUT      BOOLEAN                     *NewLine\r
+  )\r
+{\r
+  CHAR16                          *StringPtr;\r
+  UINTN                           StringLen;\r
+  UINTN                           BufferSize;\r
+  EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
+  CHAR16                          TemStr[2];\r
+  UINT8                           *DevicePathBuffer;\r
+  UINTN                           Index;\r
+  UINT8                           DigitUint8;\r
+  FORM_BROWSER_FORM               *RefForm;\r
+  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
+    //\r
+    // Goto another Hii Package list\r
+    //\r
+    Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
+    BufferSize = StrLen (StringPtr) / 2;\r
+    DevicePath = AllocatePool (BufferSize);\r
+    ASSERT (DevicePath != NULL);\r
+\r
+    //\r
+    // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
+    //\r
+    DevicePathBuffer = (UINT8 *) DevicePath;\r
+    for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {\r
+      TemStr[0] = StringPtr[Index];\r
+      DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
+      if (DigitUint8 == 0 && TemStr[0] != L'0') {\r
+        //\r
+        // Invalid Hex Char as the tail.\r
+        //\r
+        break;\r
+      }\r
+      if ((Index & 1) == 0) {\r
+        DevicePathBuffer [Index/2] = DigitUint8;\r
+      } else {\r
+        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
+      //\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
+    Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId;\r
+  } else if (!CompareGuid (&Statement->HiiValue.Value.ref.FormSetGuid, &gZeroGuid)) {\r
+    if (Selection->Form->ModalForm) {\r
+      return Status;\r
+    }  \r
+    //\r
+    // 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
+    Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId;\r
+  } else if (Statement->HiiValue.Value.ref.FormId != 0) {\r
+    //\r
+    // Check whether target From is suppressed.\r
+    //\r
+    RefForm = IdToForm (Selection->FormSet, Statement->HiiValue.Value.ref.FormId);\r
+\r
+    if ((RefForm != NULL) && (RefForm->SuppressExpression != NULL)) {\r
+      if (EvaluateExpressionList(RefForm->SuppressExpression, TRUE, Selection->FormSet, RefForm) != ExpressFalse) {\r
+        //\r
+        // Form is suppressed. \r
+        //\r
+        do {\r
+          CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);\r
+        } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+        if (Repaint != NULL) {\r
+          *Repaint = TRUE;\r
+        }\r
+        return Status;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Goto another form inside this formset,\r
+    //\r
+    Selection->Action = UI_ACTION_REFRESH_FORM;\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
+    //\r
+    // Goto another Question\r
+    //\r
+    Selection->QuestionId = Statement->HiiValue.Value.ref.QuestionId;\r
+\r
+    if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
+      Selection->Action = UI_ACTION_REFRESH_FORM;\r
+    } else {\r
+      if (Repaint != NULL) {\r
+        *Repaint = TRUE;\r
+      }\r
+      if (NewLine != NULL) {\r
+        *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
+}\r
+\r
+/**\r
+  Display menu and wait for user to select one menu option, then return it.\r
+  If AutoBoot is enabled, then if user doesn't select any option,\r
+  after period of time, it will automatically return the first menu option.\r
+\r
+  @param  Selection              Menu selection.\r
+\r
+  @retval EFI_SUCESSS            This function always return successfully for now.\r
+\r
+**/\r
+EFI_STATUS\r
+UiDisplayMenu (\r
+  IN OUT UI_MENU_SELECTION           *Selection\r
+  )\r
+{\r
+  INTN                            SkipValue;\r
+  INTN                            Difference;\r
+  INTN                            OldSkipValue;\r
+  UINTN                           DistanceValue;\r
+  UINTN                           Row;\r
+  UINTN                           Col;\r
+  UINTN                           Temp;\r
+  UINTN                           Temp2;\r
+  UINTN                           TopRow;\r
+  UINTN                           BottomRow;\r
+  UINTN                           OriginalRow;\r
+  UINTN                           Index;\r
+  UINT16                          Width;\r
+  CHAR16                          *StringPtr;\r
+  CHAR16                          *OptionString;\r
+  CHAR16                          *OutputString;\r
+  CHAR16                          *HelpString;\r
+  CHAR16                          *HelpHeaderString;\r
+  CHAR16                          *HelpBottomString;\r
+  BOOLEAN                         NewLine;\r
+  BOOLEAN                         Repaint;\r
+  BOOLEAN                         SavedValue;\r
+  BOOLEAN                         UpArrow;\r
+  BOOLEAN                         DownArrow;\r
+  BOOLEAN                         InitializedFlag;\r
+  EFI_STATUS                      Status;\r
+  EFI_INPUT_KEY                   Key;\r
+  LIST_ENTRY                      *Link;\r
+  LIST_ENTRY                      *NewPos;\r
+  LIST_ENTRY                      *TopOfScreen;\r
+  LIST_ENTRY                      *SavedListEntry;\r
+  UI_MENU_OPTION                  *MenuOption;\r
+  UI_MENU_OPTION                  *NextMenuOption;\r
+  UI_MENU_OPTION                  *SavedMenuOption;\r
+  UI_MENU_OPTION                  *PreviousMenuOption;\r
+  UI_CONTROL_FLAG                 ControlFlag;\r
+  EFI_SCREEN_DESCRIPTOR           LocalScreen;\r
+  MENU_REFRESH_ENTRY              *MenuRefreshEntry;\r
+  MENU_REFRESH_ENTRY              *MenuUpdateEntry;  \r
+  UI_SCREEN_OPERATION             ScreenOperation;\r
+  UINT8                           MinRefreshInterval;\r
+  UINT16                          DefaultId;\r
+  FORM_BROWSER_STATEMENT          *Statement;\r
+  UI_MENU_LIST                    *CurrentMenu;\r
+  UINTN                           ModalSkipColumn;\r
+  BROWSER_HOT_KEY                 *HotKey;\r
+  UINTN                           HelpPageIndex;\r
+  UINTN                           HelpPageCount;\r
+  UINTN                           RowCount;\r
+  UINTN                           HelpLine;\r
+  UINTN                           HelpHeaderLine;\r
+  UINTN                           HelpBottomLine;\r
+  BOOLEAN                         MultiHelpPage;\r
+  UINT16                          GlyphWidth;\r
+  UINT16                          EachLineWidth;\r
+  UINT16                          HeaderLineWidth;\r
+  UINT16                          BottomLineWidth;\r
+\r
+  CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
+\r
+  Status              = EFI_SUCCESS;\r
+  HelpString          = NULL;\r
+  HelpHeaderString    = NULL;\r
+  HelpBottomString    = NULL;\r
+  OptionString        = NULL;\r
+  ScreenOperation     = UiNoOperation;\r
+  NewLine             = TRUE;\r
+  MinRefreshInterval  = 0;\r
+  DefaultId           = 0;\r
+  HelpPageCount       = 0;\r
+  HelpLine            = 0;\r
+  RowCount            = 0;\r
+  HelpBottomLine      = 0;\r
+  HelpHeaderLine      = 0;\r
+  HelpPageIndex       = 0;\r
+  MultiHelpPage       = FALSE;\r
+  EachLineWidth       = 0;\r
+  HeaderLineWidth     = 0;\r
+  BottomLineWidth     = 0;\r
+  OutputString        = NULL;\r
+  UpArrow             = FALSE;\r
+  DownArrow           = FALSE;\r
   SkipValue           = 0;\r
   OldSkipValue        = 0;\r
   MenuRefreshEntry    = gMenuRefreshHead;\r
@@ -1736,7 +2238,7 @@ UiDisplayMenu (
   NextMenuOption      = NULL;\r
   PreviousMenuOption  = NULL;\r
   SavedMenuOption     = NULL;\r
-  RefForm             = NULL;\r
+  HotKey              = NULL;\r
   ModalSkipColumn     = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 6;\r
 \r
   ZeroMem (&Key, sizeof (EFI_INPUT_KEY));\r
@@ -1755,7 +2257,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
@@ -1775,7 +2277,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
@@ -1785,6 +2287,7 @@ UiDisplayMenu (
     // Highlight not specified, fetch it from cached menu\r
     //\r
     Selection->QuestionId = CurrentMenu->QuestionId;\r
+    Selection->Sequence   = CurrentMenu->Sequence;\r
   }\r
 \r
   //\r
@@ -1875,6 +2378,7 @@ UiDisplayMenu (
 \r
           Width       = GetWidth (Statement, MenuOption->Handle);\r
           OriginalRow = Row;\r
+          GlyphWidth  = 1;\r
 \r
           if (Statement->Operand == EFI_IFR_REF_OP && MenuOption->Col >= 2) {\r
             //\r
@@ -1888,7 +2392,7 @@ UiDisplayMenu (
               );\r
           }\r
 \r
-          for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
+          for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
             if ((Temp == 0) && (Row <= BottomRow)) {\r
               PrintStringAt (MenuOption->Col, Row, OutputString);\r
             }\r
@@ -1923,25 +2427,14 @@ 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
             OriginalRow = Row;\r
+            GlyphWidth  = 1;\r
 \r
-            for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+            for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
               if ((Temp2 == 0) && (Row <= BottomRow)) {\r
                 PrintStringAt (MenuOption->OptCol, Row, OutputString);\r
               }\r
@@ -2048,8 +2541,9 @@ UiDisplayMenu (
 \r
             Width       = (UINT16) gOptionBlockWidth;\r
             OriginalRow = Row;\r
+            GlyphWidth = 1;\r
 \r
-            for (Index = 0; GetLineByWidth (StringPtr, Width, &Index, &OutputString) != 0x0000;) {\r
+            for (Index = 0; GetLineByWidth (StringPtr, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
               if ((Temp == 0) && (Row <= BottomRow)) {\r
                 PrintStringAt (MenuOption->OptCol, Row, OutputString);\r
               }\r
@@ -2142,7 +2636,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
@@ -2156,7 +2650,9 @@ UiDisplayMenu (
         NewPos = gMenuOption.ForwardLink;\r
         SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
 \r
-        while (SavedMenuOption->ThisTag->QuestionId != Selection->QuestionId && NewPos->ForwardLink != &gMenuOption) {\r
+        while ((SavedMenuOption->ThisTag->QuestionId != Selection->QuestionId ||\r
+                SavedMenuOption->Sequence != Selection->Sequence) &&\r
+                NewPos->ForwardLink != &gMenuOption) {\r
           NewPos     = NewPos->ForwardLink;\r
           SavedMenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
         }\r
@@ -2169,20 +2665,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
@@ -2211,24 +2766,14 @@ 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
             OriginalRow         = MenuOption->Row;\r
+            GlyphWidth          = 1;\r
 \r
-            for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+            for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
               if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
                 PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);\r
               }\r
@@ -2255,8 +2800,9 @@ UiDisplayMenu (
 \r
               OriginalRow = MenuOption->Row;\r
               Width       = GetWidth (MenuOption->ThisTag, MenuOption->Handle);\r
+              GlyphWidth  = 1;\r
 \r
-              for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
+              for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
                 if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
                   PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);\r
                 }\r
@@ -2292,6 +2838,7 @@ UiDisplayMenu (
         // Record highlight for current menu\r
         //\r
         CurrentMenu->QuestionId = Statement->QuestionId;\r
+        CurrentMenu->Sequence   = MenuOption->Sequence;\r
 \r
         //\r
         // Set reverse attribute\r
@@ -2320,24 +2867,14 @@ 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
           OriginalRow         = MenuOption->Row;\r
+          GlyphWidth          = 1;\r
 \r
-          for (Index = 0; GetLineByWidth (OptionString, Width, &Index, &OutputString) != 0x0000;) {\r
+          for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
             if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
               PrintStringAt (MenuOption->OptCol, MenuOption->Row, OutputString);\r
             }\r
@@ -2359,8 +2896,9 @@ UiDisplayMenu (
             OriginalRow = MenuOption->Row;\r
 \r
             Width       = GetWidth (Statement, MenuOption->Handle);\r
+            GlyphWidth          = 1;\r
 \r
-            for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &Index, &OutputString) != 0x0000;) {\r
+            for (Index = 0; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
               if (MenuOption->Row >= TopRow && MenuOption->Row <= BottomRow) {\r
                 PrintStringAt (MenuOption->Col, MenuOption->Row, OutputString);\r
               }\r
@@ -2410,22 +2948,125 @@ UiDisplayMenu (
           StringPtr = GetToken (MenuOption->ThisTag->Help, MenuOption->Handle);\r
         }\r
 \r
-        ProcessHelpString (StringPtr, &FormattedString, BottomRow - TopRow);\r
-\r
-        gST->ConOut->SetAttribute (gST->ConOut, HELP_TEXT | FIELD_BACKGROUND);\r
-\r
-        for (Index = 0; Index < BottomRow - TopRow; Index++) {\r
+        RowCount      = BottomRow - TopRow;\r
+        HelpPageIndex = 0;\r
+        //\r
+        // 1.Calculate how many line the help string need to print.\r
+        //\r
+        if (HelpString != NULL) {\r
+          FreePool (HelpString);\r
+        }\r
+        HelpLine = ProcessHelpString (StringPtr, &HelpString, &EachLineWidth, RowCount);\r
+        if (HelpLine > RowCount) {\r
+          MultiHelpPage   = TRUE;\r
+          StringPtr       = GetToken (STRING_TOKEN(ADJUST_HELP_PAGE_UP), gHiiHandle);\r
+          if (HelpHeaderString != NULL) {\r
+            FreePool (HelpHeaderString);\r
+          }\r
+          HelpHeaderLine  = ProcessHelpString (StringPtr, &HelpHeaderString, &HeaderLineWidth, RowCount);\r
+          StringPtr       = GetToken (STRING_TOKEN(ADJUST_HELP_PAGE_DOWN), gHiiHandle);\r
+          if (HelpBottomString != NULL) {\r
+            FreePool (HelpBottomString);\r
+          }\r
+          HelpBottomLine  = ProcessHelpString (StringPtr, &HelpBottomString, &BottomLineWidth, RowCount);\r
           //\r
-          // Pad String with spaces to simulate a clearing of the previous line\r
+          // Calculate the help page count.\r
           //\r
-          for (; GetStringWidth (&FormattedString[Index * gHelpBlockWidth * 2]) / 2 < gHelpBlockWidth;) {\r
-            StrCat (&FormattedString[Index * gHelpBlockWidth * 2], L" ");\r
+          if (HelpLine > 2 * RowCount - 2) {\r
+            HelpPageCount = (HelpLine - RowCount + 1) / (RowCount - 2) + 1;\r
+            if ((HelpLine - RowCount + 1) % (RowCount - 2) > 1) {\r
+              HelpPageCount += 1;\r
+            }\r
+          } else {\r
+            HelpPageCount = 2;\r
           }\r
+        } else {\r
+          MultiHelpPage = FALSE;\r
+        }\r
+      }\r
+\r
+      //\r
+      // Clean the help field first.\r
+      //\r
+      ClearLines (\r
+        LocalScreen.RightColumn - gHelpBlockWidth,\r
+        LocalScreen.RightColumn,\r
+        TopRow,\r
+        BottomRow,\r
+        PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND\r
+        );\r
 \r
+      //\r
+      // Check whether need to show the 'More(U/u)' at the begin.\r
+      // Base on current direct info, here shows aligned to the right side of the column.\r
+      // If the direction is multi line and aligned to right side may have problem, so \r
+      // add ASSERT code here.\r
+      //\r
+      if (HelpPageIndex > 0) {\r
+        gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT | FIELD_BACKGROUND);\r
+        for (Index = 0; Index < HelpHeaderLine; Index++) {\r
+          ASSERT (HelpHeaderLine == 1);\r
+          ASSERT (GetStringWidth (HelpHeaderString) / 2 < (UINTN) (gHelpBlockWidth - 1));\r
+          PrintStringAt (\r
+            LocalScreen.RightColumn - GetStringWidth (HelpHeaderString) / 2 - 1,\r
+            Index + TopRow,\r
+            &HelpHeaderString[Index * HeaderLineWidth]\r
+            );\r
+        }\r
+      }\r
+\r
+      gST->ConOut->SetAttribute (gST->ConOut, HELP_TEXT | FIELD_BACKGROUND);\r
+      //\r
+      // Print the help string info.\r
+      //\r
+      if (!MultiHelpPage) {\r
+        for (Index = 0; Index < HelpLine; Index++) {\r
           PrintStringAt (\r
             LocalScreen.RightColumn - gHelpBlockWidth,\r
             Index + TopRow,\r
-            &FormattedString[Index * gHelpBlockWidth * 2]\r
+            &HelpString[Index * EachLineWidth]\r
+            );\r
+        }\r
+        gST->ConOut->SetCursorPosition(gST->ConOut, LocalScreen.RightColumn-1, BottomRow);\r
+      } else  {\r
+        if (HelpPageIndex == 0) {\r
+          for (Index = 0; Index < RowCount - HelpBottomLine; Index++) {\r
+            PrintStringAt (\r
+              LocalScreen.RightColumn - gHelpBlockWidth,\r
+              Index + TopRow,\r
+              &HelpString[Index * EachLineWidth]\r
+              );\r
+          }\r
+        } else {\r
+          for (Index = 0; (Index < RowCount - HelpBottomLine - HelpHeaderLine) && \r
+              (Index + HelpPageIndex * (RowCount - 2) + 1 < HelpLine); Index++) {\r
+            PrintStringAt (\r
+              LocalScreen.RightColumn - gHelpBlockWidth,\r
+              Index + TopRow + HelpHeaderLine,\r
+              &HelpString[(Index + HelpPageIndex * (RowCount - 2) + 1)* EachLineWidth]\r
+              );\r
+          }\r
+          if (HelpPageIndex == HelpPageCount - 1) {\r
+            gST->ConOut->SetCursorPosition(gST->ConOut, LocalScreen.RightColumn-1, BottomRow);\r
+          }\r
+        } \r
+      }\r
+\r
+      //\r
+      // Check whether need to print the 'More(D/d)' at the bottom.\r
+      // Base on current direct info, here shows aligned to the right side of the column.\r
+      // If the direction is multi line and aligned to right side may have problem, so \r
+      // add ASSERT code here.\r
+      //\r
+      if (HelpPageIndex < HelpPageCount - 1 && MultiHelpPage) {\r
+        gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT | FIELD_BACKGROUND);\r
+        for (Index = 0; Index < HelpBottomLine; Index++) {\r
+          ASSERT (HelpBottomLine == 1);\r
+          ASSERT (GetStringWidth (HelpBottomString) / 2 < (UINTN) (gHelpBlockWidth - 1)); \r
+          PrintStringAt (\r
+            LocalScreen.RightColumn - GetStringWidth (HelpBottomString) / 2 - 1,\r
+            Index + BottomRow - HelpBottomLine,\r
+            &HelpBottomString[Index * BottomLineWidth]\r
             );\r
         }\r
       }\r
@@ -2455,8 +3096,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
@@ -2470,6 +3112,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
@@ -2484,7 +3131,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
@@ -2537,37 +3184,55 @@ 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 'D':\r
+      case 'd':\r
+        if (!MultiHelpPage) {\r
+          ControlFlag = CfReadKey;\r
+          break;\r
+        }\r
+        ControlFlag    = CfUpdateHelpString;\r
+        HelpPageIndex  = HelpPageIndex < HelpPageCount - 1 ? HelpPageIndex + 1 : HelpPageCount - 1;\r
+        break;\r
+\r
+      case 'U':\r
+      case 'u':\r
+        if (!MultiHelpPage) {\r
+          ControlFlag = CfReadKey;\r
+          break;\r
+        }\r
+        ControlFlag    = CfUpdateHelpString;\r
+        HelpPageIndex  = HelpPageIndex > 0 ? HelpPageIndex - 1 : 0;\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
@@ -2613,130 +3278,7 @@ UiDisplayMenu (
 \r
       switch (Statement->Operand) {\r
       case EFI_IFR_REF_OP:\r
-        if (Statement->RefDevicePath != 0) {\r
-          if (Selection->Form->ModalForm) {\r
-            break;\r
-          }\r
-          //\r
-          // Goto another Hii Package list\r
-          //\r
-          Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
-\r
-          StringPtr = GetToken (Statement->RefDevicePath, 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
-            break;\r
-          }\r
-          BufferSize = StrLen (StringPtr) / 2;\r
-          DevicePath = AllocatePool (BufferSize);\r
-          ASSERT (DevicePath != NULL);\r
-\r
-          //\r
-          // Convert from Device Path String to DevicePath Buffer in the reverse order.\r
-          //\r
-          DevicePathBuffer = (UINT8 *) DevicePath;\r
-          for (Index = 0; StringPtr[Index] != L'\0'; Index ++) {\r
-            TemStr[0] = StringPtr[Index];\r
-            DigitUint8 = (UINT8) StrHexToUint64 (TemStr);\r
-            if (DigitUint8 == 0 && TemStr[0] != L'0') {\r
-              //\r
-              // Invalid Hex Char as the tail.\r
-              //\r
-              break;\r
-            }\r
-            if ((Index & 1) == 0) {\r
-              DevicePathBuffer [Index/2] = DigitUint8;\r
-            } else {\r
-              DevicePathBuffer [Index/2] = (UINT8) ((DevicePathBuffer [Index/2] << 4) + DigitUint8);\r
-            }\r
-          }\r
-\r
-          Selection->Handle = DevicePathToHiiHandle (DevicePath);\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
-            break;\r
-          }\r
-\r
-          FreePool (StringPtr);\r
-          FreePool (DevicePath);\r
-\r
-          CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));\r
-          Selection->FormId = Statement->RefFormId;\r
-          Selection->QuestionId = Statement->RefQuestionId;\r
-        } else if (!CompareGuid (&Statement->RefFormSetId, &gZeroGuid)) {\r
-          if (Selection->Form->ModalForm) {\r
-            break;\r
-          }\r
-          //\r
-          // Goto another Formset, check for uncommitted data\r
-          //\r
-          Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
-\r
-          CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));\r
-          Selection->FormId = Statement->RefFormId;\r
-          Selection->QuestionId = Statement->RefQuestionId;\r
-        } else if (Statement->RefFormId != 0) {\r
-          //\r
-          // Check whether target From is suppressed.\r
-          //\r
-          RefForm = IdToForm (Selection->FormSet, Statement->RefFormId);\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
-              //\r
-              // Form is suppressed. \r
-              //\r
-              do {\r
-                CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gFormSuppress, gPressEnter, gEmptyString);\r
-              } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
-\r
-              Repaint = TRUE;\r
-              break;\r
-            }\r
-          }\r
-\r
-          //\r
-          // Goto another form inside this formset,\r
-          //\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->RefFormId);\r
-          if (MenuList == NULL) {\r
-            MenuList = UiAddMenuList (CurrentMenu, &Selection->FormSetGuid, Statement->RefFormId);\r
-          }\r
-\r
-          Selection->FormId = Statement->RefFormId;\r
-          Selection->QuestionId = Statement->RefQuestionId;\r
-        } else if (Statement->RefQuestionId != 0) {\r
-          //\r
-          // Goto another Question\r
-          //\r
-          Selection->QuestionId = Statement->RefQuestionId;\r
-\r
-          if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
-            Selection->Action = UI_ACTION_REFRESH_FORM;\r
-          } else {\r
-            Repaint = TRUE;\r
-            NewLine = TRUE;\r
-            break;\r
-          }\r
-        }\r
+        ProcessGotoOpCode(Statement, Selection, &Repaint, &NewLine);\r
         break;\r
 \r
       case EFI_IFR_ACTION_OP:\r
@@ -2790,9 +3332,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
@@ -2835,18 +3375,21 @@ UiDisplayMenu (
       AdjustDateAndTimePosition (TRUE, &NewPos);\r
       if (NewPos->BackLink != &gMenuOption) {\r
         MenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
+        ASSERT (MenuOption != NULL);\r
         NewLine    = TRUE;\r
         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
-        ASSERT (MenuOption != NULL);\r
         if (Difference < 0) {\r
           //\r
           // We hit the begining MenuOption that can be focused\r
@@ -2918,6 +3461,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
@@ -2929,19 +3475,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
@@ -2956,10 +3502,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
@@ -3003,7 +3549,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
@@ -3019,7 +3565,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
@@ -3051,7 +3597,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
@@ -3068,7 +3614,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
@@ -3083,7 +3629,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
@@ -3200,7 +3746,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
@@ -3210,43 +3756,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
@@ -3262,6 +3885,15 @@ UiDisplayMenu (
       gST->ConOut->SetCursorPosition (gST->ConOut, 0, Row + 4);\r
       gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
       gST->ConOut->OutputString (gST->ConOut, L"\n");\r
+      if (HelpString != NULL) {\r
+        FreePool (HelpString);\r
+      }\r
+      if (HelpHeaderString != NULL) {\r
+        FreePool (HelpHeaderString);\r
+      }\r
+      if (HelpBottomString != NULL) {\r
+        FreePool (HelpBottomString);\r
+      }\r
 \r
       return EFI_SUCCESS;\r
 \r