]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DisplayEngineDxe/FormDisplay.c
MdeModulePkg/DisplayEngineDxe: Fix small InitializeDisplayEngine leak
[mirror_edk2.git] / MdeModulePkg / Universal / DisplayEngineDxe / FormDisplay.c
index e1ac5a32233f93ea530004b1f9d3eb424da15817..7390f954b67f1ec13d41b3dea404964096356563 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Entry and initialization module for the browser.\r
 \r
-Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
 Copyright (c) 2014, Hewlett-Packard Development Company, L.P.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
@@ -87,7 +87,7 @@ SCREEN_OPERATION_T0_CONTROL_FLAG  gScreenOperationToControlFlag[] = {
   {\r
     UiPageDown,\r
     CfUiPageDown\r
-  }, \r
+  },\r
   {\r
     UiHotKey,\r
     CfUiHotKey\r
@@ -151,6 +151,15 @@ CHAR16            *gConfirmExitMsg2nd;
 CHAR16            *gConfirmOpt;\r
 CHAR16            *gConfirmOptYes;\r
 CHAR16            *gConfirmOptNo;\r
+CHAR16            *gConfirmOptOk;\r
+CHAR16            *gConfirmOptCancel;\r
+CHAR16            *gYesOption;\r
+CHAR16            *gNoOption;\r
+CHAR16            *gOkOption;\r
+CHAR16            *gCancelOption;\r
+CHAR16            *gErrorPopup;\r
+CHAR16            *gWarningPopup;\r
+CHAR16            *gInfoPopup;\r
 CHAR16            *gConfirmMsgConnect;\r
 CHAR16            *gConfirmMsgEnd;\r
 CHAR16            *gPasswordUnsupported;\r
@@ -167,6 +176,10 @@ FORM_DISPLAY_DRIVER_PRIVATE_DATA  mPrivateData = {
     FormDisplay,\r
     DriverClearDisplayPage,\r
     ConfirmDataChange\r
+  },\r
+  {\r
+    EFI_HII_POPUP_PROTOCOL_REVISION,\r
+    CreatePopup\r
   }\r
 };\r
 \r
