]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Ui.c
HII Library Class interface refine.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Ui.c
index 962437455093a0ce3711e753aa4b0c95543e8729..4d2fc8871aaf7dd3f6831cea115ebac5971889bd 100644 (file)
@@ -117,6 +117,7 @@ SCREEN_OPERATION_T0_CONTROL_FLAG  gScreenOperationToControlFlag[] = {
 };\r
 \r
 BOOLEAN  mInputError;\r
+BOOLEAN GetLineByWidthFinished = FALSE;\r
 \r
 \r
 /**\r
@@ -190,7 +191,7 @@ UiRemoveMenuListEntry (
     Selection->FormId = UiMenuList->FormId;\r
     Selection->QuestionId = UiMenuList->QuestionId;\r
     RemoveEntryList (&UiMenuList->MenuLink);\r
-    gBS->FreePool (UiMenuList);\r
+    FreePool (UiMenuList);\r
   }\r
 }\r
 \r
@@ -209,7 +210,7 @@ UiFreeMenuList (
   while (!IsListEmpty (&gMenuList)) {\r
     UiMenuList = CR (gMenuList.ForwardLink, UI_MENU_LIST, MenuLink, UI_MENU_LIST_SIGNATURE);\r
     RemoveEntryList (&UiMenuList->MenuLink);\r
-    gBS->FreePool (UiMenuList);\r
+    FreePool (UiMenuList);\r
   }\r
 }\r
 \r
@@ -262,9 +263,9 @@ UiFreeMenu (
       // Data format :      [01/02/2004]      [11:22:33]\r
       // Line number :        0  0    1         0  0  1\r
       //\r
-      gBS->FreePool (MenuOption->Description);\r
+      FreePool (MenuOption->Description);\r
     }\r
-    gBS->FreePool (MenuOption);\r
+    FreePool (MenuOption);\r
   }\r
 }\r
 \r
@@ -282,7 +283,7 @@ UiFreeRefreshList (
 \r
   while (gMenuRefreshHead != NULL) {\r
     OldMenuRefreshEntry = gMenuRefreshHead->Next;\r
-    gBS->FreePool (gMenuRefreshHead);\r
+    FreePool (gMenuRefreshHead);\r
     gMenuRefreshHead = OldMenuRefreshEntry;\r
   }\r
 \r
@@ -341,7 +342,7 @@ RefreshForm (
           ;\r
 \r
         PrintStringAt (MenuRefreshEntry->CurrentColumn, MenuRefreshEntry->CurrentRow, &OptionString[Index]);\r
-        gBS->FreePool (OptionString);\r
+        FreePool (OptionString);\r
       }\r
 \r
       //\r
@@ -728,8 +729,8 @@ CreateDialog (
       case CHAR_NULL:\r
         switch (Key.ScanCode) {\r
         case SCAN_ESC:\r
-          gBS->FreePool (TempString);\r
-          gBS->FreePool (BufferedString);\r
+          FreePool (TempString);\r
+          FreePool (BufferedString);\r
           gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
           gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
           return EFI_DEVICE_ERROR;\r
@@ -742,8 +743,8 @@ CreateDialog (
 \r
       case CHAR_CARRIAGE_RETURN:\r
         SelectionComplete = TRUE;\r
-        gBS->FreePool (TempString);\r
-        gBS->FreePool (BufferedString);\r
+        FreePool (TempString);\r
+        FreePool (BufferedString);\r
         gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);\r
         gST->ConOut->EnableCursor (gST->ConOut, TRUE);\r
         return EFI_SUCCESS;\r
@@ -1017,8 +1018,8 @@ UpdateStatusBar (
     break;\r
   }\r
 \r
-  gBS->FreePool (InputErrorMessage);\r
-  gBS->FreePool (NvUpdateMessage);\r
+  FreePool (InputErrorMessage);\r
+  FreePool (NvUpdateMessage);\r
   return ;\r
 }\r
 \r
@@ -1050,7 +1051,7 @@ GetWidth (
   if ((Statement->Operand == EFI_IFR_TEXT_OP) && (Statement->TextTwo != 0)) {\r
     String = GetToken (Statement->TextTwo, Handle);\r
     Size   = StrLen (String);\r
-    gBS->FreePool (String);\r
+    FreePool (String);\r
   }\r
 \r
   if ((Statement->Operand == EFI_IFR_SUBTITLE_OP) ||\r
@@ -1075,9 +1076,6 @@ GetWidth (
   return Width;\r
 }\r
 \r
-\r
-BOOLEAN GetLineByWidthFinished = FALSE;\r
-\r
 /**\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
@@ -1218,7 +1216,7 @@ UpdateOptionSkipLines (
       //\r
       // If there is more string to process print on the next row and increment the Skip value\r
       //\r
-      if (StrLen (&OptionString[Index])) {\r
+      if (StrLen (&OptionString[Index]) != 0) {\r
         if (SkipValue == 0) {\r
           Row++;\r
           //\r
@@ -1234,7 +1232,7 @@ UpdateOptionSkipLines (
         }\r
       }\r
 \r
-      gBS->FreePool (OutputString);\r
+      FreePool (OutputString);\r
       if (SkipValue != 0) {\r
         SkipValue--;\r
       }\r
@@ -1450,6 +1448,102 @@ AdjustDateAndTimePosition (
   return PadLineNumber;\r
 }\r
 \r
+/**\r
+  Find HII Handle in the HII database associated with given Device Path.\r
+\r
+  If DevicePath is NULL, then ASSERT.\r
+\r
+  @param  DevicePath             Device Path associated with the HII package list\r
+                                 handle.\r
+\r
+  @retval Handle                 HII package list Handle associated with the Device\r
+                                        Path.\r
+  @retval NULL                   Hii Package list handle is not found.\r
+\r
+**/\r
+EFI_HII_HANDLE\r
+EFIAPI\r
+DevicePathToHiiHandle (\r
+  IN EFI_DEVICE_PATH_PROTOCOL   *DevicePath\r
+  )\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_DEVICE_PATH_PROTOCOL    *TmpDevicePath;\r
+  UINTN                       BufferSize;\r
+  UINTN                       HandleCount;\r
+  UINTN                       Index;\r
+  EFI_HANDLE                  Handle;\r
+  EFI_HANDLE                  DriverHandle;\r
+  EFI_HII_HANDLE              *HiiHandles;\r
+  EFI_HII_HANDLE              HiiHandle;\r
+\r
+  ASSERT (DevicePath != NULL);\r
+\r
+  TmpDevicePath = DevicePath;\r
+  //\r
+  // Locate Device Path Protocol handle buffer\r
+  //\r
+  Status = gBS->LocateDevicePath (\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &TmpDevicePath,\r
+                  &DriverHandle\r
+                  );\r
+  if (EFI_ERROR (Status) || !IsDevicePathEnd (TmpDevicePath)) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Retrieve all HII Handles from HII database\r
+  //\r
+  BufferSize = 0x1000;\r
+  HiiHandles = AllocatePool (BufferSize);\r
+  ASSERT (HiiHandles != NULL);\r
+  Status = mHiiDatabase->ListPackageLists (\r
+                           mHiiDatabase,\r
+                           EFI_HII_PACKAGE_TYPE_ALL,\r
+                           NULL,\r
+                           &BufferSize,\r
+                           HiiHandles\r
+                           );\r
+  if (Status == EFI_BUFFER_TOO_SMALL) {\r
+    FreePool (HiiHandles);\r
+    HiiHandles = AllocatePool (BufferSize);\r
+    ASSERT (HiiHandles != NULL);\r
+\r
+    Status = mHiiDatabase->ListPackageLists (\r
+                             mHiiDatabase,\r
+                             EFI_HII_PACKAGE_TYPE_ALL,\r
+                             NULL,\r
+                             &BufferSize,\r
+                             HiiHandles\r
+                             );\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (HiiHandles);\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Search Hii Handle by Driver Handle\r
+  //\r
+  HiiHandle = NULL;\r
+  HandleCount = BufferSize / sizeof (EFI_HII_HANDLE);\r
+  for (Index = 0; Index < HandleCount; Index++) {\r
+    Status = mHiiDatabase->GetPackageListHandle (\r
+                             mHiiDatabase,\r
+                             HiiHandles[Index],\r
+                             &Handle\r
+                             );\r
+    if (!EFI_ERROR (Status) && (Handle == DriverHandle)) {\r
+      HiiHandle = HiiHandles[Index];\r
+      break;\r
+    }\r
+  }\r
+\r
+  FreePool (HiiHandles);\r
+  return HiiHandle;\r
+}\r
 \r
 /**\r
   Display menu and wait for user to select one menu option, then return it.\r
@@ -1508,6 +1602,9 @@ UiDisplayMenu (
   UINT16                          DefaultId;\r
   EFI_DEVICE_PATH_PROTOCOL        *DevicePath;\r
   FORM_BROWSER_STATEMENT          *Statement;\r
+  CHAR16                          TemStr[2];\r
+  UINT8                           *DevicePathBuffer;\r
+  UINT8                           DigitUint8;\r
 \r
   CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));\r
 \r
@@ -1635,13 +1732,13 @@ UiDisplayMenu (
             //\r
             // If there is more string to process print on the next row and increment the Skip value\r
             //\r
-            if (StrLen (&MenuOption->Description[Index])) {\r
+            if (StrLen (&MenuOption->Description[Index]) != 0) {\r
               if (Temp == 0) {\r
                 Row++;\r
               }\r
             }\r
 \r
-            gBS->FreePool (OutputString);\r
+            FreePool (OutputString);\r
             if (Temp != 0) {\r
               Temp--;\r
             }\r
@@ -1730,7 +1827,7 @@ UiDisplayMenu (
               //\r
               // If there is more string to process print on the next row and increment the Skip value\r
               //\r
-              if (StrLen (&OptionString[Index])) {\r
+              if (StrLen (&OptionString[Index]) != 0) {\r
                 if (Temp2 == 0) {\r
                   Row++;\r
                   //\r
@@ -1746,7 +1843,7 @@ UiDisplayMenu (
                 }\r
               }\r
 \r
-              gBS->FreePool (OutputString);\r
+              FreePool (OutputString);\r
               if (Temp2 != 0) {\r
                 Temp2--;\r
               }\r
@@ -1755,7 +1852,7 @@ UiDisplayMenu (
             Temp2 = 0;\r
             Row   = OriginalRow;\r
 \r
-            gBS->FreePool (OptionString);\r
+            FreePool (OptionString);\r
           }\r
           //\r
           // If this is a text op with secondary text information\r
@@ -1773,7 +1870,7 @@ UiDisplayMenu (
               //\r
               // If there is more string to process print on the next row and increment the Skip value\r
               //\r
-              if (StrLen (&StringPtr[Index])) {\r
+              if (StrLen (&StringPtr[Index]) != 0) {\r
                 if (Temp2 == 0) {\r
                   Row++;\r
                   //\r
@@ -1789,14 +1886,14 @@ UiDisplayMenu (
                 }\r
               }\r
 \r
-              gBS->FreePool (OutputString);\r
+              FreePool (OutputString);\r
               if (Temp2 != 0) {\r
                 Temp2--;\r
               }\r
             }\r
 \r
             Row = OriginalRow;\r
-            gBS->FreePool (StringPtr);\r
+            FreePool (StringPtr);\r
           }\r
 \r
           //\r
@@ -1947,16 +2044,16 @@ UiDisplayMenu (
               //\r
               // If there is more string to process print on the next row and increment the Skip value\r
               //\r
-              if (StrLen (&OptionString[Index])) {\r
+              if (StrLen (&OptionString[Index]) != 0) {\r
                 MenuOption->Row++;\r
               }\r
 \r
-              gBS->FreePool (OutputString);\r
+              FreePool (OutputString);\r
             }\r
 \r
             MenuOption->Row = OriginalRow;\r
 \r
-            gBS->FreePool (OptionString);\r
+            FreePool (OptionString);\r
           } else {\r
             if (NewLine) {\r
               if (MenuOption->GrayOut) {\r
@@ -1975,11 +2072,11 @@ UiDisplayMenu (
                 //\r
                 // If there is more string to process print on the next row and increment the Skip value\r
                 //\r
-                if (StrLen (&MenuOption->Description[Index])) {\r
+                if (StrLen (&MenuOption->Description[Index]) != 0) {\r
                   MenuOption->Row++;\r
                 }\r
 \r
-                gBS->FreePool (OutputString);\r
+                FreePool (OutputString);\r
               }\r
 \r
               MenuOption->Row = OriginalRow;\r
@@ -2053,16 +2150,16 @@ UiDisplayMenu (
             //\r
             // If there is more string to process print on the next row and increment the Skip value\r
             //\r
-            if (StrLen (&OptionString[Index])) {\r
+            if (StrLen (&OptionString[Index]) != 0) {\r
               MenuOption->Row++;\r
             }\r
 \r
-            gBS->FreePool (OutputString);\r
+            FreePool (OutputString);\r
           }\r
 \r
           MenuOption->Row = OriginalRow;\r
 \r
-          gBS->FreePool (OptionString);\r
+          FreePool (OptionString);\r
         } else {\r
           if (NewLine) {\r
             OriginalRow = MenuOption->Row;\r
@@ -2076,11 +2173,11 @@ UiDisplayMenu (
               //\r
               // If there is more string to process print on the next row and increment the Skip value\r
               //\r
-              if (StrLen (&MenuOption->Description[Index])) {\r
+              if (StrLen (&MenuOption->Description[Index]) != 0) {\r
                 MenuOption->Row++;\r
               }\r
 \r
-              gBS->FreePool (OutputString);\r
+              FreePool (OutputString);\r
             }\r
 \r
             MenuOption->Row = OriginalRow;\r
@@ -2360,9 +2457,28 @@ UiDisplayMenu (
           }\r
           BufferSize = StrLen (StringPtr) / 2;\r
           DevicePath = AllocatePool (BufferSize);\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
-          HexStringToBufInReverseOrder ((UINT8 *) DevicePath, &BufferSize, StringPtr);\r
-          Selection->Handle = HiiLibDevicePathToHiiHandle (DevicePath);\r
+          Selection->Handle = DevicePathToHiiHandle (DevicePath);\r
           if (Selection->Handle == NULL) {\r
             //\r
             // If target Hii Handle not found, exit\r
@@ -2372,8 +2488,8 @@ UiDisplayMenu (
             break;\r
           }\r
 \r
-          gBS->FreePool (StringPtr);\r
-          gBS->FreePool (DevicePath);\r
+          FreePool (StringPtr);\r
+          FreePool (DevicePath);\r
 \r
           CopyMem (&Selection->FormSetGuid, &Statement->RefFormSetId, sizeof (EFI_GUID));\r
           Selection->FormId = Statement->RefFormId;\r