]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Presentation.c
Base on the type field to get the width of value field for option opcode.
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Presentation.c
index ba39f30253d0b1d988e4c9c7f45851c996279bea..62811c751a1e1d56601f6975df794c0874eb7077 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Utility functions for UI presentation.\r
 \r
-Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2012, 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
@@ -468,7 +468,6 @@ DisplayForm (
   CHAR16                 *StringPtr;\r
   UINT16                 MenuItemCount;\r
   EFI_HII_HANDLE         Handle;\r
-  BOOLEAN                Suppress;\r
   EFI_SCREEN_DESCRIPTOR  LocalScreen;\r
   UINT16                 Width;\r
   UINTN                  ArrayEntry;\r
@@ -478,6 +477,7 @@ DisplayForm (
   UINT16                 NumberOfLines;\r
   EFI_STATUS             Status;\r
   UI_MENU_OPTION         *MenuOption;\r
+  UINT16                 GlyphWidth;\r
 \r
   Handle        = Selection->Handle;\r
   MenuItemCount = 0;\r
@@ -521,17 +521,7 @@ DisplayForm (
   while (!IsNull (&Selection->Form->StatementListHead, Link)) {\r
     Statement = FORM_BROWSER_STATEMENT_FROM_LINK (Link);\r
 \r
-    if (Statement->SuppressExpression != NULL) {\r
-      Suppress = Statement->SuppressExpression->Result.Value.b;\r
-    } else {\r
-      Suppress = FALSE;\r
-    }\r
-\r
-    if (Statement->DisableExpression != NULL) {\r
-      Suppress = (BOOLEAN) (Suppress || Statement->DisableExpression->Result.Value.b);\r
-    }\r
-\r
-    if (!Suppress) {\r
+    if (EvaluateExpressionList(Statement->Expression, FALSE, NULL, NULL) <= ExpressGrayOut) {\r
       StringPtr = GetToken (Statement->Prompt, Handle);\r
       ASSERT (StringPtr != NULL);\r
 \r
@@ -539,7 +529,8 @@ DisplayForm (
 \r
       NumberOfLines = 1;\r
       ArrayEntry = 0;\r
-      for (; GetLineByWidth (StringPtr, Width, &ArrayEntry, &OutputString) != 0x0000;) {\r
+      GlyphWidth = 1;\r
+      for (; GetLineByWidth (StringPtr, Width, &GlyphWidth,&ArrayEntry, &OutputString) != 0x0000;) {\r
         //\r
         // If there is more string to process print on the next row and increment the Skip value\r
         //\r
@@ -1220,11 +1211,8 @@ ProcessCallBackFunction (
     //\r
     // Check whether Statement is disabled.\r
     //\r
-    if (Statement->DisableExpression != NULL) {\r
-      Status = EvaluateExpression (Selection->FormSet, Selection->Form, Statement->DisableExpression);\r
-      if (!EFI_ERROR (Status) && \r
-          (Statement->DisableExpression->Result.Type == EFI_IFR_TYPE_BOOLEAN) && \r
-          (Statement->DisableExpression->Result.Value.b)) {\r
+    if (Statement->Expression != NULL) {\r
+      if (EvaluateExpressionList(Statement->Expression, TRUE, Selection->FormSet, Selection->Form) == ExpressDisable) {\r
         continue;\r
       }\r
     }\r
@@ -1248,45 +1236,50 @@ ProcessCallBackFunction (
                              &ActionRequest\r
                              );\r
     if (!EFI_ERROR (Status)) {\r
-      switch (ActionRequest) {\r
-      case EFI_BROWSER_ACTION_REQUEST_RESET:\r
-        gResetRequired = TRUE;\r
-        Selection->Action = UI_ACTION_EXIT;\r
-        break;\r
+      //\r
+      // Only for EFI_BROWSER_ACTION_CHANGED need to handle this ActionRequest.\r
+      //\r
+      if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
+        switch (ActionRequest) {\r
+        case EFI_BROWSER_ACTION_REQUEST_RESET:\r
+          gResetRequired = TRUE;\r
+          Selection->Action = UI_ACTION_EXIT;\r
+          break;\r
 \r
-      case EFI_BROWSER_ACTION_REQUEST_SUBMIT:\r
-        SubmitFormIsRequired = TRUE;\r
-        Selection->Action = UI_ACTION_EXIT;\r
-        break;\r
+        case EFI_BROWSER_ACTION_REQUEST_SUBMIT:\r
+          SubmitFormIsRequired = TRUE;\r
+          Selection->Action = UI_ACTION_EXIT;\r
+          break;\r
 \r
-      case EFI_BROWSER_ACTION_REQUEST_EXIT:\r
-        Selection->Action = UI_ACTION_EXIT;\r
-        break;\r
+        case EFI_BROWSER_ACTION_REQUEST_EXIT:\r
+          Selection->Action = UI_ACTION_EXIT;\r
+          break;\r
 \r
-      case EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT:\r
-        SubmitFormIsRequired  = TRUE;\r
-        SettingLevel          = FormLevel;\r
-        NeedExit              = TRUE;\r
-        break;\r
+        case EFI_BROWSER_ACTION_REQUEST_FORM_SUBMIT_EXIT:\r
+          SubmitFormIsRequired  = TRUE;\r
+          SettingLevel          = FormLevel;\r
+          NeedExit              = TRUE;\r
+          break;\r
 \r
-      case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT:\r
-        DiscardFormIsRequired = TRUE;\r
-        SettingLevel          = FormLevel;      \r
-        NeedExit              = TRUE;\r
-        break;\r
+        case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT:\r
+          DiscardFormIsRequired = TRUE;\r
+          SettingLevel          = FormLevel;      \r
+          NeedExit              = TRUE;\r
+          break;\r
 \r
-      case EFI_BROWSER_ACTION_REQUEST_FORM_APPLY:\r
-        SubmitFormIsRequired  = TRUE;\r
-        SettingLevel          = FormLevel;\r
-        break;\r
+        case EFI_BROWSER_ACTION_REQUEST_FORM_APPLY:\r
+          SubmitFormIsRequired  = TRUE;\r
+          SettingLevel          = FormLevel;\r
+          break;\r
 \r
-      case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD:\r
-        DiscardFormIsRequired = TRUE;\r
-        SettingLevel          = FormLevel;\r
-        break;\r
+        case EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD:\r
+          DiscardFormIsRequired = TRUE;\r
+          SettingLevel          = FormLevel;\r
+          break;\r
 \r
-      default:\r
-        break;\r
+        default:\r
+          break;\r
+        }\r
       }\r
 \r
       //\r
@@ -1294,7 +1287,7 @@ ProcessCallBackFunction (
       // "retrieve" should update to the question's temp buffer.\r
       //\r
       if (Action == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
-        SetQuestionValue(Selection->FormSet, Selection->Form, Statement, TRUE);\r
+        SetQuestionValue(Selection->FormSet, Selection->Form, Statement, GetSetValueWithEditBuffer);\r
       }\r
     } else {\r
       //\r
@@ -1302,7 +1295,7 @@ ProcessCallBackFunction (
       // "retrieve", should restore the question's value.\r
       //\r
       if (Action  == EFI_BROWSER_ACTION_CHANGING || Action == EFI_BROWSER_ACTION_RETRIEVE) {\r
-        GetQuestionValue(Selection->FormSet, Selection->Form, Statement, TRUE);\r
+        GetQuestionValue(Selection->FormSet, Selection->Form, Statement, GetSetValueWithEditBuffer);\r
       }\r
 \r
       if (Status == EFI_UNSUPPORTED) {\r
@@ -1329,6 +1322,57 @@ ProcessCallBackFunction (
   return Status;\r
 }\r
 \r
+/**\r
+  Call the retrieve type call back function for one question to get the initialize data.\r
+  \r
+  This function only used when in the initialize stage, because in this stage, the \r
+  Selection->Form is not ready. For other case, use the ProcessCallBackFunction instead.\r
+\r
+  @param ConfigAccess          The config access protocol produced by the hii driver.\r
+  @param Statement             The Question which need to call.\r
+\r
+  @retval EFI_SUCCESS          The call back function excutes successfully.\r
+  @return Other value if the call back function failed to excute.  \r
+**/\r
+EFI_STATUS \r
+ProcessRetrieveForQuestion (\r
+  IN     EFI_HII_CONFIG_ACCESS_PROTOCOL  *ConfigAccess,\r
+  IN     FORM_BROWSER_STATEMENT          *Statement\r
+  )\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_BROWSER_ACTION_REQUEST      ActionRequest;\r
+  EFI_HII_VALUE                   *HiiValue;\r
+  EFI_IFR_TYPE_VALUE              *TypeValue;\r
+\r
+  Status                = EFI_SUCCESS;\r
+  ActionRequest         = EFI_BROWSER_ACTION_REQUEST_NONE;\r
+    \r
+  if ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) != EFI_IFR_FLAG_CALLBACK) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  HiiValue  = &Statement->HiiValue;\r
+  TypeValue = &HiiValue->Value;\r
+  if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {\r
+    //\r
+    // For OrderedList, passing in the value buffer to Callback()\r
+    //\r
+    TypeValue = (EFI_IFR_TYPE_VALUE *) Statement->BufferValue;\r
+  }\r
+    \r
+  ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;\r
+  Status = ConfigAccess->Callback (\r
+                           ConfigAccess,\r
+                           EFI_BROWSER_ACTION_RETRIEVE,\r
+                           Statement->QuestionId,\r
+                           HiiValue->Type,\r
+                           TypeValue,\r
+                           &ActionRequest\r
+                           );\r
+  return Status;\r
+}\r
+\r
 /**\r
   The worker function that send the displays to the screen. On output,\r
   the selection made by user is returned.\r
@@ -1392,6 +1436,15 @@ SetupBrowser (
   InsertTailList (&gBrowserFormSetList, &gOldFormSet->Link);\r
 \r
   do {\r
+    //\r
+    // IFR is updated, force to reparse the IFR binary\r
+    //\r
+    if (mHiiPackageListUpdated) {\r
+      Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
+      mHiiPackageListUpdated = FALSE;\r
+      break;\r
+    }\r
+\r
     //\r
     // Initialize Selection->Form\r
     //\r
@@ -1419,13 +1472,7 @@ SetupBrowser (
     // Check Form is suppressed.\r
     //\r
     if (Selection->Form->SuppressExpression != NULL) {\r
-      Status = EvaluateExpression (Selection->FormSet, Selection->Form, Selection->Form->SuppressExpression);\r
-      if (EFI_ERROR (Status) || (Selection->Form->SuppressExpression->Result.Type != EFI_IFR_TYPE_BOOLEAN)) {\r
-        Status = EFI_INVALID_PARAMETER;\r
-        goto Done;\r
-      }\r
-\r
-      if (Selection->Form->SuppressExpression->Result.Value.b) {\r
+      if (EvaluateExpressionList(Selection->Form->SuppressExpression, TRUE, Selection->FormSet, Selection->Form) == ExpressSuppress) {\r
         //\r
         // Form is suppressed. \r
         //\r
@@ -1438,11 +1485,6 @@ SetupBrowser (
       }\r
     }\r
 \r
-    //\r
-    // Reset FormPackage update flag\r
-    //\r
-    mHiiPackageListUpdated = FALSE;\r
-\r
     //\r
     // Before display new form, invoke ConfigAccess.Callback() with EFI_BROWSER_ACTION_FORM_OPEN\r
     // for each question with callback flag.\r
@@ -1526,11 +1568,6 @@ SetupBrowser (
         gResetRequired = TRUE;\r
       }\r
 \r
-      //\r
-      // Reset FormPackage update flag\r
-      //\r
-      mHiiPackageListUpdated = FALSE;\r
-\r
       if ((ConfigAccess != NULL) && \r
           ((Statement->QuestionFlags & EFI_IFR_FLAG_CALLBACK) == EFI_IFR_FLAG_CALLBACK) && \r
           (Statement->Operand != EFI_IFR_PASSWORD_OP)) {\r
@@ -1555,21 +1592,10 @@ SetupBrowser (
           }\r
         }\r
 \r
-        if ((Status == EFI_SUCCESS) && (Statement->Operand != EFI_IFR_REF_OP)) {\r
+        if (!EFI_ERROR (Status) && Statement->Operand != EFI_IFR_REF_OP) {\r
           ProcessCallBackFunction(Selection, Statement, EFI_BROWSER_ACTION_CHANGED, FALSE);\r
         }\r
       }\r
-\r
-      //\r
-      // Check whether Form Package has been updated during Callback\r
-      //\r
-      if (mHiiPackageListUpdated && (Selection->Action == UI_ACTION_REFRESH_FORM)) {\r
-        //\r
-        // Force to reparse IFR binary of target Formset\r
-        //\r
-        mHiiPackageListUpdated = FALSE;\r
-        Selection->Action = UI_ACTION_REFRESH_FORMSET;\r
-      }\r
     }\r
 \r
     //\r