[edk2] [PATCH V4 3/3] MdeModulePkg/DriverSample: Add sample case for popup protocol

Dandan Bi posted 3 patches 7 years, 4 months ago
There is a newer version of this series
[edk2] [PATCH V4 3/3] MdeModulePkg/DriverSample: Add sample case for popup protocol
Posted by Dandan Bi 7 years, 4 months ago
Add one sample case about how to use HiiPopup protocol to draw message box.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
---
 .../Universal/DriverSampleDxe/DriverSample.c       | 29 ++++++++++++++++++++++
 .../Universal/DriverSampleDxe/DriverSample.h       |  4 ++-
 .../Universal/DriverSampleDxe/DriverSampleDxe.inf  |  3 ++-
 MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr     | 10 ++++++--
 .../Universal/DriverSampleDxe/VfrStrings.uni       |  8 +++++-
 5 files changed, 49 insertions(+), 5 deletions(-)

diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
index f103b9c..bbd9713 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c
@@ -1098,10 +1098,13 @@ DriverCallback (
   EFI_STRING                      Results;
   UINT32                          ProgressErr;
   CHAR16                          *TmpStr;
   UINTN                           Index;
   UINT64                          BufferValue;
+  EFI_HII_POPUP_SELECTION         UserSelection;
+
+  UserSelection = 0xFF;
 
   if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))||
     (ActionRequest == NULL)) {
     return EFI_INVALID_PARAMETER;
   }
@@ -1617,10 +1620,26 @@ DriverCallback (
           Status = EFI_SUCCESS;
           break;
         }
         break;
 
+      case 0x1330:
+        Status = mPrivateData->HiiPopup->CreatePopup (
+          mPrivateData->HiiPopup,
+          EfiHiiPopupStyleInfo,
+          EfiHiiPopupTypeYesNo,
+          mPrivateData->HiiHandle[0],
+          STRING_TOKEN (STR_POPUP_STRING),
+          &UserSelection
+          );
+        if (!EFI_ERROR (Status)) {
+          if (UserSelection == EfiHiiPopupSelectionYes) {
+            *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
+          }
+        }
+        break;
+
       default:
       break;
     }
   break;
 