@@ -247,6 +260,15 @@ InitializeDisplayStrings (
   gConfirmOpt           = GetToken (STRING_TOKEN (CONFIRM_OPTION), gHiiHandle);\r
   gConfirmOptYes        = GetToken (STRING_TOKEN (CONFIRM_OPTION_YES), gHiiHandle);\r
   gConfirmOptNo         = GetToken (STRING_TOKEN (CONFIRM_OPTION_NO), gHiiHandle);\r
+  gConfirmOptOk         = GetToken (STRING_TOKEN (CONFIRM_OPTION_OK), gHiiHandle);\r
+  gConfirmOptCancel     = GetToken (STRING_TOKEN (CONFIRM_OPTION_CANCEL), gHiiHandle);\r
+  gYesOption            = GetToken (STRING_TOKEN (YES_SELECTABLE_OPTION), gHiiHandle);\r
+  gNoOption             = GetToken (STRING_TOKEN (NO_SELECTABLE_OPTION), gHiiHandle);\r
+  gOkOption             = GetToken (STRING_TOKEN (OK_SELECTABLE_OPTION), gHiiHandle);\r
+  gCancelOption         = GetToken (STRING_TOKEN (CANCEL_SELECTABLE_OPTION), gHiiHandle);\r
+  gErrorPopup           = GetToken (STRING_TOKEN (ERROR_POPUP_STRING), gHiiHandle);\r
+  gWarningPopup         = GetToken (STRING_TOKEN (WARNING_POPUP_STRING), gHiiHandle);\r
+  gInfoPopup            = GetToken (STRING_TOKEN (INFO_POPUP_STRING), gHiiHandle);\r
   gConfirmMsgConnect    = GetToken (STRING_TOKEN (CONFIRM_OPTION_CONNECT), gHiiHandle);\r
   gConfirmMsgEnd        = GetToken (STRING_TOKEN (CONFIRM_OPTION_END), gHiiHandle);\r
   gPasswordUnsupported  = GetToken (STRING_TOKEN (PASSWORD_NOT_SUPPORTED ), gHiiHandle);\r
@@ -301,6 +323,15 @@ FreeDisplayStrings (
   FreePool (gConfirmOpt);\r
   FreePool (gConfirmOptYes);\r
   FreePool (gConfirmOptNo);\r
+  FreePool (gConfirmOptOk);\r
+  FreePool (gConfirmOptCancel);\r
+  FreePool (gYesOption);\r
+  FreePool (gNoOption);\r
+  FreePool (gOkOption);\r
+  FreePool (gCancelOption);\r
+  FreePool (gErrorPopup);\r
+  FreePool (gWarningPopup);\r
+  FreePool (gInfoPopup);\r
   FreePool (gConfirmMsgConnect);\r
   FreePool (gConfirmMsgEnd);\r
   FreePool (gPasswordUnsupported);\r
@@ -387,10 +418,10 @@ GetWidth (
       //\r
       ((Statement->OpCode->OpCode == EFI_IFR_TEXT_OP) && (Size == 0))\r
       ) {\r
-    \r
+\r
     //\r
     // Return the space width.\r
-    // \r
+    //\r
     if (AdjustWidth != NULL) {\r
       *AdjustWidth = 2;\r
     }\r
@@ -431,7 +462,7 @@ GetWidth (
   @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 \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
@@ -510,7 +541,7 @@ GetLineByWidth (
     if (ReturnFlag) {\r
       break;\r
     }\r
-  } \r
+  }\r
 \r
   //\r
   // Rewind the string from the maximum size until we see a space to break the line\r
@@ -559,7 +590,7 @@ GetLineByWidth (
   if (InputString[*Index + StrOffset] == CHAR_SPACE) {\r
     //\r
     // Skip the space info at the begin of next line.\r
-    //  \r
+    //\r
     *Index = (UINT16) (*Index + StrOffset + 1);\r
   } else if (InputString[*Index + StrOffset] == CHAR_LINEFEED) {\r
     //\r
@@ -573,7 +604,7 @@ GetLineByWidth (
   } else if (InputString[*Index + StrOffset] == CHAR_CARRIAGE_RETURN) {\r
     //\r
     // Skip the /r or /r/n info.\r
-    //  \r
+    //\r
     if (InputString[*Index + StrOffset + 1] == CHAR_LINEFEED) {\r
       *Index = (UINT16) (*Index + StrOffset + 2);\r
     } else {\r
@@ -674,7 +705,7 @@ UiAddMenuOption (
     case EFI_IFR_TEXT_OP:\r
       if (FeaturePcdGet (PcdBrowserGrayOutTextStatement)) {\r
         //\r
-        // Initializing GrayOut option as TRUE for Text setup options \r
+        // Initializing GrayOut option as TRUE for Text setup options\r
         // so that those options will be Gray in colour and un selectable.\r
         //\r
         MenuOption->GrayOut = TRUE;\r
@@ -692,8 +723,8 @@ UiAddMenuOption (
       }\r
     }\r
 \r
-    if (Index == 0 && \r
-      (Statement->OpCode->OpCode != EFI_IFR_DATE_OP) && \r
+    if (Index == 0 &&\r
+      (Statement->OpCode->OpCode != EFI_IFR_DATE_OP) &&\r
       (Statement->OpCode->OpCode != EFI_IFR_TIME_OP)) {\r
       Width  = GetWidth (MenuOption, NULL);\r
       for (; GetLineByWidth (MenuOption->Description, Width, &GlyphWidth,&ArrayEntry, &OutputString) != 0x0000;) {\r
@@ -710,7 +741,7 @@ UiAddMenuOption (
       // Add three MenuOptions for Date/Time\r
       // Data format :      [01/02/2004]      [11:22:33]\r
       // Line number :        0  0    1         0  0  1\r
-      //    \r
+      //\r
       NumberOfLines = 0;\r
     }\r
 \r
@@ -877,7 +908,7 @@ UpdateSkipInfoForMenu (
   CHAR16  *OutputString;\r
   UINT16  GlyphWidth;\r
 \r
-  Width         = (UINT16) gOptionBlockWidth;\r
+  Width         = (UINT16) gOptionBlockWidth - 1;\r
   GlyphWidth    = 1;\r
   Row           = 1;\r
 \r
@@ -889,8 +920,8 @@ UpdateSkipInfoForMenu (
     FreePool (OutputString);\r
   }\r
 \r
-  if ((Row > MenuOption->Skip) && \r
-      (MenuOption->ThisTag->OpCode->OpCode != EFI_IFR_DATE_OP) && \r
+  if ((Row > MenuOption->Skip) &&\r
+      (MenuOption->ThisTag->OpCode->OpCode != EFI_IFR_DATE_OP) &&\r
       (MenuOption->ThisTag->OpCode->OpCode != EFI_IFR_TIME_OP)) {\r
     MenuOption->Skip = Row;\r
   }\r
@@ -1014,8 +1045,8 @@ IsSelectable (
   @return The row distance from current MenuOption to next selectable MenuOption.\r
 \r
   @retval -1       Reach the begin of the menu, still can't find the selectable menu.\r
-  @retval Value    Find the selectable menu, maybe the truly selectable, maybe the \r
-                   first menu showing beyond current form or last menu showing in \r
+  @retval Value    Find the selectable menu, maybe the truly selectable, maybe the\r
+                   first menu showing beyond current form or last menu showing in\r
                    current form.\r
                    The value is the line number between the new selected menu and the\r
                    current select menu, not include the new selected menu.\r
@@ -1095,10 +1126,10 @@ MoveToNextStatement (
 \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
+  @param  AddOptCol               Whether need to update MenuOption->OptCol.\r
 \r
 **/\r
-VOID \r
+VOID\r
 ProcessStringForDateTime (\r
   UI_MENU_OPTION                  *MenuOption,\r
   CHAR16                          *OptionString,\r
@@ -1112,7 +1143,7 @@ ProcessStringForDateTime (
   EFI_IFR_TIME                           *Time;\r
 \r
   ASSERT (MenuOption != NULL && OptionString != NULL);\r
-  \r
+\r
   Statement = MenuOption->ThisTag;\r
   Date      = NULL;\r
   Time      = NULL;\r
@@ -1121,7 +1152,7 @@ ProcessStringForDateTime (
   } else if (Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {\r
     Time = (EFI_IFR_TIME *) Statement->OpCode;\r
   }\r
-  \r
+\r
   //\r
   // If leading spaces on OptionString - remove the spaces\r
   //\r
@@ -1133,13 +1164,13 @@ ProcessStringForDateTime (
       MenuOption->OptCol++;\r
     }\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
   //\r
   // Enable to suppress field in the opcode base on the flag.\r
   //\r
@@ -1151,21 +1182,21 @@ ProcessStringForDateTime (
     //\r
     if ((Date->Flags & EFI_QF_DATE_MONTH_SUPPRESS) && (MenuOption->Sequence == 0)) {\r
       //\r
-      // At this point, only "<**:" in the optionstring. \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 ((Date->Flags & EFI_QF_DATE_DAY_SUPPRESS) && (MenuOption->Sequence == 1)) {\r
       //\r
-      // At this point, only "**:" in the optionstring. \r
+      // At this point, only "**:" in the optionstring.\r
       // Clean the month's "**" field, after clean, the format is "  :"\r
-      //                \r
+      //\r
       SetUnicodeMem (&OptionString[0], 2, L' ');\r
     } else if ((Date->Flags & EFI_QF_DATE_YEAR_SUPPRESS) && (MenuOption->Sequence == 2)) {\r
       //\r
-      // At this point, only "****>" in the optionstring. \r
+      // At this point, only "****>" in the optionstring.\r
       // Clean the year's "****" field, after clean, the format is "  >"\r
-      //                \r
+      //\r
       SetUnicodeMem (&OptionString[0], 4, L' ');\r
     }\r
   } else if (Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {\r
@@ -1176,21 +1207,21 @@ ProcessStringForDateTime (
     //\r
     if ((Time->Flags & QF_TIME_HOUR_SUPPRESS) && (MenuOption->Sequence == 0)) {\r
       //\r
-      // At this point, only "<**:" in the optionstring. \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 ((Time->Flags & QF_TIME_MINUTE_SUPPRESS) && (MenuOption->Sequence == 1)) {\r
       //\r
-      // At this point, only "**:" in the optionstring. \r
+      // At this point, only "**:" in the optionstring.\r
       // Clean the minute's "**" field, after clean, the format is "  :"\r
-      //                \r
+      //\r
       SetUnicodeMem (&OptionString[0], 2, L' ');\r
     } else if ((Time->Flags & QF_TIME_SECOND_SUPPRESS) && (MenuOption->Sequence == 2)) {\r
       //\r
-      // At this point, only "**>" in the optionstring. \r
+      // At this point, only "**>" in the optionstring.\r
       // Clean the second's "**" field, after clean, the format is "  >"\r
-      //                \r
+      //\r
       SetUnicodeMem (&OptionString[0], 2, L' ');\r
     }\r
   }\r
@@ -1273,7 +1304,7 @@ AdjustDateAndTimePosition (
 \r
 /**\r
   Get step info from numeric opcode.\r
-  \r
+\r
   @param[in] OpCode     The input numeric op code.\r
 \r
   @return step info for this opcode.\r
@@ -1287,24 +1318,24 @@ GetFieldFromNum (
   UINT64                Step;\r
 \r
   NumericOp = (EFI_IFR_NUMERIC *) OpCode;\r
-  \r
+\r
   switch (NumericOp->Flags & EFI_IFR_NUMERIC_SIZE) {\r
   case EFI_IFR_NUMERIC_SIZE_1:\r
     Step    = NumericOp->data.u8.Step;\r
     break;\r
-  \r
+\r
   case EFI_IFR_NUMERIC_SIZE_2:\r
     Step    = NumericOp->data.u16.Step;\r
     break;\r
-  \r
+\r
   case EFI_IFR_NUMERIC_SIZE_4:\r
     Step    = NumericOp->data.u32.Step;\r
     break;\r
-  \r
+\r
   case EFI_IFR_NUMERIC_SIZE_8:\r
     Step    = NumericOp->data.u64.Step;\r
     break;\r
-  \r
+\r
   default:\r
     Step = 0;\r
     break;\r
@@ -1315,7 +1346,7 @@ GetFieldFromNum (
 \r
 /**\r
   Find the registered HotKey based on KeyData.\r
-  \r
+\r
   @param[in] KeyData     A pointer to a buffer that describes the keystroke\r
                          information for the hot key.\r
 \r
@@ -1332,14 +1363,14 @@ GetHotKeyFromRegisterList (
   Link = GetFirstNode (&gFormData->HotKeyListHead);\r
   while (!IsNull (&gFormData->HotKeyListHead, Link)) {\r
     HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);\r
-    \r
+\r
     if (HotKey->KeyData->ScanCode == KeyData->ScanCode) {\r
       return HotKey;\r
     }\r
 \r
     Link = GetNextNode (&gFormData->HotKeyListHead, Link);\r
   }\r
-  \r
+\r
   return NULL;\r
 }\r
 \r
@@ -1409,13 +1440,13 @@ UiWaitForEvent (
           Timeout\r
           );\r
   }\r
-  \r
+\r
   WaitList[0] = Event;\r
   EventNum    = 1;\r
   if (gFormData->FormRefreshEvent != NULL) {\r
     WaitList[EventNum] = gFormData->FormRefreshEvent;\r
     EventNum ++;\r
-  } \r
+  }\r
 \r
   if (Timeout != 0) {\r
     WaitList[EventNum] = TimerEvent;\r
@@ -1448,7 +1479,7 @@ UiWaitForEvent (
   if (Timeout != 0) {\r
     gBS->CloseEvent (TimerEvent);\r
   }\r
-  \r
+\r
   return EventType;\r
 }\r
 \r
@@ -1572,7 +1603,7 @@ GetIndexInfoForOpcode (
   @retval  FALSE  This is not the highlight statement.\r
 \r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 IsSavedHighlightStatement (\r
   IN FORM_DISPLAY_ENGINE_STATEMENT  *HighLightedStatement\r
   )\r
@@ -1704,7 +1735,7 @@ IsTopOfScreeMenuOption (
 {\r
   if (gHighligthMenuInfo.TOSQuestionId != 0) {\r
     return (BOOLEAN) (GetQuestionIdInfo(MenuOption->ThisTag->OpCode) == gHighligthMenuInfo.TOSQuestionId);\r
-  } \r
+  }\r
 \r
   if(CompareMem (gHighligthMenuInfo.TOSOpCode, MenuOption->ThisTag->OpCode, gHighligthMenuInfo.TOSOpCode->Length) == 0) {\r
     if (gHighligthMenuInfo.TOSIndex == 0 || gHighligthMenuInfo.TOSIndex == GetIndexInfoForOpcode(MenuOption->ThisTag->OpCode)) {\r
@@ -1718,23 +1749,56 @@ IsTopOfScreeMenuOption (
 }\r
 \r
 /**\r
-  Find the Top of screen menu.\r
+  Calculate the distance between two menus and include the skip value of StartMenu.\r
 \r
-  If the input is NULL, base on the record highlight info in\r
-  gHighligthMenuInfo to find the last highlight menu.\r
+  @param  StartMenu             The link_entry pointer to start menu.\r
+  @param  EndMenu               The link_entry pointer to end menu.\r
 \r
-  @param  HighLightedStatement      The input highlight statement.\r
+**/\r
+UINTN\r
+GetDistanceBetweenMenus(\r
+  IN LIST_ENTRY  *StartMenu,\r
+  IN LIST_ENTRY  *EndMenu\r
+)\r
+{\r
+  LIST_ENTRY                 *Link;\r
+  UI_MENU_OPTION             *MenuOption;\r
+  UINTN                      Distance;\r
 \r
-  @retval  The highlight menu index.\r
+  Distance = 0;\r
+\r
+  Link = StartMenu;\r
+  while (Link != EndMenu) {\r
+    MenuOption = MENU_OPTION_FROM_LINK (Link);\r
+    if (MenuOption->Row == 0) {\r
+      UpdateOptionSkipLines (MenuOption);\r
+    }\r
+    Distance += MenuOption->Skip;\r
+    Link = Link->BackLink;\r
+  }\r
+  return Distance;\r
+}\r
+\r
+/**\r
+  Find the top of screen menu base on the previous record menu info.\r
+\r
+  @param  HighLightMenu      The link_entry pointer to highlight menu.\r
+\r
+  @retval  Return the the link_entry pointer top of screen menu.\r
 \r
 **/\r
 LIST_ENTRY *\r
 FindTopOfScreenMenuOption (\r
- VOID\r
- )\r
+  IN LIST_ENTRY                   *HighLightMenu\r
 )\r
 {\r
   LIST_ENTRY                      *NewPos;\r
   UI_MENU_OPTION                  *MenuOption;\r
+  UINTN                           TopRow;\r
+  UINTN                           BottomRow;\r
+\r
+  TopRow    = gStatementDimensions.TopRow    + SCROLL_ARROW_HEIGHT;\r
+  BottomRow = gStatementDimensions.BottomRow - SCROLL_ARROW_HEIGHT;\r
 \r
   NewPos = gMenuOption.ForwardLink;\r
   MenuOption = MENU_OPTION_FROM_LINK (NewPos);\r
@@ -1754,7 +1818,16 @@ FindTopOfScreenMenuOption (
   // Last time top of screen menu has disappeared.\r
   //\r
   if (NewPos == &gMenuOption) {\r
-    NewPos = NULL;\r
+    return NULL;\r
+  }\r
+  //\r
+  // Check whether highlight menu and top of screen menu can be shown within one page,\r
+  // if can't, return NULL to re-calcaulate the top of scrren menu. Because some new menus\r
+  // may be dynamically inserted between highlightmenu and previous top of screen menu,\r
+  // So previous record top of screen menu is not appropriate for current display.\r
+  //\r
+  if (GetDistanceBetweenMenus (HighLightMenu, NewPos) + 1 > BottomRow - TopRow) {\r
+    return NULL;\r
   }\r
 \r
   return NewPos;\r
@@ -1790,7 +1863,7 @@ FindTopMenu (
   //\r
   if (gMisMatch && gFormData->HiiHandle == gHighligthMenuInfo.HiiHandle && gFormData->FormId == gHighligthMenuInfo.FormId) {\r
     //\r
-    // Reenter caused by option mismatch or auto exit caused by refresh form(refresh interval/guid), \r
+    // Reenter caused by option mismatch or auto exit caused by refresh form(refresh interval/guid),\r
     // base on the record highlight info to find the highlight menu.\r
     //\r
 \r
@@ -1805,7 +1878,7 @@ FindTopMenu (
       //\r
       // Found the last time highlight menu.\r
       //\r
-      *TopOfScreen = FindTopOfScreenMenuOption();\r
+      *TopOfScreen = FindTopOfScreenMenuOption(*HighlightMenu);\r
       if (*TopOfScreen != NULL) {\r
         //\r
         // Found the last time selectable top of screen menu.\r
@@ -1857,8 +1930,8 @@ FindTopMenu (
       //\r
       MenuOption = MENU_OPTION_FROM_LINK (*HighlightMenu);\r
       UpdateOptionSkipLines (MenuOption);\r
-      \r
-      *TopOfScreen = FindTopOfScreenMenuOption();\r
+\r
+      *TopOfScreen = FindTopOfScreenMenuOption(*HighlightMenu);\r
       if (*TopOfScreen == NULL) {\r
         //\r
         // Not found last time top of screen menu, so base on current highlight menu\r
@@ -2017,7 +2090,7 @@ SetDisplayAttribute (
   )\r
 {\r
   FORM_DISPLAY_ENGINE_STATEMENT   *Statement;\r
-  \r
+\r
   Statement = MenuOption->ThisTag;\r
 \r
   if (Highlight) {\r
@@ -2067,11 +2140,11 @@ DisplayMenuString (
     PrintStringAtWithWidth (Col, Row, String, Width);\r
     return;\r
   }\r
-  \r
+\r
   //\r
   // Print the highlight menu string.\r
   // First print the highlight string.\r
-  // \r
+  //\r
   SetDisplayAttribute(MenuOption, TRUE);\r
   Length = PrintStringAt (Col, Row, String);\r
 \r
@@ -2091,7 +2164,7 @@ DisplayMenuString (
   @retval FALSE                    This menu option can't have option string.\r
 \r
 **/\r
-BOOLEAN \r
+BOOLEAN\r
 HasOptionString (\r
   IN UI_MENU_OPTION                  *MenuOption\r
   )\r
@@ -2160,8 +2233,8 @@ FxConfirmPopup (
 \r
   //\r
   // Below action need extra popup dialog to confirm.\r
-  // \r
-  CheckFlags = BROWSER_ACTION_DISCARD | \r
+  //\r
+  CheckFlags = BROWSER_ACTION_DISCARD |\r
                BROWSER_ACTION_DEFAULT |\r
                BROWSER_ACTION_SUBMIT |\r
                BROWSER_ACTION_RESET |\r
@@ -2176,12 +2249,12 @@ FxConfirmPopup (
 \r
   if ((Action & BROWSER_ACTION_DISCARD) == BROWSER_ACTION_DISCARD) {\r
     CfmStrLen += StrLen (gConfirmDiscardMsg);\r
-  } \r
+  }\r
 \r
   if ((Action & BROWSER_ACTION_DEFAULT) == BROWSER_ACTION_DEFAULT) {\r
     if (CfmStrLen != 0) {\r
       CfmStrLen += CatLen;\r
-    } \r
+    }\r
 \r
     CfmStrLen += StrLen (gConfirmDefaultMsg);\r
   }\r
@@ -2189,7 +2262,7 @@ FxConfirmPopup (
   if ((Action & BROWSER_ACTION_SUBMIT)  == BROWSER_ACTION_SUBMIT) {\r
     if (CfmStrLen != 0) {\r
       CfmStrLen += CatLen;\r
-    } \r
+    }\r
 \r
     CfmStrLen += StrLen (gConfirmSubmitMsg);\r
   }\r
@@ -2197,7 +2270,7 @@ FxConfirmPopup (
   if ((Action & BROWSER_ACTION_RESET)  == BROWSER_ACTION_RESET) {\r
     if (CfmStrLen != 0) {\r
       CfmStrLen += CatLen;\r
-    } \r
+    }\r
 \r
     CfmStrLen += StrLen (gConfirmResetMsg);\r
   }\r
@@ -2205,7 +2278,7 @@ FxConfirmPopup (
   if ((Action & BROWSER_ACTION_EXIT)  == BROWSER_ACTION_EXIT) {\r
     if (CfmStrLen != 0) {\r
       CfmStrLen += CatLen;\r
-    } \r
+    }\r
 \r
     CfmStrLen += StrLen (gConfirmExitMsg);\r
   }\r
@@ -2283,7 +2356,7 @@ FxConfirmPopup (
   @param  MenuOption               The menu opton which this attribut used to.\r
   @param  SkipWidth                The skip width between the left to the start of the prompt.\r
   @param  BeginCol                 The begin column for one menu.\r
-  @param  SkipLine                 The skip line for this menu. \r
+  @param  SkipLine                 The skip line for this menu.\r
   @param  BottomRow                The bottom row for this form.\r
   @param  Highlight                Whether this menu will be highlight.\r
   @param  UpdateCol                Whether need to update the column info for Date/Time.\r
@@ -2352,12 +2425,12 @@ DisplayOneMenu (
       //\r
       ProcessStringForDateTime(MenuOption, OptionString, UpdateCol);\r
     }\r
-  \r
+\r
     Width       = (UINT16) gOptionBlockWidth - 1;\r
     Row         = MenuOption->Row;\r
     GlyphWidth  = 1;\r
     OptionLineNum = 0;\r
-  \r
+\r
     for (Index = 0; GetLineByWidth (OptionString, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
       if (((Temp2 == 0)) && (Row <= BottomRow)) {\r
         if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP || Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {\r
@@ -2375,7 +2448,7 @@ DisplayOneMenu (
           } else {\r
             //\r
             // For date/ time, print the first and second past (year for date and second for time)\r
-            // The OutputString has a NARROW_CHAR or WIDE_CHAR at the begin of the string, \r
+            // The OutputString has a NARROW_CHAR or WIDE_CHAR at the begin of the string,\r
             // so need to - 1 to remove it, otherwise, it will clean 1 extr char follow it.\r
             DisplayMenuString (MenuOption, MenuOption->OptCol, Row, OutputString, StrLen (OutputString) - 1, Highlight);\r
           }\r
@@ -2384,7 +2457,7 @@ DisplayOneMenu (
         }\r
         OptionLineNum++;\r
       }\r
-      \r
+\r
       //\r
       // If there is more string to process print on the next row and increment the Skip value\r
       //\r
@@ -2403,13 +2476,13 @@ DisplayOneMenu (
           }\r
         }\r
       }\r
-  \r
+\r
       FreePool (OutputString);\r
       if (Temp2 != 0) {\r
         Temp2--;\r
       }\r
     }\r
-  \r
+\r
     Highlight = FALSE;\r
 \r
     FreePool (OptionString);\r
@@ -2427,13 +2500,13 @@ DisplayOneMenu (
     PrintStringAtWithWidth (BeginCol, Row, L"", PromptWidth + AdjustValue + SkipWidth);\r
     PromptLineNum++;\r
   } else {\r
-    for (Index = 0; GetLineByWidth (MenuOption->Description, PromptWidth, &GlyphWidth, &Index, &OutputString) != 0x0000;) {      \r
-      if ((Temp == 0) && (Row <= BottomRow)) { \r
+    for (Index = 0; GetLineByWidth (MenuOption->Description, PromptWidth, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
+      if ((Temp == 0) && (Row <= BottomRow)) {\r
         //\r
-        // 1.Clean the start LEFT_SKIPPED_COLUMNS \r
+        // 1.Clean the start LEFT_SKIPPED_COLUMNS\r
         //\r
         PrintStringAtWithWidth (BeginCol, Row, L"", SkipWidth);\r
-        \r
+\r
         if (Statement->OpCode->OpCode == EFI_IFR_REF_OP && MenuOption->Col >= 2 && IsProcessingFirstRow) {\r
           //\r
           // Print Arrow for Goto button.\r
@@ -2472,13 +2545,13 @@ DisplayOneMenu (
   //\r
   if ((Statement->OpCode->OpCode  == EFI_IFR_TEXT_OP) && (((EFI_IFR_TEXT*)Statement->OpCode)->TextTwo != 0)) {\r
     StringPtr   = GetToken (((EFI_IFR_TEXT*)Statement->OpCode)->TextTwo, gFormData->HiiHandle);\r
-  \r
+\r
     Width       = (UINT16) gOptionBlockWidth - 1;\r
     Row         = MenuOption->Row;\r
     GlyphWidth  = 1;\r
     OptionLineNum = 0;\r
 \r
-    for (Index = 0; GetLineByWidth (StringPtr, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) { \r
+    for (Index = 0; GetLineByWidth (StringPtr, Width, &GlyphWidth, &Index, &OutputString) != 0x0000;) {\r
       if ((Temp3 == 0) && (Row <= BottomRow)) {\r
         DisplayMenuString (MenuOption, MenuOption->OptCol, Row, OutputString, Width + 1, Highlight);\r
         OptionLineNum++;\r
@@ -2497,7 +2570,7 @@ DisplayOneMenu (
           }\r
         }\r
       }\r
-  \r
+\r
       FreePool (OutputString);\r
       if (Temp3 != 0) {\r
         Temp3--;\r
@@ -2516,7 +2589,7 @@ DisplayOneMenu (
     Row    = (OptionLineNum < PromptLineNum ? OptionLineNum : PromptLineNum) + MenuOption->Row;\r
     Width  = (UINT16) (OptionLineNum < PromptLineNum ? gOptionBlockWidth : PromptWidth + AdjustValue + SkipWidth);\r
     MaxRow = (OptionLineNum < PromptLineNum ? PromptLineNum : OptionLineNum) + MenuOption->Row - 1;\r
-    \r
+\r
     while (Row <= MaxRow) {\r
       DisplayMenuString (MenuOption, Col, Row++, L"", Width, FALSE);\r
     }\r
@@ -2644,7 +2717,7 @@ UiDisplayMenu (
   while (TRUE) {\r
     switch (ControlFlag) {\r
     case CfInitialization:\r
-      if ((gOldFormEntry.HiiHandle != FormData->HiiHandle) || \r
+      if ((gOldFormEntry.HiiHandle != FormData->HiiHandle) ||\r
           (!CompareGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid))) {\r
         //\r
         // Clear Statement range if different formset is painted.\r
@@ -2673,7 +2746,7 @@ UiDisplayMenu (
         Row             = TopRow;\r
 \r
         gST->ConOut->SetAttribute (gST->ConOut, GetFieldTextColor ());\r
-        \r
+\r
         //\r
         // 1. Check whether need to print the arrow up.\r
         //\r
@@ -2722,19 +2795,19 @@ UiDisplayMenu (
           }\r
 \r
           if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {\r
-            Status = DisplayOneMenu (MenuOption, \r
+            Status = DisplayOneMenu (MenuOption,\r
                             MenuOption->Col - gStatementDimensions.LeftColumn,\r
-                            gStatementDimensions.LeftColumn + gModalSkipColumn, \r
-                            Link == TopOfScreen ? SkipValue : 0, \r
+                            gStatementDimensions.LeftColumn + gModalSkipColumn,\r
+                            Link == TopOfScreen ? SkipValue : 0,\r
                             BottomRow,\r
                             (BOOLEAN) ((Link == NewPos) && IsSelectable(MenuOption)),\r
                             TRUE\r
                             );\r
           } else {\r
-            Status = DisplayOneMenu (MenuOption, \r
+            Status = DisplayOneMenu (MenuOption,\r
                             MenuOption->Col - gStatementDimensions.LeftColumn,\r
-                            gStatementDimensions.LeftColumn, \r
-                            Link == TopOfScreen ? SkipValue : 0, \r
+                            gStatementDimensions.LeftColumn,\r
+                            Link == TopOfScreen ? SkipValue : 0,\r
                             BottomRow,\r
                             (BOOLEAN) ((Link == NewPos) && IsSelectable(MenuOption)),\r
                             TRUE\r
@@ -2842,10 +2915,10 @@ UiDisplayMenu (
           //\r
           // Remove the old highlight menu.\r
           //\r
-          Status = DisplayOneMenu (MenuOption, \r
+          Status = DisplayOneMenu (MenuOption,\r
                           MenuOption->Col - gStatementDimensions.LeftColumn,\r
-                          gStatementDimensions.LeftColumn, \r
-                          Temp, \r
+                          gStatementDimensions.LeftColumn,\r
+                          Temp,\r
                           BottomRow,\r
                           FALSE,\r
                           FALSE\r
@@ -2862,10 +2935,10 @@ UiDisplayMenu (
           break;\r
         }\r
 \r
-        Status = DisplayOneMenu (MenuOption, \r
+        Status = DisplayOneMenu (MenuOption,\r
                         MenuOption->Col - gStatementDimensions.LeftColumn,\r
-                        gStatementDimensions.LeftColumn, \r
-                        Temp2, \r
+                        gStatementDimensions.LeftColumn,\r
+                        Temp2,\r
                         BottomRow,\r
                         TRUE,\r
                         FALSE\r
@@ -2965,7 +3038,7 @@ UiDisplayMenu (
       //\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
+      // 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
@@ -3020,7 +3093,7 @@ UiDisplayMenu (
               );\r
           }\r
         } else {\r
-          for (Index = 0; (Index < RowCount - HelpBottomLine - HelpHeaderLine) && \r
+          for (Index = 0; (Index < RowCount - HelpBottomLine - HelpHeaderLine) &&\r
               (Index + HelpPageIndex * (RowCount - 2) + 1 < HelpLine); Index++) {\r
             PrintStringAtWithWidth (\r
               gStatementDimensions.RightColumn - gHelpBlockWidth,\r
@@ -3040,13 +3113,13 @@ UiDisplayMenu (
             }\r
             gST->ConOut->SetCursorPosition(gST->ConOut, gStatementDimensions.RightColumn-1, BottomRow);\r
           }\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
+      // 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
@@ -3098,7 +3171,7 @@ UiDisplayMenu (
         if (Status != EFI_NOT_READY) {\r
           continue;\r
         }\r
-        \r
+\r
         EventType = UiWaitForEvent(gST->ConIn->WaitForKey);\r
         if (EventType == UIEventKey) {\r
           gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
@@ -3112,7 +3185,7 @@ UiDisplayMenu (
         ControlFlag = CfExit;\r
         break;\r
       }\r
-      \r
+\r
       if (EventType == UIEventTimeOut) {\r
         gUserInput->Action = BROWSER_ACTION_FORM_EXIT;\r
         ControlFlag = CfExit;\r
@@ -3156,7 +3229,7 @@ UiDisplayMenu (
           } else {\r
             gDirection = SCAN_LEFT;\r
           }\r
-          \r
+\r
           Status = ProcessOptions (MenuOption, TRUE, &OptionString, TRUE);\r
           if (OptionString != NULL) {\r
             FreePool (OptionString);\r
@@ -3187,7 +3260,7 @@ UiDisplayMenu (
           ControlFlag = CfReadKey;\r
           break;\r
         }\r
-        \r
+\r
         ASSERT(MenuOption != NULL);\r
         if (MenuOption->ThisTag->OpCode->OpCode == EFI_IFR_CHECKBOX_OP && !MenuOption->GrayOut && !MenuOption->ReadOnly) {\r
           ScreenOperation = UiSelect;\r
@@ -3221,7 +3294,7 @@ UiDisplayMenu (
             break;\r
           }\r
         }\r
-        \r
+\r
         if (((FormData->Attribute & HII_DISPLAY_MODAL) != 0) && (Key.ScanCode == SCAN_ESC || Index == mScanCodeNumber)) {\r
           //\r
           // ModalForm has no ESC key and Hot Key.\r
@@ -3286,11 +3359,11 @@ UiDisplayMenu (
         //\r
         RefreshKeyHelp (gFormData, Statement, TRUE);\r
         Status = ProcessOptions (MenuOption, TRUE, &OptionString, TRUE);\r
-        \r
+\r
         if (OptionString != NULL) {\r
           FreePool (OptionString);\r
         }\r
-        \r
+\r
         if (EFI_ERROR (Status)) {\r
           Repaint = TRUE;\r
           NewLine = TRUE;\r
@@ -3420,12 +3493,12 @@ UiDisplayMenu (
         // Check whether new highlight menu is selectable, if not, keep highlight on the old one.\r
         //\r
         // BottomRow - TopRow + 1 means the total rows current forms supported.\r
-        // Difference + NextMenuOption->Skip + 1 means the distance between last highlight menu \r
-        // and new top menu. New top menu will all shows in next form, but last highlight menu \r
-        // may only shows 1 line. + 1 at right part means at least need to keep 1 line for the \r
+        // Difference + NextMenuOption->Skip + 1 means the distance between last highlight menu\r
+        // and new top menu. New top menu will all shows in next form, but last highlight menu\r
+        // may only shows 1 line. + 1 at right part means at least need to keep 1 line for the\r
         // last highlight menu.\r
-        // \r
-        if (!IsSelectable(NextMenuOption) && IsSelectable(MenuOption) && \r
+        //\r
+        if (!IsSelectable(NextMenuOption) && IsSelectable(MenuOption) &&\r
             (BottomRow - TopRow + 1 >= Difference + NextMenuOption->Skip + 1)) {\r
           NewPos = SavedListEntry;\r
         }\r
@@ -3466,11 +3539,11 @@ UiDisplayMenu (
       } else {\r
         Index     = (BottomRow + 1) - SkipValue - TopRow;\r
       }\r
-      \r
+\r
       TopOfScreen = FindTopOfScreenMenu(TopOfScreen, Index, &SkipValue);\r
       NewPos = TopOfScreen;\r
       MoveToNextStatement (FALSE, &NewPos, BottomRow - TopRow, FALSE);\r
-      \r
+\r
       UpdateStatusBar (INPUT_ERROR, FALSE);\r
 \r
       //\r
@@ -3589,7 +3662,7 @@ UiDisplayMenu (
         //\r
         // Scroll to the first page.\r
         //\r
-        if (TopOfScreen != gMenuOption.ForwardLink || SkipValue != 0) { \r
+        if (TopOfScreen != gMenuOption.ForwardLink || SkipValue != 0) {\r
           TopOfScreen = gMenuOption.ForwardLink;\r
           Repaint     = TRUE;\r
           MenuOption  = NULL;\r
@@ -3608,7 +3681,7 @@ UiDisplayMenu (
 \r
         UpdateHighlightMenuInfo(NewPos, TopOfScreen, SkipValue);\r
         break;\r
-      }        \r
+      }\r
 \r
       //\r
       // Get next selected menu info.\r
@@ -3687,12 +3760,12 @@ UiDisplayMenu (
       // Check whether new highlight menu is selectable, if not, keep highlight on the old one.\r
       //\r
       // BottomRow - TopRow + 1 means the total rows current forms supported.\r
-      // Difference + NextMenuOption->Skip + 1 means the distance between last highlight menu \r
-      // and new top menu. New top menu will all shows in next form, but last highlight menu \r
-      // may only shows 1 line. + 1 at right part means at least need to keep 1 line for the \r
+      // Difference + NextMenuOption->Skip + 1 means the distance between last highlight menu\r
+      // and new top menu. New top menu will all shows in next form, but last highlight menu\r
+      // may only shows 1 line. + 1 at right part means at least need to keep 1 line for the\r
       // last highlight menu.\r
-      // \r
-      if (!IsSelectable (NextMenuOption) && IsSelectable (MenuOption) && \r
+      //\r
+      if (!IsSelectable (NextMenuOption) && IsSelectable (MenuOption) &&\r
          (BottomRow - TopRow + 1 >= Difference + NextMenuOption->Skip + 1)) {\r
         NewPos = SavedListEntry;\r
       }\r
@@ -3911,7 +3984,7 @@ BrowserStatusProcess (
       // Show the dialog first to avoid long time not reaction.\r
       //\r
       gBS->SignalEvent (RefreshIntervalEvent);\r
-    \r
+\r
       Status = gBS->SetTimer (RefreshIntervalEvent, TimerPeriodic, ONE_SECOND);\r
       ASSERT_EFI_ERROR (Status);\r
 \r
@@ -3952,17 +4025,17 @@ BrowserStatusProcess (
 \r
 /**\r
   Display one form, and return user input.\r
-  \r
+\r
   @param FormData                Form Data to be shown.\r
   @param UserInputData           User input data.\r
-  \r
+\r
   @retval EFI_SUCCESS            1.Form Data is shown, and user input is got.\r
                                  2.Error info has show and return.\r
   @retval EFI_INVALID_PARAMETER  The input screen dimension is not valid\r
   @retval EFI_NOT_FOUND          New form data has some error.\r
 **/\r
 EFI_STATUS\r
-EFIAPI \r
+EFIAPI\r
 FormDisplay (\r
   IN  FORM_DISPLAY_ENGINE_FORM  *FormData,\r
   OUT USER_INPUT                *UserInputData\r
@@ -4001,7 +4074,7 @@ FormDisplay (
   //\r
   //  Left                                              right\r
   //   |<-.->|<-.........->|<- .........->|<-...........->|\r
-  //     Skip    Prompt         Option         Help \r
+  //     Skip    Prompt         Option         Help\r
   //\r
   gOptionBlockWidth = (CHAR16) ((gStatementDimensions.RightColumn - gStatementDimensions.LeftColumn) / 3) + 1;\r
   gHelpBlockWidth   = (CHAR16) (gOptionBlockWidth - 1 - LEFT_SKIPPED_COLUMNS);\r
@@ -4012,7 +4085,7 @@ FormDisplay (
   //\r
   // Check whether layout is changed.\r
   //\r
-  if (mIsFirstForm \r
+  if (mIsFirstForm\r
       || (gOldFormEntry.HiiHandle != FormData->HiiHandle)\r
       || (!CompareGuid (&gOldFormEntry.FormSetGuid, &FormData->FormSetGuid))\r
       || (gOldFormEntry.FormId != FormData->FormId)) {\r
@@ -4022,7 +4095,7 @@ FormDisplay (
   }\r
 \r
   Status = UiDisplayMenu(FormData);\r
-  \r
+\r
   //\r
   // Backup last form info.\r
   //\r
@@ -4043,7 +4116,7 @@ FormDisplay (
   Clear Screen to the initial state.\r
 **/\r
 VOID\r
-EFIAPI \r
+EFIAPI\r
 DriverClearDisplayPage (\r
   VOID\r
   )\r
@@ -4119,14 +4192,25 @@ InitializeDisplayEngine (
                   );\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  //\r
+  // Install HII Popup Protocol.\r
+  //\r
+  Status = gBS->InstallProtocolInterface (\r
+                 &mPrivateData.Handle,\r
+                 &gEfiHiiPopupProtocolGuid,\r
+                 EFI_NATIVE_INTERFACE,\r
+                 &mPrivateData.HiiPopup\r
+                );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   InitializeDisplayStrings();\r
-  \r
+\r
   ZeroMem (&gHighligthMenuInfo, sizeof (gHighligthMenuInfo));\r
   ZeroMem (&gOldFormEntry, sizeof (gOldFormEntry));\r
 \r
   //\r
   // Use BrowserEx2 protocol to register HotKey.\r
-  // \r
+  //\r
   Status = gBS->LocateProtocol (&gEdkiiFormBrowserEx2ProtocolGuid, NULL, (VOID **) &FormBrowserEx2);\r
   if (!EFI_ERROR (Status)) {\r
     //\r
@@ -4137,11 +4221,13 @@ InitializeDisplayEngine (
     NewString         = HiiGetString (gHiiHandle, STRING_TOKEN (FUNCTION_TEN_STRING), NULL);\r
     ASSERT (NewString != NULL);\r
     FormBrowserEx2->RegisterHotKey (&HotKey, BROWSER_ACTION_SUBMIT, 0, NewString);\r
+    FreePool (NewString);\r
 \r
     HotKey.ScanCode   = SCAN_F9;\r
     NewString         = HiiGetString (gHiiHandle, STRING_TOKEN (FUNCTION_NINE_STRING), NULL);\r
     ASSERT (NewString != NULL);\r
     FormBrowserEx2->RegisterHotKey (&HotKey, BROWSER_ACTION_DEFAULT, EFI_HII_DEFAULT_CLASS_STANDARD, NewString);\r
+    FreePool (NewString);\r
   }\r
 \r
   return EFI_SUCCESS;\r