]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add example usage of EFI_BROWSER_ACTION_FORM_OPEN and EFI_BROWSER_ACTION_FORM_CLOSE...
authorxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Oct 2009 05:27:28 +0000 (05:27 +0000)
committerxdu2 <xdu2@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 26 Oct 2009 05:27:28 +0000 (05:27 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@9365 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf

index f74ae3e9594b20e69199e0ceaff8411cab6798d5..a3aa2511bce48121b3bf09b4cecc7af2c76a0684 100644 (file)
@@ -2,7 +2,7 @@
 This is an example of how a driver might export data to the HII protocol to be\r
 later utilized by the Setup Protocol\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation\r
+Copyright (c) 2004 - 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
@@ -43,7 +43,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath0 = {
   {\r
     END_DEVICE_PATH_TYPE,\r
     END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { \r
+    {\r
       (UINT8) (END_DEVICE_PATH_LENGTH),\r
       (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
     }\r
@@ -68,7 +68,7 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath1 = {
   {\r
     END_DEVICE_PATH_TYPE,\r
     END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
-    { \r
+    {\r
       (UINT8) (END_DEVICE_PATH_LENGTH),\r
       (UINT8) ((END_DEVICE_PATH_LENGTH) >> 8)\r
     }\r
@@ -77,10 +77,10 @@ HII_VENDOR_DEVICE_PATH  mHiiVendorDevicePath1 = {
 \r
 /**\r
   Encode the password using a simple algorithm.\r
-  \r
+\r
   @param Password The string to be encoded.\r
   @param MaxSize  The size of the string.\r
-  \r
+\r
 **/\r
 VOID\r
 EncodePassword (\r
@@ -111,10 +111,10 @@ EncodePassword (
 \r
 /**\r
   Validate the user's password.\r
-  \r
+\r
   @param PrivateData This driver's private context data.\r
   @param StringId    The user's input.\r
-  \r
+\r
   @retval EFI_SUCCESS   The user's input matches the password.\r
   @retval EFI_NOT_READY The user's input does not match the password.\r
 **/\r
@@ -204,13 +204,13 @@ ValidatePassword (
 \r
 /**\r
   Encode the password using a simple algorithm.\r
-  \r
+\r
   @param PrivateData This driver's private context data.\r
   @param StringId    The password from User.\r
-  \r
+\r
   @retval  EFI_SUCESS The operation is successful.\r
   @return  Other value if gRT->SetVariable () fails.\r
-  \r
+\r
 **/\r
 EFI_STATUS\r
 SetPassword (\r
@@ -244,9 +244,9 @@ SetPassword (
   // Get user input password\r
   //\r
   Password = &PrivateData->Configuration.WhatIsThePassword2[0];\r
-  PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2); \r
+  PasswordSize = sizeof (PrivateData->Configuration.WhatIsThePassword2);\r
   ZeroMem (Password, PasswordSize);\r
-  \r
+\r
   TempPassword = HiiGetString (PrivateData->HiiHandle[0], StringId, NULL);\r
   if (TempPassword == NULL) {\r
     return EFI_NOT_READY;\r
@@ -344,7 +344,7 @@ ExtractConfig (
   EFI_STRING                       ConfigRequest;\r
   EFI_STRING                       ConfigRequestHdr;\r
   UINTN                            Size;\r
-  \r
+\r
   if (Progress == NULL || Results == NULL || Request == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -374,14 +374,14 @@ ExtractConfig (
   if (EFI_ERROR (Status)) {\r
     return EFI_NOT_FOUND;\r
   }\r
-  \r
+\r
   if (Request == NULL) {\r
     //\r
     // Request is set to NULL, construct full request string.\r
     //\r
 \r
     //\r
-    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template \r
+    // Allocate and fill a buffer large enough to hold the <ConfigHdr> template\r
     // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator\r
     //\r
     ConfigRequestHdr = HiiConstructConfigHdr (&mFormSetGuid, VariableName, PrivateData->DriverHandle[0]);\r
@@ -411,7 +411,7 @@ ExtractConfig (
                                 Results,\r
                                 Progress\r
                                 );\r
-  \r
+\r
   if (Request == NULL) {\r
     FreePool (ConfigRequest);\r
     *Progress = NULL;\r
@@ -554,15 +554,76 @@ DriverCallback (
   EFI_IFR_GUID_LABEL              *StartLabel;\r
   VOID                            *EndOpCodeHandle;\r
   EFI_IFR_GUID_LABEL              *EndLabel;\r
+  EFI_INPUT_KEY                   Key;\r
+  DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
+\r
+  if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
+    //\r
+    // On FORM_OPEN event, update the form on-the-fly\r
+    //\r
+    PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
+\r
+    //\r
+    // Initialize the container for dynamic opcodes\r
+    //\r
+    StartOpCodeHandle = HiiAllocateOpCodeHandle ();\r
+    ASSERT (StartOpCodeHandle != NULL);\r
+\r
+    //\r
+    // Create Hii Extend Label OpCode as the start opcode\r
+    //\r
+    StartLabel = (EFI_IFR_GUID_LABEL *) HiiCreateGuidOpCode (StartOpCodeHandle, &gEfiIfrTianoGuid, NULL, sizeof (EFI_IFR_GUID_LABEL));\r
+    StartLabel->ExtendOpCode = EFI_IFR_EXTEND_OP_LABEL;\r
+    StartLabel->Number       = LABEL_UPDATE2;\r
+\r
+    HiiCreateActionOpCode (\r
+      StartOpCodeHandle,                // Container for dynamic created opcodes\r
+      0x1238,                           // Question ID\r
+      STRING_TOKEN(STR_SAVE_TEXT),      // Prompt text\r
+      STRING_TOKEN(STR_SAVE_TEXT),      // Help text\r
+      EFI_IFR_FLAG_CALLBACK,            // Question flag\r
+      0                                 // Action String ID\r
+    );\r
+\r
+    HiiUpdateForm (\r
+      PrivateData->HiiHandle[0],  // HII handle\r
+      &mFormSetGuid,              // Formset GUID\r
+      0x3,                        // Form ID\r
+      StartOpCodeHandle,          // Label for where to insert opcodes\r
+      NULL                        // Insert data\r
+      );\r
+\r
+    HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (Action == EFI_BROWSER_ACTION_FORM_CLOSE) {\r
+    //\r
+    // On FORM_CLOSE event, show up a pop-up\r
+    //\r
+    do {\r
+      CreatePopUp (\r
+        EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
+        &Key,\r
+        L"",\r
+        L"You are going to leave the Form!",\r
+        L"Press ESC or ENTER to continue ...",\r
+        L"",\r
+        NULL\r
+        );\r
+    } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
+\r
+    return EFI_SUCCESS;\r
+  }\r
 \r
   if ((Value == NULL) || (ActionRequest == NULL)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-  \r
+\r
   if ((Type == EFI_IFR_TYPE_STRING) && (Value->string == 0)) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
-   \r
+\r
 \r
   Status = EFI_SUCCESS;\r
   PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This);\r
@@ -635,6 +696,28 @@ DriverCallback (
                     &PrivateData->Configuration\r
                     );\r
 \r
+    //\r
+    // Set initial vlaue of dynamic created oneof Question in Form Browser\r
+    //\r
+    Configuration = AllocateZeroPool (sizeof (DRIVER_SAMPLE_CONFIGURATION));\r
+    ASSERT (Configuration != NULL);\r
+    Status = HiiGetBrowserData (&mFormSetGuid, VariableName, sizeof (DRIVER_SAMPLE_CONFIGURATION), (UINT8 *) Configuration);\r
+    if (!EFI_ERROR (Status)) {\r
+      Configuration->DynamicOneof = 2;\r
+\r
+      //\r
+      // Update uncommitted data of Browser\r
+      //\r
+      HiiSetBrowserData (\r
+        &mFormSetGuid,\r
+        VariableName,\r
+        sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
+        (UINT8 *) Configuration,\r
+        NULL\r
+        );\r
+    }\r
+    FreePool (Configuration);\r
+\r
     HiiCreateOneOfOpCode (\r
       StartOpCodeHandle,                         // Container for dynamic created opcodes\r
       0x8001,                                    // Question ID (or call it "key")\r
@@ -682,8 +765,9 @@ DriverCallback (
 \r
     HiiFreeOpCodeHandle (StartOpCodeHandle);\r
     HiiFreeOpCodeHandle (OptionsOpCodeHandle);\r
+    HiiFreeOpCodeHandle (EndOpCodeHandle);\r
     break;\r
-    \r
+\r
   case 0x5678:\r
     //\r
     // We will reach here once the Question is refreshed\r
@@ -710,7 +794,7 @@ DriverCallback (
       EFI_IFR_FLAG_CALLBACK,            // Question flag\r
       0                                 // Action String ID\r
     );\r
-    \r
+\r
     HiiUpdateForm (\r
       PrivateData->HiiHandle[0],  // HII handle\r
       &mFormSetGuid,              // Formset GUID\r
@@ -719,8 +803,8 @@ DriverCallback (
       NULL                        // Insert data\r
       );\r
 \r
-    HiiFreeOpCodeHandle (StartOpCodeHandle); \r
-  \r
+    HiiFreeOpCodeHandle (StartOpCodeHandle);\r
+\r
     //\r
     // Refresh the Question value\r
     //\r
@@ -732,7 +816,7 @@ DriverCallback (
                     sizeof (DRIVER_SAMPLE_CONFIGURATION),\r
                     &PrivateData->Configuration\r
                     );\r
-  \r
+\r
     //\r
     // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause\r
     // the first statement in Form 3 be suppressed\r
@@ -795,7 +879,7 @@ DriverCallback (
 \r
 /**\r
   Main entry for this driver.\r
-  \r
+\r
   @param ImageHandle     Image handle this driver.\r
   @param SystemTable     Pointer to SystemTable.\r
 \r
@@ -820,8 +904,8 @@ DriverSampleInit (
   UINTN                           BufferSize;\r
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;\r
   BOOLEAN                         ActionFlag;\r
-  EFI_STRING                      ConfigRequestHdr;  \r
-  \r
+  EFI_STRING                      ConfigRequestHdr;\r
+\r
   //\r
   // Initialize the local variables.\r
   //\r
@@ -990,18 +1074,18 @@ DriverSampleInit (
     ActionFlag = HiiValidateSettings (ConfigRequestHdr);\r
     ASSERT (ActionFlag);\r
   }\r
-  \r
+\r
   FreePool (ConfigRequestHdr);\r
 \r
 \r
   //\r
-  // In default, this driver is built into Flash device image, \r
+  // In default, this driver is built into Flash device image,\r
   // the following code doesn't run.\r
   //\r
 \r
   //\r
   // Example of how to display only the item we sent to HII\r
-  // When this driver is not built into Flash device image, \r
+  // When this driver is not built into Flash device image,\r
   // it need to call SendForm to show front page by itself.\r
   //\r
   if (DISPLAY_ONLY_MY_ITEM <= 1) {\r
@@ -1017,9 +1101,9 @@ DriverSampleInit (
                              NULL,\r
                              NULL\r
                              );\r
-  \r
+\r
     HiiRemovePackages (HiiHandle[0]);\r
-  \r
+\r
     HiiRemovePackages (HiiHandle[1]);\r
   }\r
 \r
index f9a5324b7c16fa5aebdae0b757344e81a31c11bc..ebe40a2948efe27e14f666f1d5eb5da8a25ddbe8 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-Copyright (c) 2007, 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
@@ -43,6 +43,7 @@ Revision History
 #include <Library/HiiLib.h>\r
 #include <Library/DevicePathLib.h>\r
 #include <Library/PrintLib.h>\r
+#include <Library/UefiLib.h>\r
 \r
 #include "NVDataStruc.h"\r
 \r
index b70968db4c5f44f50253e920e65e34dc03d15ccd..86613e937d732fce9238ec255dad8c86fecaa411 100644 (file)
@@ -2,7 +2,7 @@
 # This is a sample driver which show how HII protocol, VFR and UNI files are used to\r
 # create a driver which can be dipslayed and configured by a UEFI HII Form Browser.\r
 #\r
-# Copyright (c) 2007 - 2008, Intel Corporation. All rights reserved.\r
+# Copyright (c) 2007 - 2009, Intel Corporation. All rights reserved.\r
 #\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
@@ -55,6 +55,7 @@
   DebugLib\r
   HiiLib\r
   PrintLib\r
+  UefiLib\r
 \r
 [Guids]\r
   gEfiIfrTianoGuid                              ## CONSUMES ## Guid\r