]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/ProcessOptions.c
Add new call back return value; also add some sample code to use it.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / ProcessOptions.c
index 639c04dafbad5a1930ed10dd08d6bd51a263a112..aa57fe437c729d77e83baed67c6e0ba67648cbd1 100644 (file)
@@ -2,8 +2,8 @@
 Implementation for handling the User Interface option processing.\r
 \r
 \r
-Copyright (c) 2004 - 2009, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2004 - 2011, 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
@@ -302,9 +302,8 @@ PasswordCallback (
   EFI_STATUS                      Status;\r
   EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess;\r
   EFI_BROWSER_ACTION_REQUEST      ActionRequest;\r
-  EFI_HII_VALUE                   *QuestionValue;\r
+  EFI_IFR_TYPE_VALUE              IfrTypeValue;\r
 \r
-  QuestionValue = &MenuOption->ThisTag->HiiValue;\r
   ConfigAccess = Selection->FormSet->ConfigAccess;\r
   if (ConfigAccess == NULL) {\r
     return EFI_UNSUPPORTED;\r
@@ -314,9 +313,9 @@ PasswordCallback (
   // Prepare password string in HII database\r
   //\r
   if (String != NULL) {\r
-    QuestionValue->Value.string = NewString (String, Selection->FormSet->HiiHandle);\r
+    IfrTypeValue.string = NewString (String, Selection->FormSet->HiiHandle);\r
   } else {\r
-    QuestionValue->Value.string = 0;\r
+    IfrTypeValue.string = 0;\r
   }\r
 \r
   //\r
@@ -326,8 +325,8 @@ PasswordCallback (
                            ConfigAccess,\r
                            EFI_BROWSER_ACTION_CHANGING,\r
                            MenuOption->ThisTag->QuestionId,\r
-                           QuestionValue->Type,\r
-                           &QuestionValue->Value,\r
+                           MenuOption->ThisTag->HiiValue.Type,\r
+                           &IfrTypeValue,\r
                            &ActionRequest\r
                            );\r
 \r
@@ -335,7 +334,7 @@ PasswordCallback (
   // Remove password string from HII database\r
   //\r
   if (String != NULL) {\r
-    DeleteString (QuestionValue->Value.string, Selection->FormSet->HiiHandle);\r
+    DeleteString (IfrTypeValue.string, Selection->FormSet->HiiHandle);\r
   }\r
 \r
   return Status;\r
@@ -402,12 +401,14 @@ ProcessOptions (
   UINTN                           Index2;\r
   UINT8                           *ValueArray;\r
   UINT8                           ValueType;\r
+  EFI_STRING_ID                   StringId;\r
 \r
   Status        = EFI_SUCCESS;\r
 \r
   StringPtr     = NULL;\r
   Character[1]  = L'\0';\r
   *OptionString = NULL;\r
+  StringId      = 0;\r
 \r
   ZeroMem (FormattedNumber, 21 * sizeof (CHAR16));\r
   BufferSize = (gOptionBlockWidth + 1) * 2 * gScreenDimensions.BottomRow;\r
@@ -421,6 +422,12 @@ ProcessOptions (
 \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
@@ -475,7 +482,7 @@ ProcessOptions (
           SetArrayData (ValueArray, ValueType, Index2, 0);\r
 \r
           Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
-          UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+          UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
 \r
           FreePool (*OptionString);\r
           *OptionString = NULL;\r
@@ -508,6 +515,12 @@ ProcessOptions (
     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
@@ -537,7 +550,7 @@ ProcessOptions (
               !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
+            UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
             break;\r
           }\r
 \r
@@ -573,8 +586,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
+            UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+            gST->ConOut->SetAttribute (gST->ConOut, PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND);\r
             break;\r
           }\r
 \r
@@ -625,7 +638,7 @@ ProcessOptions (
       // Save Question value\r
       //\r
       Status = SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
-      UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+      UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
     }\r
 \r
     if (QuestionValue->Value.b) {\r
@@ -730,10 +743,16 @@ ProcessOptions (
 \r
       Status = ReadString (MenuOption, gPromptForData, StringPtr);\r
       if (!EFI_ERROR (Status)) {\r
-        CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
-        SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
+        HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r
+        Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
+        if (EFI_ERROR (Status)) {\r
+          HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);\r
+        } else {\r
+          CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
+          SetQuestionValue (Selection->FormSet, Selection->Form, Question, TRUE);\r
 \r
-        UpdateStatusBar (NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+          UpdateStatusBar (Selection, NV_UPDATE_REQUIRED, Question->QuestionFlags, TRUE);\r
+        }\r
       }\r
 \r
       FreePool (StringPtr);\r
@@ -766,8 +785,9 @@ ProcessOptions (
         //\r
         *StringPtr = 0;\r
         Status = PasswordCallback (Selection, MenuOption, StringPtr);\r
-        if (Status == EFI_NOT_AVAILABLE_YET) {\r
+        if (Status == EFI_NOT_AVAILABLE_YET || Status == EFI_UNSUPPORTED) {\r
           //\r
+          // Callback is not supported, or\r
           // Callback request to terminate password input\r
           //\r
           FreePool (StringPtr);\r
@@ -877,13 +897,47 @@ ProcessOptions (
       //\r
       if (StrCmp (StringPtr, TempString) == 0) {\r
         //\r
-        // Two password match, send it to Configuration Driver\r
+        // Prepare the  Question->HiiValue.Value.string for ValidateQuestion use.\r
         //\r
-        if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
-          PasswordCallback (Selection, MenuOption, StringPtr);\r
+        if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
+          StringId = Question->HiiValue.Value.string;\r
+          Question->HiiValue.Value.string = NewString (StringPtr, Selection->FormSet->HiiHandle);\r
         } else {\r
-          CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
-          SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);\r
+          HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, StringPtr, NULL);\r
+        }\r
+        \r
+        Status = ValidateQuestion(Selection->FormSet, Selection->Form, Question, EFI_HII_EXPRESSION_INCONSISTENT_IF);\r
+\r
+        //\r
+        //  Researve the Question->HiiValue.Value.string.\r
+        //\r
+        if((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
+          DeleteString(Question->HiiValue.Value.string, Selection->FormSet->HiiHandle);\r
+          Question->HiiValue.Value.string = StringId;\r
+        }   \r
+        \r
+        if (EFI_ERROR (Status)) {\r
+          //\r
+          // Reset state machine for interactive password\r
+          //\r
+          if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
+            PasswordCallback (Selection, MenuOption, NULL);\r
+          } else {\r
+            //\r
+            // Researve the Question->HiiValue.Value.string.\r
+            //\r
+            HiiSetString(Selection->FormSet->HiiHandle, Question->HiiValue.Value.string, (CHAR16*)Question->BufferValue, NULL);            \r
+          }\r
+        } else {\r
+          //\r
+          // Two password match, send it to Configuration Driver\r
+          //\r
+          if ((Question->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != 0) {\r
+            PasswordCallback (Selection, MenuOption, StringPtr);\r
+          } else {\r
+            CopyMem (Question->BufferValue, StringPtr, Maximum * sizeof (CHAR16));\r
+            SetQuestionValue (Selection->FormSet, Selection->Form, Question, FALSE);\r
+          }\r
         }\r
       } else {\r
         //\r