]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / ProcessOptions.c
index eaa832a99826c013b21fea59bb5fb17e05667e3d..6bd2063cafb40e27c45a2c6836463b44cb245002 100644 (file)
@@ -2,8 +2,8 @@
 Implementation for handling the User Interface option processing.\r
 \r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2010, 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
 http://opensource.org/licenses/bsd-license.php\r
@@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \r
 **/\r
 \r
-#include "Ui.h"\r
 #include "Setup.h"\r
 \r
 \r
@@ -101,6 +100,96 @@ ValueToOption (
 }\r
 \r
 \r
+/**\r
+  Return data element in an Array by its Index.\r
+\r
+  @param  Array                  The data array.\r
+  @param  Type                   Type of the data in this array.\r
+  @param  Index                  Zero based index for data in this array.\r
+\r
+  @retval Value                  The data to be returned\r
+\r
+**/\r
+UINT64\r
+GetArrayData (\r
+  IN VOID                     *Array,\r
+  IN UINT8                    Type,\r
+  IN UINTN                    Index\r
+  )\r
+{\r
+  UINT64 Data;\r
+\r
+  ASSERT (Array != NULL);\r
+\r
+  Data = 0;\r
+  switch (Type) {\r
+  case EFI_IFR_TYPE_NUM_SIZE_8:\r
+    Data = (UINT64) *(((UINT8 *) Array) + Index);\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_16:\r
+    Data = (UINT64) *(((UINT16 *) Array) + Index);\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_32:\r
+    Data = (UINT64) *(((UINT32 *) Array) + Index);\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_64:\r
+    Data = (UINT64) *(((UINT64 *) Array) + Index);\r
+    break;\r
+\r
+  default:\r
+    break;\r
+  }\r
+\r
+  return Data;\r
+}\r
+\r
+\r
+/**\r
+  Set value of a data element in an Array by its Index.\r
+\r
+  @param  Array                  The data array.\r
+  @param  Type                   Type of the data in this array.\r
+  @param  Index                  Zero based index for data in this array.\r
+  @param  Value                  The value to be set.\r
+\r
+**/\r
+VOID\r
+SetArrayData (\r
+  IN VOID                     *Array,\r
+  IN UINT8                    Type,\r
+  IN UINTN                    Index,\r
+  IN UINT64                   Value\r
+  )\r
+{\r
+\r
+  ASSERT (Array != NULL);\r
+\r
+  switch (Type) {\r
+  case EFI_IFR_TYPE_NUM_SIZE_8:\r
+    *(((UINT8 *) Array) + Index) = (UINT8) Value;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_16:\r
+    *(((UINT16 *) Array) + Index) = (UINT16) Value;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_32:\r
+    *(((UINT32 *) Array) + Index) = (UINT32) Value;\r
+    break;\r
+\r
+  case EFI_IFR_TYPE_NUM_SIZE_64:\r
+    *(((UINT64 *) Array) + Index) = (UINT64) Value;\r
+    break;\r
+\r
+  default:\r
+    break;\r
+  }\r
+}\r
+\r
+\r
 /**\r
   Print Question Value according to it's storage width and display attributes.\r
 \r
@@ -309,6 +398,10 @@ ProcessOptions (
   EFI_HII_VALUE                   *QuestionValue;\r
   BOOLEAN                         Suppress;\r
   UINT16                          Maximum;\r
+  QUESTION_OPTION                 *Option;\r
+  UINTN                           Index2;\r
+  UINT8                           *ValueArray;\r
+  UINT8                           ValueType;\r
 \r
   Status        = EFI_SUCCESS;\r
 \r
@@ -323,13 +416,21 @@ ProcessOptions (
   QuestionValue = &Question->HiiValue;\r
   Maximum = (UINT16) Question->Maximum;\r
 \r
+  ValueArray = Question->BufferValue;\r
+  ValueType = Question->ValueType;\r
+\r
   switch (Question->Operand) {\r
   case EFI_IFR_ORDERED_LIST_OP:\r
+    //\r
+    // Check whether there are Options of this OrderedList\r
+    //\r
+    if (IsListEmpty (&Question->OptionListHead)) {\r
+      break;\r
+    }\r
     //\r
     // Initialize Option value array\r
     //\r
-\r
-    if (Question->BufferValue[0] == 0) {\r
+    if (GetArrayData (ValueArray, ValueType, 0) == 0) {\r
       GetQuestionDefault (Selection->FormSet, Selection->Form, Question, 0);\r
     }\r
 \r
@@ -346,11 +447,11 @@ ProcessOptions (
       *OptionString = AllocateZeroPool (Question->MaxContainers * BufferSize);\r
       ASSERT (*OptionString);\r
 \r
-      HiiValue.Type = EFI_IFR_TYPE_NUM_SIZE_8;\r
+      HiiValue.Type = ValueType;\r
       HiiValue.Value.u64 = 0;\r
       for (Index = 0; Index < Question->MaxContainers; Index++) {\r
-        HiiValue.Value.u8 = Question->BufferValue[Index];\r
-        if (HiiValue.Value.u8 == 0) {\r
+        HiiValue.Value.u64 = GetArrayData (ValueArray, ValueType, Index);\r
+        if (HiiValue.Value.u64 == 0) {\r
           //\r
           // Values for the options in ordered lists should never be a 0\r
           //\r
@@ -359,7 +460,31 @@ ProcessOptions (
 \r
         OneOfOption = ValueToOption (Question, &HiiValue);\r
         if (OneOfOption == NULL) {\r
-          gBS->FreePool (*OptionString);\r
+          //\r
+          // Show error message\r
+          //\r
+          do {\r
+            CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r
+          } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+\r
+          //\r
+          // The initial value of the orderedlist is invalid, force to be valid value\r
+          //\r
+          Link = GetFirstNode (&Question->OptionListHead);\r
+          Index2 = 0;\r
+          while (!IsNull (&Question->OptionListHead, Link) && Index2 < Question->MaxContainers) {\r
+            Option = QUESTION_OPTION_FROM_LINK (Link);\r
+            SetArrayData (ValueArray, ValueType, Index2, Option->Value.Value.u64);\r
+            Index2++;\r
+            Link = GetNextNode (&Question->OptionListHead, Link);\r
+          }\r
+          SetArrayData (ValueArray, ValueType, Index2, 0);\r
+\r
+          Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
+          UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+\r
+          FreePool (*OptionString);\r
+          *OptionString = NULL;\r
           return EFI_NOT_FOUND;\r
         }\r
 \r
@@ -382,13 +507,19 @@ ProcessOptions (
           Character[0] = CHAR_CARRIAGE_RETURN;\r
           NewStrCat (OptionString[0], Character);\r
 \r
-          gBS->FreePool (StringPtr);\r
+          FreePool (StringPtr);\r
         }\r
       }\r
     }\r
     break;\r
 \r
   case EFI_IFR_ONE_OF_OP:\r
+    //\r
+    // Check whether there are Options of this OneOf\r
+    //\r
+    if (IsListEmpty (&Question->OptionListHead)) {\r
+      break;\r
+    }\r
     if (Selected) {\r
       //\r
       // Go ask for input\r
@@ -400,7 +531,33 @@ ProcessOptions (
 \r
       OneOfOption = ValueToOption (Question, QuestionValue);\r
       if (OneOfOption == NULL) {\r
-        gBS->FreePool (*OptionString);\r
+        //\r
+        // Show error message\r
+        //\r
+        do {\r
+          CreateDialog (4, TRUE, 0, NULL, &Key, gEmptyString, gOptionMismatch, gPressEnter, gEmptyString);\r
+        } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
+\r
+        //\r
+        // Force the Question value to be valid\r
+        //\r
+        Link = GetFirstNode (&Question->OptionListHead);\r
+        while (!IsNull (&Question->OptionListHead, Link)) {\r
+          Option = QUESTION_OPTION_FROM_LINK (Link);\r
+\r
+          if ((Option->SuppressExpression == NULL) ||\r
+              !Option->SuppressExpression->Result.Value.b) {\r
+            CopyMem (QuestionValue, &Option->Value, sizeof (EFI_HII_VALUE));\r
+            SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
+            UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+            break;\r
+          }\r
+\r
+          Link = GetNextNode (&Question->OptionListHead, Link);\r
+        }\r
+\r
+        FreePool (*OptionString);\r
+        *OptionString = NULL;\r
         return EFI_NOT_FOUND;\r
       }\r
 \r
@@ -428,6 +585,8 @@ ProcessOptions (
             Suppress = FALSE;\r
             CopyMem (QuestionValue, &OneOfOption->Value, sizeof (EFI_HII_VALUE));\r
             SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
+            UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+            gST->ConOut->SetAttribute (gST->ConOut, FIELD_TEXT | FIELD_BACKGROUND);\r
             break;\r
           }\r
 \r
@@ -443,7 +602,7 @@ ProcessOptions (
         Character[0] = RIGHT_ONEOF_DELIMITER;\r
         NewStrCat (OptionString[0], Character);\r
 \r
-        gBS->FreePool (StringPtr);\r
+        FreePool (StringPtr);\r
       }\r
     }\r
     break;\r
@@ -469,7 +628,8 @@ ProcessOptions (
         // Inconsistent check fail, restore Question Value\r
         //\r
         QuestionValue->Value.b = (BOOLEAN) (QuestionValue->Value.b ? FALSE : TRUE);\r
-        gBS->FreePool (*OptionString);\r
+        FreePool (*OptionString);\r
+        *OptionString = NULL;\r
         return Status;\r
       }\r
 \r
@@ -588,7 +748,7 @@ ProcessOptions (
         UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
       }\r
 \r
-      gBS->FreePool (StringPtr);\r
+      FreePool (StringPtr);\r
     } else {\r
       *OptionString = AllocateZeroPool (BufferSize);\r
       ASSERT (*OptionString);\r
@@ -622,7 +782,7 @@ ProcessOptions (
           //\r
           // Callback request to terminate password input\r
           //\r
-          gBS->FreePool (StringPtr);\r
+          FreePool (StringPtr);\r
           return EFI_SUCCESS;\r
         }\r
 \r
@@ -632,7 +792,7 @@ ProcessOptions (
           //\r
           Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r
           if (EFI_ERROR (Status)) {\r
-            gBS->FreePool (StringPtr);\r
+            FreePool (StringPtr);\r
             return Status;\r
           }\r
 \r
@@ -650,7 +810,7 @@ ProcessOptions (
               Status = EFI_SUCCESS;\r
             }\r
 \r
-            gBS->FreePool (StringPtr);\r
+            FreePool (StringPtr);\r
             return Status;\r
           }\r
         }\r
@@ -664,11 +824,13 @@ ProcessOptions (
           //\r
           Status = ReadString (MenuOption, gPromptForPassword, StringPtr);\r
           if (EFI_ERROR (Status)) {\r
-            gBS->FreePool (StringPtr);\r
+            FreePool (StringPtr);\r
             return Status;\r
           }\r
 \r
           TempString = AllocateCopyPool ((Maximum + 1) * sizeof (CHAR16), Question->BufferValue);\r
+          ASSERT (TempString != NULL);\r
+\r
           TempString[Maximum] = L'\0';\r
 \r
           if (StrCmp (StringPtr, TempString) != 0) {\r
@@ -677,12 +839,12 @@ ProcessOptions (
             //\r
             PasswordInvalid ();\r
 \r
-            gBS->FreePool (StringPtr);\r
-            gBS->FreePool (TempString);\r
+            FreePool (StringPtr);\r
+            FreePool (TempString);\r
             return Status;\r
           }\r
 \r
-          gBS->FreePool (TempString);\r
+          FreePool (TempString);\r
         }\r
       }\r
 \r
@@ -699,7 +861,7 @@ ProcessOptions (
           PasswordCallback (Selection, MenuOption, NULL);\r
         }\r
 \r
-        gBS->FreePool (StringPtr);\r
+        FreePool (StringPtr);\r
         return Status;\r
       }\r
 \r
@@ -717,8 +879,8 @@ ProcessOptions (
           PasswordCallback (Selection, MenuOption, NULL);\r
         }\r
 \r
-        gBS->FreePool (StringPtr);\r
-        gBS->FreePool (TempString);\r
+        FreePool (StringPtr);\r
+        FreePool (TempString);\r
         return Status;\r
       }\r
 \r
@@ -751,8 +913,8 @@ ProcessOptions (
         } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
       }\r
 \r
-      gBS->FreePool (TempString);\r
-      gBS->FreePool (StringPtr);\r
+      FreePool (TempString);\r
+      FreePool (StringPtr);\r
     }\r
     break;\r
 \r
@@ -780,7 +942,7 @@ ProcessHelpString (
   IN  UINTN   RowCount\r
   )\r
 {\r
-  CONST UINTN BlockWidth = (UINTN) gHelpBlockWidth - 1;\r
+  UINTN BlockWidth;\r
   UINTN AllocateSize;\r
   //\r
   // [PrevCurrIndex, CurrIndex) forms a range of a screen-line\r
@@ -813,6 +975,8 @@ ProcessHelpString (
   UINTN *IndexArray;\r
   UINTN *OldIndexArray;\r
 \r
+  BlockWidth = (UINTN) gHelpBlockWidth - 1;\r
+\r
   //\r
   // every three elements of IndexArray form a screen-line of string:[ IndexArray[i*3], IndexArray[i*3+1] )\r
   // IndexArray[i*3+2] stores the initial glyph width of single character. to save this is because we want\r
@@ -822,9 +986,10 @@ ProcessHelpString (
   //\r
   AllocateSize  = 0x20;\r
   IndexArray    = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
+  ASSERT (IndexArray != NULL);\r
 \r
   if (*FormattedString != NULL) {\r
-    gBS->FreePool (*FormattedString);\r
+    FreePool (*FormattedString);\r
     *FormattedString = NULL;\r
   }\r
 \r
@@ -837,8 +1002,10 @@ ProcessHelpString (
       AllocateSize += 0x10;\r
       OldIndexArray  = IndexArray;\r
       IndexArray = AllocatePool (AllocateSize * sizeof (UINTN) * 3);\r
+      ASSERT (IndexArray != NULL);\r
+\r
       CopyMem (IndexArray, OldIndexArray, LineCount * sizeof (UINTN) * 3);\r
-      gBS->FreePool (OldIndexArray);\r
+      FreePool (OldIndexArray);\r
     }\r
     switch (StringPtr[CurrIndex]) {\r
 \r
@@ -957,6 +1124,7 @@ ProcessHelpString (
 \r
   VirtualLineCount = RowCount * (LineCount / RowCount + (LineCount % RowCount > 0));\r
   *FormattedString = AllocateZeroPool (VirtualLineCount * (BlockWidth + 1) * sizeof (CHAR16) * 2);\r
+  ASSERT (*FormattedString != NULL);\r
 \r
   for (CurrIndex = 0; CurrIndex < LineCount; CurrIndex ++) {\r
     *(*FormattedString + CurrIndex * 2 * (BlockWidth + 1)) = (CHAR16) ((IndexArray[CurrIndex*3+2] == 2) ? WIDE_CHAR : NARROW_CHAR);\r
@@ -967,5 +1135,5 @@ ProcessHelpString (
       );\r
   }\r
 \r
-  gBS->FreePool (IndexArray);\r
+  FreePool (IndexArray);\r
 }\r