/** @file
This library class defines a set of interfaces to customize Ui module
Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PrintLib.h>
#include <Library/BaseMemoryLib.h>
#include "FrontPage.h"
#include "FrontPageCustomizedUiSupport.h"
#include <Library/PrintTestBaseLib.h>
#include <Library/HiiLib.h>
EFI_GUID FORMSET_GUID = { 0x9e0c30bc, 0x3f06, 0x4ba6, 0x82, 0x88, 0x9, 0x17, 0x9b, 0x85, 0x5d, 0xbe };
extern FRONT_PAGE_CALLBACK_DATA gFrontPagePrivate;
/*
Customize Set Variable
*/
typedef struct {
UINT8 ShowTest;
UINT8 FeatureEnabled;
} MY_VARSTORE;
MY_VARSTORE MyVarStore = {0, 0}; // Initialize with default values
// Forward declaration
EFI_STATUS
UpdateFormVariable (
IN EFI_HII_HANDLE HiiHandle,
IN UINT16 QuestionId,
IN UINT8 Value
);
VOID
CreateDynamicControls(IN EFI_HII_HANDLE HiiHandle);
/**
Customize menus in the page.
@param[in] HiiHandle The HII Handle of the form to update.
@param[in] StartOpCodeHandle The context used to insert opcode.
@param[in] CustomizePageType The page type need to be customized.
**/
VOID
UiCustomizeFrontPage (
IN EFI_HII_HANDLE HiiHandle,
IN VOID *StartOpCodeHandle
)
{
//
// Create "Select Language" menu with Oneof opcode.
//
UiCreateLanguageMenu (HiiHandle, StartOpCodeHandle);
//
// Create empty line.
//
UiCreateEmptyLine (HiiHandle, StartOpCodeHandle);
//
// Find third party drivers which need to be shown in the front page.
//
UiListThirdPartyDrivers (HiiHandle, &gEfiIfrFrontPageGuid, NULL, StartOpCodeHandle);
//
// Create empty line.
//
UiCreateEmptyLine (HiiHandle, StartOpCodeHandle);
//
// Create "Continue" menu.
//
UiCreateContinueMenu (HiiHandle, StartOpCodeHandle);
//
// Create reset menu.
//
UiCreateResetMenu (HiiHandle, StartOpCodeHandle);
// Create initial dynamic controls based on current variable values
CreateDynamicControls(HiiHandle);
}
/**
This function processes the results of changes in configuration.
@param HiiHandle Points to the hii handle for this formset.
@param Action Specifies the type of action taken by the browser.
@param QuestionId A unique value which is sent to the original exporting driver
so that it can identify the type of data to expect.
@param Type The type of value for the question.
@param Value A pointer to the data being sent to the original exporting driver.
@param ActionRequest On return, points to the action requested by the callback function.
@retval EFI_SUCCESS The callback successfully handled the action.
@retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the variable and its data.
@retval EFI_DEVICE_ERROR The variable could not be saved.
@retval EFI_UNSUPPORTED The specified Action is not supported by the callback.
**/
EFI_STATUS
UiFrontPageCallbackHandler (
IN EFI_HII_HANDLE HiiHandle,
IN EFI_BROWSER_ACTION Action,
IN EFI_QUESTION_ID QuestionId,
IN UINT8 Type,
IN EFI_IFR_TYPE_VALUE *Value,
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
)
{
EFI_STATUS Status;
// Handle ShowTest checkbox changes (QuestionId = 0x2000)
if (QuestionId == 0x2000) {
if (Action == EFI_BROWSER_ACTION_CHANGING) {
return EFI_SUCCESS;
} else if (Action == EFI_BROWSER_ACTION_CHANGED) {
// Update value in memory directly, no need to save to NVRAM
MyVarStore.ShowTest = Value->u8;
Print(L"\nShowTest changed to: %d\n", Value->u8);
// Recreate dynamic controls
CreateDynamicControls(HiiHandle);
Print(L"Dynamic controls recreated\n");
}
}
// Handle FeatureEnabled checkbox changes (QuestionId = 0x1000)
if (QuestionId == 0x1000) {
if (Action == EFI_BROWSER_ACTION_CHANGING) {
return EFI_SUCCESS;
} else if (Action == EFI_BROWSER_ACTION_CHANGED) {
// Update value in memory directly, no need to save to NVRAM
MyVarStore.FeatureEnabled = Value->u8;
Print(L"\nFeatureEnabled changed to: %d\n", Value->u8);
// Recreate dynamic controls
CreateDynamicControls(HiiHandle);
Print(L"Dynamic controls recreated after FeatureEnabled change\n");
return EFI_SUCCESS;
}
}
if (UiSupportLibCallbackHandler (HiiHandle, Action, QuestionId, Type, Value, ActionRequest, &Status)) {
return Status;
}
return EFI_UNSUPPORTED;
}
/**
Update the banner string in the front page.
Current layout for the banner string like below:
PS: Totally only 5 lines of banner supported.
Line 1: Left BannerStr RightBannerStr
Line 2: Left BannerStr RightBannerStr
Line 3: Left BannerStr RightBannerStr
Line 4: Left BannerStr RightBannerStr
Line 5: Left BannerStr RightBannerStr
<EmptyLine>
First menu in front page.
...
@param LineIndex The line index of the banner need to check.
@param LeftOrRight The left or right banner need to check.
@param BannerStr Banner string need to update.
Input the current string and user can update
it and return the new string.
**/
VOID
UiCustomizeFrontPageBanner (
IN UINTN LineIndex,
IN BOOLEAN LeftOrRight,
IN OUT EFI_STRING *BannerStr
)
{
// Temporarily disable banner update functionality as related PCDs and strings are not defined
// If this functionality is needed, the corresponding PCDs and strings should be defined first
return;
}
/**
Create dynamic controls based on current variable values in memory
**/
VOID
CreateDynamicControls(IN EFI_HII_HANDLE HiiHandle)
{
VOID *StartOp = HiiAllocateOpCodeHandle();
VOID *EndOp = HiiAllocateOpCodeHandle();
if (StartOp == NULL || EndOp == NULL) {
Print(L"Failed to allocate opcode handles\n");
return;
}
// Use variable values directly from memory, no need to read from NVRAM
UINT16 VarStoreId = 0; // Use 0 as default VarStore ID
Print(L"Using default VarStore ID: %d\n", VarStoreId);
Print(L"Creating dynamic controls based on ShowTest=%d, FeatureEnabled=%d\n",
MyVarStore.ShowTest, MyVarStore.FeatureEnabled);
// Create FeatureEnabled checkbox only if ShowTest != 0
if (MyVarStore.ShowTest != 0) {
Print(L"Creating FeatureEnabled checkbox\n");
// Create FeatureEnabled checkbox
HiiCreateCheckBoxOpCode(
StartOp,
0x1000, // QuestionId
VarStoreId, // VarStoreId
OFFSET_OF(MY_VARSTORE, FeatureEnabled), // VarStoreOffset
0, // Prompt (will use default)
0, // Help (will use default)
EFI_IFR_FLAG_CALLBACK, // Flags
0, // CheckBoxFlags
0 // DefaultId
);
// Create PowerOnTime text only if FeatureEnabled != 0
if (MyVarStore.FeatureEnabled != 0) {
Print(L"Creating PowerOnTime text\n");
HiiCreateTextOpCode(
StartOp,
0, // Text (will use default)
0, // Help (will use default)
0 // Flags
);
}
}
HiiCreateEndOpCode(EndOp);
// Insert into form at LABEL_FRONTPAGE_INFORMATION
EFI_STATUS Status = HiiUpdateForm(
HiiHandle,
&FORMSET_GUID,
0x1000, // Form ID
StartOp,
EndOp
);
if (EFI_ERROR(Status)) {
Print(L"Failed to update form, Status: 0x%x\n", Status);
} else {
Print(L"Dynamic controls created successfully\n");
}
HiiFreeOpCodeHandle(StartOp);
HiiFreeOpCodeHandle(EndOp);
}
/**
Update form variable in memory only (no persistence)
**/
EFI_STATUS
UpdateFormVariable (
IN EFI_HII_HANDLE HiiHandle,
IN UINT16 QuestionId,
IN UINT8 Value
)
{
// Only update the variable structure in memory, do not save to NVRAM
if (QuestionId == 0x1000) {
MyVarStore.FeatureEnabled = Value;
} else if (QuestionId == 0x2000) {
MyVarStore.ShowTest = Value;
}
Print(L"Form variable updated in memory: QuestionId=0x%x, Value=%d\n", QuestionId, Value);
return EFI_SUCCESS;
}
最新发布