@@ -1676,10 +1695,11 @@ DriverSampleInit (
   EFI_HII_DATABASE_PROTOCOL       *HiiDatabase;
   EFI_HII_STRING_PROTOCOL         *HiiString;
   EFI_FORM_BROWSER2_PROTOCOL      *FormBrowser2;
   EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting;
   EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;
+  EFI_HII_POPUP_PROTOCOL              *PopupHandler;
   CHAR16                          *NewString;
   UINTN                           BufferSize;
   DRIVER_SAMPLE_CONFIGURATION     *Configuration;
   BOOLEAN                         ActionFlag;
   EFI_STRING                      ConfigRequestHdr;
@@ -1761,10 +1781,19 @@ DriverSampleInit (
   if (EFI_ERROR (Status)) {
     return Status;
   }
   mPrivateData->HiiKeywordHandler = HiiKeywordHandler;
 
+  //
+  // Locate HiiPopup protocol
+  //
+  Status = gBS->LocateProtocol (&gEfiHiiPopupProtocolGuid, NULL, (VOID **) &PopupHandler);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  mPrivateData->HiiPopup = PopupHandler;
+
   Status = gBS->InstallMultipleProtocolInterfaces (
                   &DriverHandle[0],
                   &gEfiDevicePathProtocolGuid,
                   &mHiiVendorDevicePath0,
                   &gEfiHiiConfigAccessProtocolGuid,
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
index 6c97239..507cff6 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h
@@ -1,8 +1,8 @@
 /** @file
 
-Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
@@ -31,10 +31,11 @@ Revision History
 #include <Protocol/HiiConfigAccess.h>
 #include <Protocol/HiiDatabase.h>
 #include <Protocol/HiiString.h>
 #include <Protocol/FormBrowserEx.h>
 #include <Protocol/HiiConfigKeyword.h>
+#include <Protocol/HiiPopup.h>
 
 #include <Guid/MdeModuleHii.h>
 #include <Library/DebugLib.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
@@ -96,10 +97,11 @@ typedef struct {
   //
   EFI_HII_DATABASE_PROTOCOL        *HiiDatabase;
   EFI_HII_STRING_PROTOCOL          *HiiString;
   EFI_HII_CONFIG_ROUTING_PROTOCOL  *HiiConfigRouting;
   EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler;
+  EFI_HII_POPUP_PROTOCOL              *HiiPopup;
 
   EFI_FORM_BROWSER2_PROTOCOL       *FormBrowser2;
 
   //
   // Produced protocol
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
index 4233e63..bfd7484 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
+++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
@@ -2,11 +2,11 @@
 # This is a sample HII driver. 
 #
 # This driver shows how HII protocol, VFR and UNI files are used to create a HII 
 # driver which can be dipslayed and configured by a UEFI HII Form Browser.
 #
-# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 #
 #  This program and the accompanying materials
 #  are licensed and made available under the terms and conditions of the BSD License
 #  which accompanies this distribution. The full text of the license may be found at
 #  http://opensource.org/licenses/bsd-license.php
@@ -91,10 +91,11 @@
   gEfiFormBrowser2ProtocolGuid                  ## CONSUMES
   gEfiHiiDatabaseProtocolGuid                   ## CONSUMES
   gEfiSimpleTextInputExProtocolGuid             ## SOMETIMES_CONSUMES
   gEdkiiFormBrowserExProtocolGuid               ## CONSUMES
   gEfiConfigKeywordHandlerProtocolGuid          ## CONSUMES
+  gEfiHiiPopupProtocolGuid                      ## CONSUMES
 
 [Depex]
   gEfiSimpleTextOutProtocolGuid AND gEfiHiiDatabaseProtocolGuid AND gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid
 
 [UserExtensions.TianoCore."ExtraFiles"]
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
index 4bdaf76..d547ec8 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
+++ b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr
@@ -1,10 +1,10 @@
 ///** @file
 //
 //    Sample Setup formset.
 //
-//  Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>
+//  Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>
 //  This program and the accompanying materials
 //  are licensed and made available under the terms and conditions of the BSD License
 //  which accompanies this distribution.  The full text of the license may be found at
 //  http://opensource.org/licenses/bsd-license.php
 //
@@ -474,11 +474,17 @@ formset
             flags   = INTERACTIVE,
             minimum = 0,
             maximum = 255,
             default = 18,
     endnumeric;
-    
+
+    text
+      help  = STRING_TOKEN(STR_POPUP_TEST_HELP),
+      text  = STRING_TOKEN(STR_POPUP_TEST_PROMPT),
+      flags = INTERACTIVE,
+      key   = 0x1330;
+
     goto 2,
       prompt = STRING_TOKEN(STR_GOTO_FORM2), //SecondSetupPage  // this too has no end-op and basically it's a jump to a form ONLY
       help   = STRING_TOKEN(STR_GOTO_HELP);
 
     goto 3,
diff --git a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
index 8d24a47..6a268d1 100644
--- a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
+++ b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni
@@ -1,8 +1,8 @@
 // *++
 	//
-// Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+// Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
 // This program and the accompanying materials                          
 // are licensed and made available under the terms and conditions of the BSD License         
 // which accompanies this distribution.  The full text of the license may be found at        
 // http://opensource.org/licenses/bsd-license.php                                            
 //                                                                                           
@@ -265,10 +265,16 @@
                                                      #language fr-FR ""                                                                                                           
 #string STR_SUBMITTED_CALLBACK_TEST_PROMPT           #language en-US "Submitted callback test"
                                                      #language fr-FR "Submitted callback test"
 #string STR_SUBMITTED_CALLBACK_TEST_HELP             #language en-US "Change the value and press F10 to submmit will pop up a dialogue to show SUBMITTED Callback has been triggered"
                                                      #language fr-FR "Change the value and press F10 to submmit will pop up a dialogue to show SUBMITTED Callback has been triggered"
+#string STR_POPUP_TEST_PROMPT                        #language en-US "Select it to invoke Hii Popup Protocol"
+                                                     #language fr-FR "Select it to invoke Hii Popup Protocol"
+#string STR_POPUP_TEST_HELP                          #language en-US "Select this question will pop up a message box, then user can decide whether exit curret form or not"
+                                                     #language fr-FR "Select this question will pop up a message box, then user can decide whether exit curret form or not"
+#string STR_POPUP_STRING                             #language en-US "Are you sure to exit current form?"
+                                                     #language fr-FR "Are you sure to exit current form?"
 // Boot Order
 #string STR_BOOT_TITLE                 #language en-US "Boot"
 #string STR_BOOT_OPTIONS               #language en-US "Boot Order"
 #string STR_BOOT_OPTION1               #language en-US "IDE HDD"
 #string STR_BOOT_OPTION2               #language en-US "ATAPI CD"
-- 
1.9.5.msysgit.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel