]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Application/UiApp/FrontPageCustomizedUiSupport.c
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Application / UiApp / FrontPageCustomizedUiSupport.c
index b838222106ee956e1bd9a57b4d3a49d8c52950fe..c9823e565de8c10bc9e122fc2c04c866e072ad5b 100644 (file)
@@ -3,13 +3,7 @@
   This library class defines a set of interfaces to customize Ui module\r
 \r
 Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
-This program and the accompanying materials are licensed and made available under\r
-the terms and conditions of the BSD License that accompanies this distribution.\r
-The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php.\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 #include <Uefi.h>\r
@@ -43,6 +37,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define FRONT_PAGE_KEY_CONTINUE               0x1000\r
 #define FRONT_PAGE_KEY_RESET                  0x1001\r
 #define FRONT_PAGE_KEY_LANGUAGE               0x1002\r
+#define FRONT_PAGE_KEY_DRIVER                 0x2000\r
 \r
 typedef struct {\r
   EFI_STRING_ID   PromptId;\r
@@ -55,7 +50,8 @@ typedef struct {
 CHAR8                        *gLanguageString;\r
 EFI_STRING_ID                *gLanguageToken;\r
 UI_HII_DRIVER_INSTANCE       *gHiiDriverList;\r
-EFI_HII_HANDLE               gHiiHandle;\r
+extern EFI_HII_HANDLE        gStringPackHandle;\r
+UINT8                        gCurrentLanguageIndex;\r
 \r
 \r
 /**\r
@@ -130,6 +126,7 @@ LanguageChangeHandler (
     GetNextLanguage (&LangCode, Lang);\r
 \r
     if (Index == Value->u8) {\r
+      gCurrentLanguageIndex = Value->u8;\r
       break;\r
     }\r
 \r
@@ -190,6 +187,16 @@ UiSupportLibCallbackHandler (
     return FALSE;\r
   }\r
 \r
+  if (Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
+    if (QuestionId == FRONT_PAGE_KEY_LANGUAGE) {\r
+      Value->u8 = gCurrentLanguageIndex;\r
+      *Status = EFI_SUCCESS;\r
+    } else {\r
+      *Status = EFI_UNSUPPORTED;\r
+    }\r
+    return TRUE;\r
+  }\r
+\r
   if (Action != EFI_BROWSER_ACTION_CHANGED) {\r
     //\r
     // Do nothing for other UEFI Action. Only do call back when data is changed.\r
@@ -236,11 +243,8 @@ UiSupportLibCallbackHandler (
   Create Select language menu in the front page with oneof opcode.\r
 \r
   @param[in]    HiiHandle           The hii handle for the Uiapp driver.\r
-  @param[in]    QuestionId          Question ID\r
   @param[in]    StartOpCodeHandle   The opcode handle to save the new opcode.\r
 \r
-  @retval   EFI_SUCCESS         Search the driver success\r
-\r
 **/\r
 VOID\r
 UiCreateLanguageMenu (\r
@@ -250,6 +254,7 @@ UiCreateLanguageMenu (
 {\r
   CHAR8                       *LangCode;\r
   CHAR8                       *Lang;\r
+  UINTN                       LangSize;\r
   CHAR8                       *CurrentLang;\r
   UINTN                       OptionCount;\r
   CHAR16                      *StringBuffer;\r
@@ -319,9 +324,10 @@ UiCreateLanguageMenu (
       }\r
 \r
       if (EFI_ERROR (Status)) {\r
-        StringBuffer = AllocatePool (AsciiStrSize (Lang) * sizeof (CHAR16));\r
+        LangSize = AsciiStrSize (Lang);\r
+        StringBuffer = AllocatePool (LangSize * sizeof (CHAR16));\r
         ASSERT (StringBuffer != NULL);\r
-        AsciiStrToUnicodeStr (Lang, StringBuffer);\r
+        AsciiStrToUnicodeStrS (Lang, StringBuffer, LangSize);\r
       }\r
 \r
       ASSERT (StringBuffer != NULL);\r
@@ -350,6 +356,7 @@ UiCreateLanguageMenu (
         EFI_IFR_NUMERIC_SIZE_1,\r
         (UINT8) OptionCount\r
         );\r
+      gCurrentLanguageIndex = (UINT8) OptionCount;\r
     } else {\r
       HiiCreateOneOfOptionOpCode (\r
         OptionsOpCodeHandle,\r
@@ -547,8 +554,8 @@ RequiredDriver (
 \r
   @param    HiiHandle           The hii handle for the Uiapp driver.\r
   @param    ClassGuid           The class guid for the driver which is the target.\r
+  @param    SpecialHandlerFn    The pointer to the specail handler function, if any.\r
   @param    StartOpCodeHandle   The opcode handle to save the new opcode.\r
-  @param    SpecialHandler      The pointer to the specail handler function, if any.\r
 \r
   @retval   EFI_SUCCESS         Search the driver success\r
 \r
@@ -592,7 +599,7 @@ UiListThirdPartyDrivers (
 \r
     String = HiiGetString (HiiHandles[Index], Token, NULL);\r
     if (String == NULL) {\r
-      String = HiiGetString (gHiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r
+      String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r
       ASSERT (String != NULL);\r
     } else if (SpecialHandlerFn != NULL) {\r
       //\r
@@ -610,7 +617,7 @@ UiListThirdPartyDrivers (
 \r
     String = HiiGetString (HiiHandles[Index], TokenHelp, NULL);\r
     if (String == NULL) {\r
-      String = HiiGetString (gHiiHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r
+      String = HiiGetString (gStringPackHandle, STRING_TOKEN (STR_MISSING_STRING), NULL);\r
       ASSERT (String != NULL);\r
     }\r
     DriverListPtr[Count].HelpId = HiiSetString (HiiHandle, 0, String, NULL);\r
@@ -626,9 +633,13 @@ UiListThirdPartyDrivers (
 \r
     Count++;\r
     if (Count >= CurrentSize) {\r
-      DriverListPtr = AllocateCopyPool ((Count + UI_HII_DRIVER_LIST_SIZE) * sizeof (UI_HII_DRIVER_INSTANCE), gHiiDriverList);\r
+      DriverListPtr = ReallocatePool (\r
+                        CurrentSize * sizeof (UI_HII_DRIVER_INSTANCE),\r
+                        (Count + UI_HII_DRIVER_LIST_SIZE)\r
+                          * sizeof (UI_HII_DRIVER_INSTANCE),\r
+                        gHiiDriverList\r
+                        );\r
       ASSERT (DriverListPtr != NULL);\r
-      FreePool (gHiiDriverList);\r
       gHiiDriverList = DriverListPtr;\r
       CurrentSize += UI_HII_DRIVER_LIST_SIZE;\r
     }\r
@@ -644,7 +655,7 @@ UiListThirdPartyDrivers (
       gHiiDriverList[Index].PromptId,\r
       gHiiDriverList[Index].HelpId,\r
       0,\r
-      0,\r
+      (EFI_QUESTION_ID) (Index + FRONT_PAGE_KEY_DRIVER),\r
       0,\r
       &gHiiDriverList[Index].FormSetGuid,\r
       gHiiDriverList[Index].DevicePathId\r