]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/SetupBrowserDxe/Setup.c
Change the FormBrowser behavior of "Pressing ESC":
[mirror_edk2.git] / MdeModulePkg / Universal / SetupBrowserDxe / Setup.c
index 4f2c92c818aa908bf7366930745a43bd4b3c1f5d..a8393aa502019a6b8b3f64c5cdcceef78dfe2903 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Entry and initialization module for the browser.\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation\r
+Copyright (c) 2007 - 2009, Intel Corporation\r
 All rights reserved. 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
@@ -45,7 +45,6 @@ BOOLEAN               gDownArrow;
 // Browser Global Strings\r
 //\r
 CHAR16            *gFunctionOneString;\r
-CHAR16            *gFunctionTwoString;\r
 CHAR16            *gFunctionNineString;\r
 CHAR16            *gFunctionTenString;\r
 CHAR16            *gEnterString;\r
@@ -87,6 +86,8 @@ EFI_GUID  gSetupBrowserGuid = {
   0xab368524, 0xb60c, 0x495b, {0xa0, 0x9, 0x12, 0xe8, 0x5b, 0x1a, 0xea, 0x32}\r
 };\r
 \r
+FORM_BROWSER_FORMSET  *gOldFormSet = NULL;\r
+\r
 FUNCTIION_KEY_SETTING gFunctionKeySettingTable[] = {\r
   //\r
   // Boot Manager\r
@@ -190,7 +191,7 @@ FUNCTIION_KEY_SETTING gFunctionKeySettingTable[] = {
   @param FormId          This field specifies which EFI_IFR_FORM to render as the first\r
                          displayable page. If this field has a value of 0x0000, then\r
                          the forms browser will render the specified forms in their encoded order.\r
-  @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in \r
+  @param ScreenDimensions Points to recommended form dimensions, including any non-content area, in\r
                           characters.\r
   @param ActionRequest   Points to the action recommended by the form.\r
 \r
@@ -287,6 +288,8 @@ SendForm (
       Selection->FormId = FormId;\r
     }\r
 \r
+    gNvUpdateRequired = FALSE;\r
+\r
     do {\r
       FormSet = AllocateZeroPool (sizeof (FORM_BROWSER_FORMSET));\r
       ASSERT (FormSet != NULL);\r
@@ -301,15 +304,6 @@ SendForm (
       }\r
       Selection->FormSet = FormSet;\r
 \r
-      //\r
-      // Initialize current settings of Questions in this FormSet\r
-      //\r
-      Status = InitializeCurrentSetting (FormSet);\r
-      if (EFI_ERROR (Status)) {\r
-        DestroyFormSet (FormSet);\r
-        break;\r
-      }\r
-\r
       //\r
       // Display this formset\r
       //\r
@@ -318,7 +312,6 @@ SendForm (
       Status = SetupBrowser (Selection);\r
 \r
       gCurrentSelection = NULL;\r
-      DestroyFormSet (FormSet);\r
 \r
       if (EFI_ERROR (Status)) {\r
         break;\r
@@ -326,6 +319,11 @@ SendForm (
 \r
     } while (Selection->Action == UI_ACTION_REFRESH_FORMSET);\r
 \r
+    if (gOldFormSet != NULL) {\r
+      DestroyFormSet (gOldFormSet);\r
+      gOldFormSet = NULL;\r
+    }\r
+\r
     FreePool (Selection);\r
   }\r
 \r
@@ -1128,7 +1126,7 @@ GetQuestionValue (
       if (EFI_ERROR (Status)) {\r
         return Status;\r
       }\r
-      \r
+\r
       LengthStr = StrLen (Value);\r
       Status    = EFI_SUCCESS;\r
       if (IsString) {\r
@@ -1529,7 +1527,7 @@ SetQuestionValue (
         TemString += UnicodeValueToString (TemString, PREFIX_ZERO | RADIX_HEX, *TemBuffer, 2);\r
       }\r
     }\r
-    \r
+\r
     //\r
     // Convert to lower char.\r
     //\r
@@ -1893,7 +1891,7 @@ GetQuestionDefault (
     //\r
     // Take first oneof option as oneof's default value\r
     //\r
-    if (ValueToOption (Question, HiiValue) == NULL) {    \r
+    if (ValueToOption (Question, HiiValue) == NULL) {\r
       Link = GetFirstNode (&Question->OptionListHead);\r
       if (!IsNull (&Question->OptionListHead, Link)) {\r
         Option = QUESTION_OPTION_FROM_LINK (Link);\r
@@ -2026,6 +2024,42 @@ LoadFormConfig (
 }\r
 \r
 \r
+/**\r
+  Initialize Question's Edit copy from Storage for the whole Formset.\r
+\r
+  @param  FormSet                FormSet data structure.\r
+\r
+  @retval EFI_SUCCESS            The function completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+LoadFormSetConfig (\r
+  IN FORM_BROWSER_FORMSET             *FormSet\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  LIST_ENTRY          *Link;\r
+  FORM_BROWSER_FORM   *Form;\r
+\r
+  Link = GetFirstNode (&FormSet->FormListHead);\r
+  while (!IsNull (&FormSet->FormListHead, Link)) {\r
+    Form = FORM_BROWSER_FORM_FROM_LINK (Link);\r
+\r
+    //\r
+    // Initialize local copy of Value for each Form\r
+    //\r
+    Status = LoadFormConfig (FormSet, Form);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Link = GetNextNode (&FormSet->FormListHead, Link);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   Fill storage's edit copy with settings requested from Configuration Driver.\r
 \r
@@ -2088,6 +2122,54 @@ LoadStorage (
 }\r
 \r
 \r
+/**\r
+  Copy uncommitted data from source Storage to destination Storage.\r
+\r
+  @param  Dst                    Target Storage for uncommitted data.\r
+  @param  Src                    Source Storage for uncommitted data.\r
+\r
+  @retval EFI_SUCCESS            The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER  Source and destination Storage is not the same type.\r
+\r
+**/\r
+EFI_STATUS\r
+CopyStorage (\r
+  IN OUT FORMSET_STORAGE     *Dst,\r
+  IN FORMSET_STORAGE         *Src\r
+  )\r
+{\r
+  LIST_ENTRY          *Link;\r
+  NAME_VALUE_NODE     *Node;\r
+\r
+  if ((Dst->Type != Src->Type) || (Dst->Size != Src->Size)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  switch (Src->Type) {\r
+  case EFI_HII_VARSTORE_BUFFER:\r
+    CopyMem (Dst->EditBuffer, Src->EditBuffer, Src->Size);\r
+    break;\r
+\r
+  case EFI_HII_VARSTORE_NAME_VALUE:\r
+    Link = GetFirstNode (&Src->NameValueListHead);\r
+    while (!IsNull (&Src->NameValueListHead, Link)) {\r
+      Node = NAME_VALUE_NODE_FROM_LINK (Link);\r
+\r
+      SetValueByName (Dst, Node->Name, Node->EditValue);\r
+\r
+      Link = GetNextNode (&Src->NameValueListHead, Link);\r
+    }\r
+    break;\r
+\r
+  case EFI_HII_VARSTORE_EFI_VARIABLE:\r
+  default:\r
+    break;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
 /**\r
   Get current setting of Questions.\r
 \r
@@ -2102,7 +2184,10 @@ InitializeCurrentSetting (
   )\r
 {\r
   LIST_ENTRY              *Link;\r
+  LIST_ENTRY              *Link2;\r
   FORMSET_STORAGE         *Storage;\r
+  FORMSET_STORAGE         *StorageSrc;\r
+  FORMSET_STORAGE         *OldStorage;\r
   FORM_BROWSER_FORM       *Form;\r
   EFI_STATUS              Status;\r
 \r
@@ -2125,7 +2210,35 @@ InitializeCurrentSetting (
   while (!IsNull (&FormSet->StorageListHead, Link)) {\r
     Storage = FORMSET_STORAGE_FROM_LINK (Link);\r
 \r
-    Status = LoadStorage (FormSet, Storage);\r
+    OldStorage = NULL;\r
+    if (gOldFormSet != NULL) {\r
+      //\r
+      // Try to find the Storage in backup formset gOldFormSet\r
+      //\r
+      Link2 = GetFirstNode (&gOldFormSet->StorageListHead);\r
+      while (!IsNull (&gOldFormSet->StorageListHead, Link2)) {\r
+        StorageSrc = FORMSET_STORAGE_FROM_LINK (Link2);\r
+\r
+        if (StorageSrc->VarStoreId == Storage->VarStoreId) {\r
+          OldStorage = StorageSrc;\r
+          break;\r
+        }\r
+\r
+        Link2 = GetNextNode (&gOldFormSet->StorageListHead, Link2);\r
+      }\r
+    }\r
+\r
+    if (OldStorage == NULL) {\r
+      //\r
+      // Storage is not found in backup formset, request it from ConfigDriver\r
+      //\r
+      Status = LoadStorage (FormSet, Storage);\r
+    } else {\r
+      //\r
+      // Storage found in backup formset, use it\r
+      //\r
+      Status = CopyStorage (Storage, OldStorage);\r
+    }\r
 \r
     //\r
     // Now Edit Buffer is filled with default values(lower priority) and current\r
@@ -2211,7 +2324,7 @@ GetIfrBinaryData (
     return Status;\r
   }\r
   ASSERT (HiiPackageList != NULL);\r
-  \r
+\r
   //\r
   // Get Form package from this HII package List\r
   //\r
@@ -2391,10 +2504,6 @@ InitializeFormSet (
         gFunctionOneString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
       }\r
 \r
-      if ((gFunctionKeySetting & FUNCTION_TWO) != FUNCTION_TWO) {\r
-        gFunctionTwoString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
-      }\r
-\r
       if ((gFunctionKeySetting & FUNCTION_NINE) != FUNCTION_NINE) {\r
         gFunctionNineString = GetToken (STRING_TOKEN (EMPTY_STRING), gHiiHandle);\r
       }\r