Update Browser to provide the customization possibilities.

Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>

MdeModulePkg Patch
Tested-by: Laszlo Ersek <lersek@redhat.com>

OvmfPkg Patch  
Tested-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com> 


git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14537 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Eric Dong
2013-08-09 05:26:47 +00:00
committed by ydong10
parent 301c867b27
commit b9feb4bdf2
39 changed files with 12446 additions and 9017 deletions

View File

@@ -0,0 +1,44 @@
/** @file
MACRO definitions for color used in Setup Browser.
Copyright (c) 2004 - 2011, 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
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
//
// Unicode collation protocol in
#ifndef _COLORS_H_
#define _COLORS_H_
//
// Screen Color Settings
//
#define PICKLIST_HIGHLIGHT_TEXT EFI_WHITE
#define PICKLIST_HIGHLIGHT_BACKGROUND EFI_BACKGROUND_CYAN
#define TITLE_TEXT EFI_WHITE
#define TITLE_BACKGROUND EFI_BACKGROUND_BLUE
#define KEYHELP_TEXT EFI_LIGHTGRAY
#define KEYHELP_BACKGROUND EFI_BACKGROUND_BLACK
#define SUBTITLE_BACKGROUND EFI_BACKGROUND_LIGHTGRAY
#define BANNER_TEXT EFI_BLUE
#define BANNER_BACKGROUND EFI_BACKGROUND_LIGHTGRAY
#define FIELD_TEXT_GRAYED EFI_DARKGRAY
#define FIELD_BACKGROUND EFI_BACKGROUND_LIGHTGRAY
#define POPUP_TEXT EFI_LIGHTGRAY
#define POPUP_BACKGROUND EFI_BACKGROUND_BLUE
#define POPUP_INVERSE_TEXT EFI_LIGHTGRAY
#define POPUP_INVERSE_BACKGROUND EFI_BACKGROUND_BLACK
#define HELP_TEXT EFI_BLUE
#define ERROR_TEXT EFI_RED | EFI_BRIGHT
#define INFO_TEXT EFI_YELLOW | EFI_BRIGHT
#define ARROW_TEXT EFI_RED | EFI_BRIGHT
#define ARROW_BACKGROUND EFI_BACKGROUND_LIGHTGRAY
#endif

View File

@@ -0,0 +1,921 @@
/** @file
This library class defines a set of interfaces to customize Display module
Copyright (c) 2013, 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 that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "CustomizedDisplayLibInternal.h"
EFI_GUID gCustomizedDisplayLibGuid = { 0x99fdc8fd, 0x849b, 0x4eba, { 0xad, 0x13, 0xfb, 0x96, 0x99, 0xc9, 0xa, 0x4d } };
EFI_HII_HANDLE mCDLStringPackHandle;
UINT16 gClassOfVfr; // Formset class information
BOOLEAN gLibIsFirstForm = TRUE;
BANNER_DATA *gBannerData;
UINTN gFooterHeight;
/**
+------------------------------------------------------------------------------+
| Setup Page |
+------------------------------------------------------------------------------+
Statement
Statement
Statement
+------------------------------------------------------------------------------+
| F9=Reset to Defaults F10=Save |
| ^"=Move Highlight <Spacebar> Toggles Checkbox Esc=Exit |
+------------------------------------------------------------------------------+
StatusBar
**/
/**
This funtion defines Page Frame and Backgroud.
Based on the above layout, it will be responsible for HeaderHeight, FooterHeight,
StatusBarHeight and Backgroud. And, it will reserve Screen for Statement.
@param[in] FormData Form Data to be shown in Page.
@param[out] ScreenForStatement Screen to be used for Statement. (Prompt, Value and Help)
@return Status
**/
EFI_STATUS
EFIAPI
DisplayPageFrame (
IN FORM_DISPLAY_ENGINE_FORM *FormData,
OUT EFI_SCREEN_DESCRIPTOR *ScreenForStatement
)
{
EFI_STATUS Status;
ASSERT (FormData != NULL && ScreenForStatement != NULL);
if (FormData == NULL || ScreenForStatement == NULL) {
return EFI_INVALID_PARAMETER;
}
Status = ScreenDiemensionInfoValidate (FormData);
if (EFI_ERROR (Status)) {
return Status;
}
gClassOfVfr = FORMSET_CLASS_PLATFORM_SETUP;
ProcessExternedOpcode(FormData);
//
// Calculate the ScreenForStatement.
//
ScreenForStatement->BottomRow = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight;
if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
ScreenForStatement->TopRow = gScreenDimensions.TopRow + FRONT_PAGE_HEADER_HEIGHT;
} else {
ScreenForStatement->TopRow = gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT;
}
ScreenForStatement->LeftColumn = gScreenDimensions.LeftColumn;
ScreenForStatement->RightColumn = gScreenDimensions.RightColumn;
if ((gLibIsFirstForm) || ((FormData->Attribute & HII_DISPLAY_MODAL) != 0)) {
//
// Ensure we are in Text mode
//
gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
ClearLines (0, gScreenDimensions.RightColumn, 0, gScreenDimensions.BottomRow, KEYHELP_BACKGROUND);
gLibIsFirstForm = FALSE;
}
//
// Don't print frame for modal form.
//
if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
return EFI_SUCCESS;
}
if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
PrintBannerInfo (FormData);
}
PrintFramework (FormData);
UpdateStatusBar(NV_UPDATE_REQUIRED, FormData->SettingChangedFlag);
return EFI_SUCCESS;
}
/**
This function updates customized key panel's help information.
The library will prepare those Strings for the basic key, ESC, Enter, Up/Down/Left/Right, +/-.
and arrange them in Footer panel.
@param[in] FormData Form Data to be shown in Page. FormData has the highlighted statement.
@param[in] Statement The statement current selected.
@param[in] Selected Whether or not a tag be selected. TRUE means Enter has hit this question.
**/
VOID
EFIAPI
RefreshKeyHelp (
IN FORM_DISPLAY_ENGINE_FORM *FormData,
IN FORM_DISPLAY_ENGINE_STATEMENT *Statement,
IN BOOLEAN Selected
)
{
UINTN SecCol;
UINTN ThdCol;
UINTN LeftColumnOfHelp;
UINTN RightColumnOfHelp;
UINTN TopRowOfHelp;
UINTN BottomRowOfHelp;
UINTN StartColumnOfHelp;
EFI_IFR_NUMERIC *NumericOp;
EFI_IFR_DATE *DateOp;
EFI_IFR_TIME *TimeOp;
BOOLEAN HexDisplay;
ASSERT (FormData != NULL);
if (FormData == NULL) {
return;
}
gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_TEXT | KEYHELP_BACKGROUND);
if ((FormData->Attribute & HII_DISPLAY_MODAL) != 0) {
return;
}
SecCol = gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3;
ThdCol = gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3 * 2;
StartColumnOfHelp = gScreenDimensions.LeftColumn + 2;
LeftColumnOfHelp = gScreenDimensions.LeftColumn + 1;
RightColumnOfHelp = gScreenDimensions.RightColumn - 2;
TopRowOfHelp = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1;
BottomRowOfHelp = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 2;
ClearLines (LeftColumnOfHelp, RightColumnOfHelp, TopRowOfHelp, BottomRowOfHelp, KEYHELP_TEXT | KEYHELP_BACKGROUND);
if (Statement == NULL) {
//
// Print Key for Form without showable statement.
//
PrintHotKeyHelpString (FormData);
PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
return;
}
HexDisplay = FALSE;
NumericOp = NULL;
DateOp = NULL;
TimeOp = NULL;
if (Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP) {
NumericOp = (EFI_IFR_NUMERIC *) Statement->OpCode;
HexDisplay = (NumericOp->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX;
} else if (Statement->OpCode->OpCode == EFI_IFR_DATE_OP) {
DateOp = (EFI_IFR_DATE *) Statement->OpCode;
HexDisplay = (DateOp->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX;
} else if (Statement->OpCode->OpCode == EFI_IFR_TIME_OP) {
TimeOp = (EFI_IFR_TIME *) Statement->OpCode;
HexDisplay = (TimeOp->Flags & EFI_IFR_DISPLAY_UINT_HEX) == EFI_IFR_DISPLAY_UINT_HEX;
}
switch (Statement->OpCode->OpCode) {
case EFI_IFR_ORDERED_LIST_OP:
case EFI_IFR_ONE_OF_OP:
case EFI_IFR_NUMERIC_OP:
case EFI_IFR_TIME_OP:
case EFI_IFR_DATE_OP:
if (!Selected) {
PrintHotKeyHelpString (FormData);
if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
}
if ((Statement->OpCode->OpCode == EFI_IFR_DATE_OP) ||
(Statement->OpCode->OpCode == EFI_IFR_TIME_OP)) {
PrintAt (
0,
StartColumnOfHelp,
BottomRowOfHelp,
L"%c%c%c%c%s",
ARROW_UP,
ARROW_DOWN,
ARROW_RIGHT,
ARROW_LEFT,
gMoveHighlight
);
PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber);
} else {
PrintAt (0, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
if (Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP && NumericOp != NULL && LibGetFieldFromNum(Statement->OpCode) != 0) {
PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gAdjustNumber);
}
PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
}
} else {
PrintStringAt (SecCol, BottomRowOfHelp, gEnterCommitString);
//
// If it is a selected numeric with manual input, display different message
//
if ((Statement->OpCode->OpCode == EFI_IFR_NUMERIC_OP) ||
(Statement->OpCode->OpCode == EFI_IFR_DATE_OP) ||
(Statement->OpCode->OpCode == EFI_IFR_TIME_OP)) {
PrintStringAt (
SecCol,
TopRowOfHelp,
HexDisplay ? gHexNumericInput : gDecNumericInput
);
} else if (Statement->OpCode->OpCode != EFI_IFR_ORDERED_LIST_OP) {
PrintAt (0, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
}
if (Statement->OpCode->OpCode == EFI_IFR_ORDERED_LIST_OP) {
PrintStringAt (StartColumnOfHelp, TopRowOfHelp, gPlusString);
PrintStringAt (ThdCol, TopRowOfHelp, gMinusString);
}
PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
}
break;
case EFI_IFR_CHECKBOX_OP:
PrintHotKeyHelpString (FormData);
if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
}
PrintAt (0, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
PrintStringAt (SecCol, BottomRowOfHelp, gToggleCheckBox);
break;
case EFI_IFR_REF_OP:
case EFI_IFR_PASSWORD_OP:
case EFI_IFR_STRING_OP:
case EFI_IFR_TEXT_OP:
case EFI_IFR_ACTION_OP:
case EFI_IFR_RESET_BUTTON_OP:
case EFI_IFR_SUBTITLE_OP:
if (!Selected) {
PrintHotKeyHelpString (FormData);
if (gClassOfVfr == FORMSET_CLASS_PLATFORM_SETUP) {
PrintStringAt (ThdCol, BottomRowOfHelp, gEscapeString);
}
PrintAt (0, StartColumnOfHelp, BottomRowOfHelp, L"%c%c%s", ARROW_UP, ARROW_DOWN, gMoveHighlight);
if (Statement->OpCode->OpCode != EFI_IFR_TEXT_OP && Statement->OpCode->OpCode != EFI_IFR_SUBTITLE_OP) {
PrintStringAt (SecCol, BottomRowOfHelp, gEnterString);
}
} else {
if (Statement->OpCode->OpCode != EFI_IFR_REF_OP) {
PrintStringAt (
(gScreenDimensions.RightColumn - LibGetStringWidth (gEnterCommitString) / 2) / 2,
BottomRowOfHelp,
gEnterCommitString
);
PrintStringAt (ThdCol, BottomRowOfHelp, gEnterEscapeString);
}
}
break;
default:
break;
}
}
/**
Update status bar.
This function updates the status bar on the bottom of menu screen. It just shows StatusBar.
Original logic in this function should be splitted out.
@param[in] MessageType The type of message to be shown. InputError or Configuration Changed.
@param[in] State Show or Clear Message.
**/
VOID
EFIAPI
UpdateStatusBar (
IN UINTN MessageType,
IN BOOLEAN State
)
{
UINTN Index;
CHAR16 OptionWidth;
OptionWidth = (CHAR16) ((gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3);
switch (MessageType) {
case INPUT_ERROR:
if (State) {
gST->ConOut->SetAttribute (gST->ConOut, ERROR_TEXT);
PrintStringAt (
gScreenDimensions.LeftColumn + OptionWidth,
gScreenDimensions.BottomRow - 1,
gInputErrorMessage
);
} else {
gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_BACKGROUND);
for (Index = 0; Index < (LibGetStringWidth (gInputErrorMessage) - 2) / 2; Index++) {
PrintStringAt (gScreenDimensions.LeftColumn + OptionWidth + Index, gScreenDimensions.BottomRow - 1, L" ");
}
}
break;
case NV_UPDATE_REQUIRED:
//
// Global setting support. Show configuration change on every form.
//
if (State) {
gST->ConOut->SetAttribute (gST->ConOut, INFO_TEXT);
PrintStringAt (
gScreenDimensions.LeftColumn + OptionWidth * 2,
gScreenDimensions.BottomRow - 1,
gNvUpdateMessage
);
} else {
gST->ConOut->SetAttribute (gST->ConOut, KEYHELP_BACKGROUND);
for (Index = 0; Index < (LibGetStringWidth (gNvUpdateMessage) - 2) / 2; Index++) {
PrintStringAt (
(gScreenDimensions.LeftColumn + OptionWidth * 2 + Index),
gScreenDimensions.BottomRow - 1,
L" "
);
}
}
break;
default:
break;
}
}
/**
Create popup window. It will replace CreateDialog().
This function draws OEM/Vendor specific pop up windows.
@param[out] Key User Input Key
@param ... String to be shown in Popup. The variable argument list is terminated by a NULL.
**/
VOID
EFIAPI
CreateDialog (
OUT EFI_INPUT_KEY *Key, OPTIONAL
...
)
{
VA_LIST Marker;
EFI_INPUT_KEY KeyValue;
EFI_STATUS Status;
UINTN LargestString;
UINTN LineNum;
UINTN Index;
UINTN Count;
CHAR16 Character;
UINTN Start;
UINTN End;
UINTN Top;
UINTN Bottom;
CHAR16 *String;
UINTN DimensionsWidth;
UINTN DimensionsHeight;
UINTN CurrentAttribute;
//
// If screen dimension info is not ready, get it from console.
//
if (gScreenDimensions.RightColumn == 0 || gScreenDimensions.BottomRow == 0) {
ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
gST->ConOut->QueryMode (
gST->ConOut,
gST->ConOut->Mode->Mode,
&gScreenDimensions.RightColumn,
&gScreenDimensions.BottomRow
);
}
DimensionsWidth = gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn;
DimensionsHeight = gScreenDimensions.BottomRow - gScreenDimensions.TopRow;
LargestString = 0;
LineNum = 0;
VA_START (Marker, Key);
while ((String = VA_ARG (Marker, CHAR16 *)) != NULL) {
LineNum ++;
if ((LibGetStringWidth (String) / 2) > LargestString) {
LargestString = (LibGetStringWidth (String) / 2);
}
}
VA_END (Marker);
if ((LargestString + 2) > DimensionsWidth) {
LargestString = DimensionsWidth - 2;
}
CurrentAttribute = gST->ConOut->Mode->Attribute;
gST->ConOut->EnableCursor (gST->ConOut, FALSE);
gST->ConOut->SetAttribute (gST->ConOut, GetPopupColor ());
//
// Subtract the PopUp width from total Columns, allow for one space extra on
// each end plus a border.
//
Start = (DimensionsWidth - LargestString - 2) / 2 + gScreenDimensions.LeftColumn + 1;
End = Start + LargestString + 1;
Top = ((DimensionsHeight - LineNum - 2) / 2) + gScreenDimensions.TopRow - 1;
Bottom = Top + LineNum + 2;
Character = BOXDRAW_DOWN_RIGHT;
PrintCharAt (Start, Top, Character);
Character = BOXDRAW_HORIZONTAL;
for (Index = Start; Index + 2 < End; Index++) {
PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
}
Character = BOXDRAW_DOWN_LEFT;
PrintCharAt ((UINTN)-1, (UINTN)-1, Character);
Character = BOXDRAW_VERTICAL;
Count = 0;
VA_START (Marker, Key);
for (Index = Top; Index + 2 < Bottom; Index++, Count++) {
String = VA_ARG (Marker, CHAR16*);
if (String[0] == CHAR_NULL) {
//
// Passing in a NULL results in a blank space
//
ClearLines (Start, End, Index + 1, Index + 1, GetPopupColor ());
} else if (String[0] == L' ') {
//
// Passing in a space results in the assumption that this is where typing will occur
//
ClearLines (Start + 1, End - 1, Index + 1, Index + 1, POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND);
PrintStringAt (
((DimensionsWidth - LibGetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,
Index + 1,
String + 1
);
} else {
//
// This will clear the background of the line - we never know who might have been
// here before us. This differs from the next clear in that it used the non-reverse
// video for normal printing.
//
ClearLines (Start, End, Index + 1, Index + 1, GetPopupColor ());
PrintStringAt (
((DimensionsWidth - LibGetStringWidth (String) / 2) / 2) + gScreenDimensions.LeftColumn + 1,
Index + 1,
String
);
}
gST->ConOut->SetAttribute (gST->ConOut, GetPopupColor ());
PrintCharAt (Start, Index + 1, Character);
PrintCharAt (End - 1, Index + 1, Character);
}
VA_END (Marker);
Character = BOXDRAW_UP_RIGHT;
PrintCharAt (Start, Bottom - 1, Character);
Character = BOXDRAW_HORIZONTAL;
for (Index = Start; Index + 2 < End; Index++) {
PrintCharAt ((UINTN)-1, (UINTN) -1, Character);
}
Character = BOXDRAW_UP_LEFT;
PrintCharAt ((UINTN)-1, (UINTN) -1, Character);
if (Key != NULL) {
Status = WaitForKeyStroke (&KeyValue);
ASSERT_EFI_ERROR (Status);
CopyMem (Key, &KeyValue, sizeof (EFI_INPUT_KEY));
}
gST->ConOut->SetAttribute (gST->ConOut, CurrentAttribute);
gST->ConOut->EnableCursor (gST->ConOut, TRUE);
}
/**
Confirm how to handle the changed data.
@return Action BROWSER_ACTION_SUBMIT, BROWSER_ACTION_DISCARD or other values.
**/
UINTN
EFIAPI
ConfirmDataChange (
VOID
)
{
CHAR16 YesResponse;
CHAR16 NoResponse;
EFI_INPUT_KEY Key;
gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);
YesResponse = gYesResponse[0];
NoResponse = gNoResponse[0];
//
// If NV flag is up, prompt user
//
do {
CreateDialog (&Key, gLibEmptyString, gSaveChanges, gAreYouSure, gLibEmptyString, NULL);
} while
(
(Key.ScanCode != SCAN_ESC) &&
((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (NoResponse | UPPER_LOWER_CASE_OFFSET)) &&
((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (YesResponse | UPPER_LOWER_CASE_OFFSET))
);
if (Key.ScanCode == SCAN_ESC) {
return BROWSER_ACTION_NONE;
} else if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (YesResponse | UPPER_LOWER_CASE_OFFSET)) {
return BROWSER_ACTION_SUBMIT;
} else {
return BROWSER_ACTION_DISCARD;
}
}
/**
OEM specifies whether Setup exits Page by ESC key.
This function customized the behavior that whether Setup exits Page so that
system able to boot when configuration is not changed.
@retval TRUE Exits FrontPage
@retval FALSE Don't exit FrontPage.
**/
BOOLEAN
EFIAPI
FormExitPolicy (
VOID
)
{
return gClassOfVfr == FORMSET_CLASS_FRONT_PAGE ? FALSE : TRUE;
}
/**
Set Timeout value for a ceratain Form to get user response.
This function allows to set timeout value on a ceratain form if necessary.
If timeout is not zero, the form will exit if user has no response in timeout.
@param[in] FormData Form Data to be shown in Page
@return 0 No timeout for this form.
@return > 0 Timeout value in 100 ns units.
**/
UINT64
EFIAPI
FormExitTimeout (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
return 0;
}
//
// Print Functions
//
/**
Prints a unicode string to the default console, at
the supplied cursor position, using L"%s" format.
@param Column The cursor position to print the string at. When it is -1, use current Position.
@param Row The cursor position to print the string at. When it is -1, use current Position.
@param String String pointer.
@return Length of string printed to the console
**/
UINTN
EFIAPI
PrintStringAt (
IN UINTN Column,
IN UINTN Row,
IN CHAR16 *String
)
{
return PrintAt (0, Column, Row, L"%s", String);
}
/**
Prints a unicode string to the default console, at
the supplied cursor position, using L"%s" format.
@param Column The cursor position to print the string at. When it is -1, use current Position.
@param Row The cursor position to print the string at. When it is -1, use current Position.
@param String String pointer.
@param Width Width for String.
@return Length of string printed to the console
**/
UINTN
EFIAPI
PrintStringAtWithWidth (
IN UINTN Column,
IN UINTN Row,
IN CHAR16 *String,
IN UINTN Width
)
{
return PrintAt (Width, Column, Row, L"%s", String);
}
/**
Prints a chracter to the default console, at
the supplied cursor position, using L"%c" format.
@param Column The cursor position to print the string at. When it is -1, use current Position.
@param Row The cursor position to print the string at. When it is -1, use current Position.
@param Character Character to print.
@return Length of string printed to the console.
**/
UINTN
EFIAPI
PrintCharAt (
IN UINTN Column,
IN UINTN Row,
CHAR16 Character
)
{
return PrintAt (0, Column, Row, L"%c", Character);
}
/**
Clear retangle with specified text attribute.
@param LeftColumn Left column of retangle.
@param RightColumn Right column of retangle.
@param TopRow Start row of retangle.
@param BottomRow End row of retangle.
@param TextAttribute The character foreground and background.
**/
VOID
EFIAPI
ClearLines (
IN UINTN LeftColumn,
IN UINTN RightColumn,
IN UINTN TopRow,
IN UINTN BottomRow,
IN UINTN TextAttribute
)
{
CHAR16 *Buffer;
UINTN Row;
//
// For now, allocate an arbitrarily long buffer
//
Buffer = AllocateZeroPool (0x10000);
ASSERT (Buffer != NULL);
//
// Set foreground and background as defined
//
gST->ConOut->SetAttribute (gST->ConOut, TextAttribute);
//
// Much faster to buffer the long string instead of print it a character at a time
//
LibSetUnicodeMem (Buffer, RightColumn - LeftColumn, L' ');
//
// Clear the desired area with the appropriate foreground/background
//
for (Row = TopRow; Row <= BottomRow; Row++) {
PrintStringAt (LeftColumn, Row, Buffer);
}
gST->ConOut->SetCursorPosition (gST->ConOut, LeftColumn, TopRow);
FreePool (Buffer);
}
//
// Color Setting Functions
//
/**
Get OEM/Vendor specific popup attribute colors.
@retval Byte code color setting for popup color.
**/
UINT8
EFIAPI
GetPopupColor (
VOID
)
{
return POPUP_TEXT | POPUP_BACKGROUND;
}
/**
Get OEM/Vendor specific popup attribute colors.
@retval Byte code color setting for popup inverse color.
**/
UINT8
EFIAPI
GetPopupInverseColor (
VOID
)
{
return POPUP_INVERSE_TEXT | POPUP_INVERSE_BACKGROUND;
}
/**
Get OEM/Vendor specific PickList color attribute.
@retval Byte code color setting for pick list color.
**/
UINT8
EFIAPI
GetPickListColor (
VOID
)
{
return PICKLIST_HIGHLIGHT_TEXT | PICKLIST_HIGHLIGHT_BACKGROUND;
}
/**
Get OEM/Vendor specific arrow color attribute.
@retval Byte code color setting for arrow color.
**/
UINT8
EFIAPI
GetArrowColor (
VOID
)
{
return ARROW_TEXT | ARROW_BACKGROUND;
}
/**
Get OEM/Vendor specific info text color attribute.
@retval Byte code color setting for info text color.
**/
UINT8
EFIAPI
GetInfoTextColor (
VOID
)
{
return INFO_TEXT | FIELD_BACKGROUND;
}
/**
Get OEM/Vendor specific help text color attribute.
@retval Byte code color setting for help text color.
**/
UINT8
EFIAPI
GetHelpTextColor (
VOID
)
{
return HELP_TEXT | FIELD_BACKGROUND;
}
/**
Get OEM/Vendor specific grayed out text color attribute.
@retval Byte code color setting for grayed out text color.
**/
UINT8
EFIAPI
GetGrayedTextColor (
VOID
)
{
return FIELD_TEXT_GRAYED | FIELD_BACKGROUND;
}
/**
Get OEM/Vendor specific highlighted text color attribute.
@retval Byte code color setting for highlight text color.
**/
UINT8
EFIAPI
GetHighlightTextColor (
VOID
)
{
return PcdGet8 (PcdBrowserFieldTextHighlightColor) | PcdGet8 (PcdBrowserFieldBackgroundHighlightColor);
}
/**
Get OEM/Vendor specific field text color attribute.
@retval Byte code color setting for field text color.
**/
UINT8
EFIAPI
GetFieldTextColor (
VOID
)
{
return PcdGet8 (PcdBrowserFieldTextColor) | FIELD_BACKGROUND;
}
/**
Get OEM/Vendor specific subtitle text color attribute.
@retval Byte code color setting for subtitle text color.
**/
UINT8
EFIAPI
GetSubTitleTextColor (
VOID
)
{
return PcdGet8 (PcdBrowserSubtitleTextColor) | FIELD_BACKGROUND;
}
/**
Clear Screen to the initial state.
**/
VOID
EFIAPI
ClearDisplayPage (
VOID
)
{
gST->ConOut->SetAttribute (gST->ConOut, EFI_TEXT_ATTR (EFI_LIGHTGRAY, EFI_BLACK));
gST->ConOut->ClearScreen (gST->ConOut);
gLibIsFirstForm = TRUE;
}
/**
Constructor of Customized Display Library Instance.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
**/
EFI_STATUS
EFIAPI
CustomizedDisplayLibConstructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
mCDLStringPackHandle = HiiAddPackages (&gCustomizedDisplayLibGuid, ImageHandle, CustomizedDisplayLibStrings, NULL);
ASSERT (mCDLStringPackHandle != NULL);
InitializeLibStrings();
return EFI_SUCCESS;
}
/**
Destructor of Customized Display Library Instance.
@param ImageHandle The firmware allocated handle for the EFI image.
@param SystemTable A pointer to the EFI System Table.
@retval EFI_SUCCESS The destructor completed successfully.
@retval Other value The destructor did not complete successfully.
**/
EFI_STATUS
EFIAPI
CustomizedDisplayLibDestructor (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
HiiRemovePackages(mCDLStringPackHandle);
FreeLibStrings ();
return EFI_SUCCESS;
}

View File

@@ -0,0 +1,74 @@
##
# This file contains an 'Intel Peripheral Driver' and is
# licensed for Intel CPUs and chipsets under the terms of your
# license agreement with Intel or your vendor. This file may
# be modified by the user, subject to additional terms of the
# license agreement
##
## @file
#
# General BDS defines and produce general interfaces for platform BDS driver including:
# 1) BDS boot policy interface;
# 2) BDS boot device connect interface;
# 3) BDS Misc interfaces for mainting boot variable, ouput string, etc.
#
# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
# This software and associated documentation (if any) is furnished
# under a license and may only be used or copied in accordance
# with the terms of the license. Except as permitted by such
# license, no part of this software or documentation may be
# reproduced, stored in a retrieval system, or transmitted in any
# form or by any means without the express written consent of
# Intel Corporation.
#
##
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = CustomizedDisplayLib
FILE_GUID = 80B92017-EC64-4923-938D-94FAEE85832E
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = CustomizedDisplayLib|DXE_DRIVER UEFI_APPLICATION
CONSTRUCTOR = CustomizedDisplayLibConstructor
DESTRUCTOR = CustomizedDisplayLibDestructor
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
[Sources]
CustomizedDisplayLib.c
Colors.h
CustomizedDisplayLibInternal.h
CustomizedDisplayLibInternal.c
CustomizedDisplayLib.uni
[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
[LibraryClasses]
MemoryAllocationLib
BaseLib
UefiBootServicesTableLib
UefiDriverEntryPoint
UefiRuntimeServicesTableLib
BaseMemoryLib
DebugLib
PrintLib
HiiLib
DevicePathLib
PcdLib
[Guids]
gEfiIfrTianoGuid
[Protocols]
[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdBrowserSubtitleTextColor ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdBrowserFieldTextColor ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdBrowserFieldTextHighlightColor ## CONSUMES
gEfiMdeModulePkgTokenSpaceGuid.PcdBrowserFieldBackgroundHighlightColor ## CONSUMES

View File

@@ -0,0 +1,914 @@
/** @file
This library class defines a set of interfaces to customize Display module
Copyright (c) 2013, 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 that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include "CustomizedDisplayLibInternal.h"
EFI_SCREEN_DESCRIPTOR gScreenDimensions;
CHAR16 *mLibUnknownString;
extern EFI_HII_HANDLE mCDLStringPackHandle;
CHAR16 *mSpaceBuffer;
#define SPACE_BUFFER_SIZE 1000
//
// Browser Global Strings
//
CHAR16 *gEnterString;
CHAR16 *gEnterCommitString;
CHAR16 *gEnterEscapeString;
CHAR16 *gEscapeString;
CHAR16 *gMoveHighlight;
CHAR16 *gDecNumericInput;
CHAR16 *gHexNumericInput;
CHAR16 *gToggleCheckBox;
CHAR16 *gLibEmptyString;
CHAR16 *gAreYouSure;
CHAR16 *gYesResponse;
CHAR16 *gNoResponse;
CHAR16 *gPlusString;
CHAR16 *gMinusString;
CHAR16 *gAdjustNumber;
CHAR16 *gSaveChanges;
CHAR16 *gNvUpdateMessage;
CHAR16 *gInputErrorMessage;
/**
Print banner info for front page.
@param[in] FormData Form Data to be shown in Page
**/
VOID
PrintBannerInfo (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
UINT8 Line;
UINT8 Alignment;
CHAR16 *StrFrontPageBanner;
UINT8 RowIdx;
UINT8 ColumnIdx;
//
// ClearLines(0, LocalScreen.RightColumn, 0, BANNER_HEIGHT-1, BANNER_TEXT | BANNER_BACKGROUND);
//
ClearLines (
gScreenDimensions.LeftColumn,
gScreenDimensions.RightColumn,
gScreenDimensions.TopRow,
FRONT_PAGE_HEADER_HEIGHT - 1 + gScreenDimensions.TopRow,
BANNER_TEXT | BANNER_BACKGROUND
);
//
// for (Line = 0; Line < BANNER_HEIGHT; Line++) {
//
for (Line = (UINT8) gScreenDimensions.TopRow; Line < BANNER_HEIGHT + (UINT8) gScreenDimensions.TopRow; Line++) {
//
// for (Alignment = 0; Alignment < BANNER_COLUMNS; Alignment++) {
//
for (Alignment = (UINT8) gScreenDimensions.LeftColumn;
Alignment < BANNER_COLUMNS + (UINT8) gScreenDimensions.LeftColumn;
Alignment++
) {
RowIdx = (UINT8) (Line - (UINT8) gScreenDimensions.TopRow);
ColumnIdx = (UINT8) (Alignment - (UINT8) gScreenDimensions.LeftColumn);
ASSERT (RowIdx < BANNER_HEIGHT && ColumnIdx < BANNER_COLUMNS);
if (gBannerData!= NULL && gBannerData->Banner[RowIdx][ColumnIdx] != 0x0000) {
StrFrontPageBanner = LibGetToken (gBannerData->Banner[RowIdx][ColumnIdx], FormData->HiiHandle);
} else {
continue;
}
switch (Alignment - gScreenDimensions.LeftColumn) {
case 0:
//
// Handle left column
//
PrintStringAt (gScreenDimensions.LeftColumn + BANNER_LEFT_COLUMN_INDENT, Line, StrFrontPageBanner);
break;
case 1:
//
// Handle center column
//
PrintStringAt (
gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) / 3,
Line,
StrFrontPageBanner
);
break;
case 2:
//
// Handle right column
//
PrintStringAt (
gScreenDimensions.LeftColumn + (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn) * 2 / 3,
Line,
StrFrontPageBanner
);
break;
}
FreePool (StrFrontPageBanner);
}
}
}
/**
Print framework and form title for a page.
@param[in] FormData Form Data to be shown in Page
**/
VOID
PrintFramework (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
UINTN Index;
CHAR16 Character;
CHAR16 *Buffer;
UINTN Row;
CHAR16 *TitleStr;
if (gClassOfVfr != FORMSET_CLASS_PLATFORM_SETUP) {
//
// Only Setup page needs Framework
//
ClearLines (
gScreenDimensions.LeftColumn,
gScreenDimensions.RightColumn,
gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight,
gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 1,
KEYHELP_TEXT | KEYHELP_BACKGROUND
);
return;
}
Buffer = AllocateZeroPool (0x10000);
ASSERT (Buffer != NULL);
Character = BOXDRAW_HORIZONTAL;
for (Index = 0; Index + 2 < (gScreenDimensions.RightColumn - gScreenDimensions.LeftColumn); Index++) {
Buffer[Index] = Character;
}
//
// Print Top border line
// +------------------------------------------------------------------------------+
// ? ?
// +------------------------------------------------------------------------------+
//
gST->ConOut->SetAttribute (gST->ConOut, TITLE_TEXT | TITLE_BACKGROUND);
Character = BOXDRAW_DOWN_RIGHT;
PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.TopRow, Character);
PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
Character = BOXDRAW_DOWN_LEFT;
PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
Character = BOXDRAW_VERTICAL;
for (Row = gScreenDimensions.TopRow + 1; Row <= gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 2; Row++) {
PrintCharAt (gScreenDimensions.LeftColumn, Row, Character);
PrintCharAt (gScreenDimensions.RightColumn - 1, Row, Character);
}
//
// Print Form Title
//
ClearLines (
gScreenDimensions.LeftColumn + 1,
gScreenDimensions.RightColumn - 1,
gScreenDimensions.TopRow + 1,
gScreenDimensions.TopRow + 1,
TITLE_TEXT | TITLE_BACKGROUND
);
TitleStr = LibGetToken (FormData->FormTitle, FormData->HiiHandle);
ASSERT (TitleStr != NULL);
PrintStringAt (
(gScreenDimensions.RightColumn + gScreenDimensions.LeftColumn - LibGetStringWidth (TitleStr) / 2) / 2,
gScreenDimensions.TopRow + 1,
TitleStr
);
FreePool (TitleStr);
Character = BOXDRAW_UP_RIGHT;
PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.TopRow + NONE_FRONT_PAGE_HEADER_HEIGHT - 1, Character);
PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
Character = BOXDRAW_UP_LEFT;
PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
//
// Print Bottom border line
// +------------------------------------------------------------------------------+
// ? ?
// +------------------------------------------------------------------------------+
//
Character = BOXDRAW_DOWN_RIGHT;
PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight, Character);
PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
Character = BOXDRAW_DOWN_LEFT;
PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
Character = BOXDRAW_VERTICAL;
for (Row = gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - gFooterHeight + 1;
Row <= gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 2;
Row++
) {
PrintCharAt (gScreenDimensions.LeftColumn, Row, Character);
PrintCharAt (gScreenDimensions.RightColumn - 1, Row, Character);
}
Character = BOXDRAW_UP_RIGHT;
PrintCharAt (gScreenDimensions.LeftColumn, gScreenDimensions.BottomRow - STATUS_BAR_HEIGHT - 1, Character);
PrintStringAt ((UINTN) -1, (UINTN) -1, Buffer);
Character = BOXDRAW_UP_LEFT;
PrintCharAt ((UINTN) -1, (UINTN) -1, Character);
FreePool (Buffer);
}
/**
Process some op code which is not recognized by browser core.
@param OpCodeData The pointer to the op code buffer.
@return EFI_SUCCESS Pass the statement success.
**/
VOID
ProcessUserOpcode(
IN EFI_IFR_OP_HEADER *OpCodeData
)
{
switch (OpCodeData->OpCode) {
case EFI_IFR_GUID_OP:
if (CompareGuid (&gEfiIfrTianoGuid, (EFI_GUID *)((CHAR8*) OpCodeData + sizeof (EFI_IFR_OP_HEADER)))) {
//
// Tiano specific GUIDed opcodes
//
switch (((EFI_IFR_GUID_LABEL *) OpCodeData)->ExtendOpCode) {
case EFI_IFR_EXTEND_OP_LABEL:
//
// just ignore label
//
break;
case EFI_IFR_EXTEND_OP_BANNER:
//
// Only in front page form set, we care about the banner data.
//
if (gClassOfVfr == FORMSET_CLASS_FRONT_PAGE) {
//
// Initialize Driver private data
//
if (gBannerData == NULL) {
gBannerData = AllocateZeroPool (sizeof (BANNER_DATA));
ASSERT (gBannerData != NULL);
}
CopyMem (
&gBannerData->Banner[((EFI_IFR_GUID_BANNER *) OpCodeData)->LineNumber][
((EFI_IFR_GUID_BANNER *) OpCodeData)->Alignment],
&((EFI_IFR_GUID_BANNER *) OpCodeData)->Title,
sizeof (EFI_STRING_ID)
);
}
break;
case EFI_IFR_EXTEND_OP_SUBCLASS:
if (((EFI_IFR_GUID_SUBCLASS *) OpCodeData)->SubClass == EFI_FRONT_PAGE_SUBCLASS) {
gClassOfVfr = FORMSET_CLASS_FRONT_PAGE;
}
break;
default:
break;
}
}
break;
default:
break;
}
}
/**
Process some op codes which is out side of current form.
@param FormData Pointer to the form data.
@return EFI_SUCCESS Pass the statement success.
**/
VOID
ProcessExternedOpcode (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
LIST_ENTRY *Link;
FORM_DISPLAY_ENGINE_STATEMENT *Statement;
Link = GetFirstNode (&FormData->StatementListOSF);
while (!IsNull (&FormData->StatementListOSF, Link)) {
Statement = FORM_DISPLAY_ENGINE_STATEMENT_FROM_LINK (Link);
Link = GetNextNode (&FormData->StatementListOSF, Link);
ProcessUserOpcode(Statement->OpCode);
}
Link = GetFirstNode (&FormData->StatementListHead);
while (!IsNull (&FormData->StatementListHead, Link)) {
Statement = FORM_DISPLAY_ENGINE_STATEMENT_FROM_LINK (Link);
Link = GetNextNode (&FormData->StatementListHead, Link);
ProcessUserOpcode(Statement->OpCode);
}
}
/**
Validate the input screen diemenstion info.
@param FormData The input form data info.
@return EFI_SUCCESS The input screen info is acceptable.
@return EFI_INVALID_PARAMETER The input screen info is not acceptable.
**/
EFI_STATUS
ScreenDiemensionInfoValidate (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
LIST_ENTRY *Link;
UINTN Index;
//
// Calculate total number of Register HotKeys.
//
Index = 0;
if (!IsListEmpty (&FormData->HotKeyListHead)){
Link = GetFirstNode (&FormData->HotKeyListHead);
while (!IsNull (&FormData->HotKeyListHead, Link)) {
Link = GetNextNode (&FormData->HotKeyListHead, Link);
Index ++;
}
}
//
// Show three HotKeys help information on one row.
//
gFooterHeight = FOOTER_HEIGHT + (Index / 3);
ZeroMem (&gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
gST->ConOut->QueryMode (
gST->ConOut,
gST->ConOut->Mode->Mode,
&gScreenDimensions.RightColumn,
&gScreenDimensions.BottomRow
);
//
// Check local dimension vs. global dimension.
//
if (FormData->ScreenDimensions != NULL) {
if ((gScreenDimensions.RightColumn < FormData->ScreenDimensions->RightColumn) ||
(gScreenDimensions.BottomRow < FormData->ScreenDimensions->BottomRow)
) {
return EFI_INVALID_PARAMETER;
} else {
//
// Local dimension validation.
//
if ((FormData->ScreenDimensions->RightColumn > FormData->ScreenDimensions->LeftColumn) &&
(FormData->ScreenDimensions->BottomRow > FormData->ScreenDimensions->TopRow) &&
((FormData->ScreenDimensions->RightColumn - FormData->ScreenDimensions->LeftColumn) > 2) &&
((FormData->ScreenDimensions->BottomRow - FormData->ScreenDimensions->TopRow) > STATUS_BAR_HEIGHT +
FRONT_PAGE_HEADER_HEIGHT + gFooterHeight + 3)) {
CopyMem (&gScreenDimensions, (VOID *) FormData->ScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
} else {
return EFI_INVALID_PARAMETER;
}
}
}
return EFI_SUCCESS;
}
/**
Get the string based on the StringId and HII Package List Handle.
@param Token The String's ID.
@param HiiHandle The package list in the HII database to search for
the specified string.
@return The output string.
**/
CHAR16 *
LibGetToken (
IN EFI_STRING_ID Token,
IN EFI_HII_HANDLE HiiHandle
)
{
EFI_STRING String;
String = HiiGetString (HiiHandle, Token, NULL);
if (String == NULL) {
String = AllocateCopyPool (StrSize (mLibUnknownString), mLibUnknownString);
ASSERT (String != NULL);
}
return (CHAR16 *) String;
}
/**
Count the storage space of a Unicode string.
This function handles the Unicode string with NARROW_CHAR
and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
does not count in the resultant output. If a WIDE_CHAR is
hit, then 2 Unicode character will consume an output storage
space with size of CHAR16 till a NARROW_CHAR is hit.
If String is NULL, then ASSERT ().
@param String The input string to be counted.
@return Storage space for the input string.
**/
UINTN
LibGetStringWidth (
IN CHAR16 *String
)
{
UINTN Index;
UINTN Count;
UINTN IncrementValue;
ASSERT (String != NULL);
if (String == NULL) {
return 0;
}
Index = 0;
Count = 0;
IncrementValue = 1;
do {
//
// Advance to the null-terminator or to the first width directive
//
for (;
(String[Index] != NARROW_CHAR) && (String[Index] != WIDE_CHAR) && (String[Index] != 0);
Index++, Count = Count + IncrementValue
)
;
//
// We hit the null-terminator, we now have a count
//
if (String[Index] == 0) {
break;
}
//
// We encountered a narrow directive - strip it from the size calculation since it doesn't get printed
// and also set the flag that determines what we increment by.(if narrow, increment by 1, if wide increment by 2)
//
if (String[Index] == NARROW_CHAR) {
//
// Skip to the next character
//
Index++;
IncrementValue = 1;
} else {
//
// Skip to the next character
//
Index++;
IncrementValue = 2;
}
} while (String[Index] != 0);
//
// Increment by one to include the null-terminator in the size
//
Count++;
return Count * sizeof (CHAR16);
}
/**
Show all registered HotKey help strings on bottom Rows.
@param FormData The curent input form data info.
**/
VOID
PrintHotKeyHelpString (
IN FORM_DISPLAY_ENGINE_FORM *FormData
)
{
UINTN CurrentCol;
UINTN CurrentRow;
UINTN BottomRowOfHotKeyHelp;
UINTN ColumnWidth;
UINTN Index;
EFI_SCREEN_DESCRIPTOR LocalScreen;
LIST_ENTRY *Link;
BROWSER_HOT_KEY *HotKey;
if (IsListEmpty (&FormData->HotKeyListHead)) {
return;
}
CopyMem (&LocalScreen, &gScreenDimensions, sizeof (EFI_SCREEN_DESCRIPTOR));
ColumnWidth = (LocalScreen.RightColumn - LocalScreen.LeftColumn) / 3;
BottomRowOfHotKeyHelp = LocalScreen.BottomRow - STATUS_BAR_HEIGHT - 3;
//
// Calculate total number of Register HotKeys.
//
Index = 0;
Link = GetFirstNode (&FormData->HotKeyListHead);
while (!IsNull (&FormData->HotKeyListHead, Link)) {
HotKey = BROWSER_HOT_KEY_FROM_LINK (Link);
//
// Help string can't exceed ColumnWidth. One Row will show three Help information.
//
if (StrLen (HotKey->HelpString) > ColumnWidth) {
HotKey->HelpString[ColumnWidth] = L'\0';
}
//
// Calculate help information Column and Row.
//
if ((Index % 3) != 2) {
CurrentCol = LocalScreen.LeftColumn + (2 - Index % 3) * ColumnWidth;
} else {
CurrentCol = LocalScreen.LeftColumn + 2;
}
CurrentRow = BottomRowOfHotKeyHelp - Index / 3;
//
// Print HotKey help string on bottom Row.
//
PrintStringAt (CurrentCol, CurrentRow, HotKey->HelpString);
//
// Get Next Hot Key.
//
Link = GetNextNode (&FormData->HotKeyListHead, Link);
Index ++;
}
return;
}
/**
Get step info from numeric opcode.
@param[in] OpCode The input numeric op code.
@return step info for this opcode.
**/
UINT64
LibGetFieldFromNum (
IN EFI_IFR_OP_HEADER *OpCode
)
{
EFI_IFR_NUMERIC *NumericOp;
UINT64 Step;
NumericOp = (EFI_IFR_NUMERIC *) OpCode;
switch (NumericOp->Flags & EFI_IFR_NUMERIC_SIZE) {
case EFI_IFR_NUMERIC_SIZE_1:
Step = NumericOp->data.u8.Step;
break;
case EFI_IFR_NUMERIC_SIZE_2:
Step = NumericOp->data.u16.Step;
break;
case EFI_IFR_NUMERIC_SIZE_4:
Step = NumericOp->data.u32.Step;
break;
case EFI_IFR_NUMERIC_SIZE_8:
Step = NumericOp->data.u64.Step;
break;
default:
Step = 0;
break;
}
return Step;
}
/**
Initialize the HII String Token to the correct values.
**/
VOID
InitializeLibStrings (
VOID
)
{
mLibUnknownString = L"!";
gEnterString = LibGetToken (STRING_TOKEN (ENTER_STRING), mCDLStringPackHandle);
gEnterCommitString = LibGetToken (STRING_TOKEN (ENTER_COMMIT_STRING), mCDLStringPackHandle);
gEnterEscapeString = LibGetToken (STRING_TOKEN (ENTER_ESCAPE_STRING), mCDLStringPackHandle);
gEscapeString = LibGetToken (STRING_TOKEN (ESCAPE_STRING), mCDLStringPackHandle);
gMoveHighlight = LibGetToken (STRING_TOKEN (MOVE_HIGHLIGHT), mCDLStringPackHandle);
gDecNumericInput = LibGetToken (STRING_TOKEN (DEC_NUMERIC_INPUT), mCDLStringPackHandle);
gHexNumericInput = LibGetToken (STRING_TOKEN (HEX_NUMERIC_INPUT), mCDLStringPackHandle);
gToggleCheckBox = LibGetToken (STRING_TOKEN (TOGGLE_CHECK_BOX), mCDLStringPackHandle);
gAreYouSure = LibGetToken (STRING_TOKEN (ARE_YOU_SURE), mCDLStringPackHandle);
gYesResponse = LibGetToken (STRING_TOKEN (ARE_YOU_SURE_YES), mCDLStringPackHandle);
gNoResponse = LibGetToken (STRING_TOKEN (ARE_YOU_SURE_NO), mCDLStringPackHandle);
gPlusString = LibGetToken (STRING_TOKEN (PLUS_STRING), mCDLStringPackHandle);
gMinusString = LibGetToken (STRING_TOKEN (MINUS_STRING), mCDLStringPackHandle);
gAdjustNumber = LibGetToken (STRING_TOKEN (ADJUST_NUMBER), mCDLStringPackHandle);
gSaveChanges = LibGetToken (STRING_TOKEN (SAVE_CHANGES), mCDLStringPackHandle);
gLibEmptyString = LibGetToken (STRING_TOKEN (EMPTY_STRING), mCDLStringPackHandle);
gNvUpdateMessage = LibGetToken (STRING_TOKEN (NV_UPDATE_MESSAGE), mCDLStringPackHandle);
gInputErrorMessage = LibGetToken (STRING_TOKEN (INPUT_ERROR_MESSAGE), mCDLStringPackHandle);
//
// SpaceBuffer;
//
mSpaceBuffer = AllocatePool ((SPACE_BUFFER_SIZE + 1) * sizeof (CHAR16));
ASSERT (mSpaceBuffer != NULL);
LibSetUnicodeMem (mSpaceBuffer, SPACE_BUFFER_SIZE, L' ');
mSpaceBuffer[SPACE_BUFFER_SIZE] = L'\0';
}
/**
Free the HII String.
**/
VOID
FreeLibStrings (
VOID
)
{
FreePool (gEnterString);
FreePool (gEnterCommitString);
FreePool (gEnterEscapeString);
FreePool (gEscapeString);
FreePool (gMoveHighlight);
FreePool (gDecNumericInput);
FreePool (gHexNumericInput);
FreePool (gToggleCheckBox);
FreePool (gAreYouSure);
FreePool (gYesResponse);
FreePool (gNoResponse);
FreePool (gPlusString);
FreePool (gMinusString);
FreePool (gAdjustNumber);
FreePool (gSaveChanges);
FreePool (gLibEmptyString);
FreePool (gNvUpdateMessage);
FreePool (gInputErrorMessage);
FreePool (mSpaceBuffer);
}
/**
Wait for a key to be pressed by user.
@param Key The key which is pressed by user.
@retval EFI_SUCCESS The function always completed successfully.
**/
EFI_STATUS
WaitForKeyStroke (
OUT EFI_INPUT_KEY *Key
)
{
EFI_STATUS Status;
UINTN Index;
while (TRUE) {
Status = gST->ConIn->ReadKeyStroke (gST->ConIn, Key);
if (!EFI_ERROR (Status)) {
break;
}
if (Status != EFI_NOT_READY) {
continue;
}
gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &Index);
}
return Status;
}
/**
Set Buffer to Value for Size bytes.
@param Buffer Memory to set.
@param Size Number of bytes to set
@param Value Value of the set operation.
**/
VOID
LibSetUnicodeMem (
IN VOID *Buffer,
IN UINTN Size,
IN CHAR16 Value
)
{
CHAR16 *Ptr;
Ptr = Buffer;
while ((Size--) != 0) {
*(Ptr++) = Value;
}
}
/**
The internal function prints to the EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL
protocol instance.
@param Width Width of string to be print.
@param Column The position of the output string.
@param Row The position of the output string.
@param Out The EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL instance.
@param Fmt The format string.
@param Args The additional argument for the variables in the format string.
@return Number of Unicode character printed.
**/
UINTN
PrintInternal (
IN UINTN Width,
IN UINTN Column,
IN UINTN Row,
IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *Out,
IN CHAR16 *Fmt,
IN VA_LIST Args
)
{
CHAR16 *Buffer;
CHAR16 *BackupBuffer;
UINTN Index;
UINTN PreviousIndex;
UINTN Count;
UINTN PrintWidth;
UINTN CharWidth;
//
// For now, allocate an arbitrarily long buffer
//
Buffer = AllocateZeroPool (0x10000);
BackupBuffer = AllocateZeroPool (0x10000);
ASSERT (Buffer);
ASSERT (BackupBuffer);
if (Column != (UINTN) -1) {
Out->SetCursorPosition (Out, Column, Row);
}
UnicodeVSPrint (Buffer, 0x10000, Fmt, Args);
Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
Out->SetAttribute (Out, Out->Mode->Attribute);
Index = 0;
PreviousIndex = 0;
Count = 0;
PrintWidth = 0;
CharWidth = 1;
do {
for (; (Buffer[Index] != NARROW_CHAR) && (Buffer[Index] != WIDE_CHAR) && (Buffer[Index] != 0); Index++) {
BackupBuffer[Index] = Buffer[Index];
}
if (Buffer[Index] == 0) {
break;
}
//
// Null-terminate the temporary string
//
BackupBuffer[Index] = 0;
//
// Print this out, we are about to switch widths
//
Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
Count += StrLen (&BackupBuffer[PreviousIndex]);
PrintWidth += Count * CharWidth;
//
// Preserve the current index + 1, since this is where we will start printing from next
//
PreviousIndex = Index + 1;
//
// We are at a narrow or wide character directive. Set attributes and strip it and print it
//
if (Buffer[Index] == NARROW_CHAR) {
//
// Preserve bits 0 - 6 and zero out the rest
//
Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
Out->SetAttribute (Out, Out->Mode->Attribute);
CharWidth = 1;
} else {
//
// Must be wide, set bit 7 ON
//
Out->Mode->Attribute = Out->Mode->Attribute | EFI_WIDE_ATTRIBUTE;
Out->SetAttribute (Out, Out->Mode->Attribute);
CharWidth = 2;
}
Index++;
} while (Buffer[Index] != 0);
//
// We hit the end of the string - print it
//
Out->OutputString (Out, &BackupBuffer[PreviousIndex]);
Count += StrLen (&BackupBuffer[PreviousIndex]);
PrintWidth += Count * CharWidth;
if (PrintWidth < Width) {
Out->Mode->Attribute = Out->Mode->Attribute & 0x7f;
Out->SetAttribute (Out, Out->Mode->Attribute);
Out->OutputString (Out, &mSpaceBuffer[SPACE_BUFFER_SIZE - Width + PrintWidth]);
}
FreePool (Buffer);
FreePool (BackupBuffer);
return Count;
}
/**
Prints a formatted unicode string to the default console, at
the supplied cursor position.
@param Width Width of String to be printed.
@param Column The cursor position to print the string at.
@param Row The cursor position to print the string at.
@param Fmt Format string.
@param ... Variable argument list for format string.
@return Length of string printed to the console
**/
UINTN
EFIAPI
PrintAt (
IN UINTN Width,
IN UINTN Column,
IN UINTN Row,
IN CHAR16 *Fmt,
...
)
{
VA_LIST Args;
UINTN LengthOfPrinted;
VA_START (Args, Fmt);
LengthOfPrinted = PrintInternal (Width, Column, Row, gST->ConOut, Fmt, Args);
VA_END (Args);
return LengthOfPrinted;
}

View File

@@ -0,0 +1,295 @@
/** @file
This library class defines a set of interfaces to customize Display module
Copyright (c) 2013, 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 that accompanies this distribution.
The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php.
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __CUSTOMIZED_DISPLAY_LIB_INTERNAL_H__
#define __CUSTOMIZED_DISPLAY_LIB_INTERNAL_H__
#include <PiDxe.h>
#include <Protocol/SimpleTextOut.h>
#include <Protocol/SimpleTextIn.h>
#include <Protocol/FormBrowser2.h>
#include <Protocol/FormBrowserEx2.h>
#include <Protocol/DisplayProtocol.h>
#include <Protocol/DevicePath.h>
#include <Protocol/UnicodeCollation.h>
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/HiiConfigRouting.h>
#include <Protocol/HiiDatabase.h>
#include <Protocol/HiiString.h>
#include <Protocol/UserManager.h>
#include <Protocol/DevicePathFromText.h>
#include <Guid/MdeModuleHii.h>
#include <Guid/HiiPlatformSetupFormset.h>
#include <Guid/HiiFormMapMethodGuid.h>
#include <Library/PrintLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/HiiLib.h>
#include <Library/PcdLib.h>
#include <Library/DevicePathLib.h>
#include <Library/CustomizedDisplayLib.h>
#include "Colors.h"
#define FORMSET_CLASS_PLATFORM_SETUP 0x0001
#define FORMSET_CLASS_FRONT_PAGE 0x0002
#define FRONT_PAGE_HEADER_HEIGHT 6
#define NONE_FRONT_PAGE_HEADER_HEIGHT 3
#define FOOTER_HEIGHT 4
#define STATUS_BAR_HEIGHT 1
//
// Screen definitions
//
#define BANNER_HEIGHT 6
#define BANNER_COLUMNS 3
#define BANNER_LEFT_COLUMN_INDENT 1
//
// Character definitions
//
#define UPPER_LOWER_CASE_OFFSET 0x20
//
// This is the Input Error Message
//
#define INPUT_ERROR 1
//
// This is the NV RAM update required Message
//
#define NV_UPDATE_REQUIRED 2
typedef struct {
EFI_STRING_ID Banner[BANNER_HEIGHT][BANNER_COLUMNS];
} BANNER_DATA;
extern UINT16 gClassOfVfr; // Formset class information
extern BANNER_DATA *gBannerData;
extern EFI_SCREEN_DESCRIPTOR gScreenDimensions;
extern UINTN gFooterHeight;
//
// Browser Global Strings
//
extern CHAR16 *gEnterString;
extern CHAR16 *gEnterCommitString;
extern CHAR16 *gEnterEscapeString;
extern CHAR16 *gEscapeString;
extern CHAR16 *gMoveHighlight;
extern CHAR16 *gDecNumericInput;
extern CHAR16 *gHexNumericInput;
extern CHAR16 *gToggleCheckBox;
extern CHAR16 *gLibEmptyString;
extern CHAR16 *gAreYouSure;
extern CHAR16 *gYesResponse;
extern CHAR16 *gNoResponse;
extern CHAR16 *gPlusString;
extern CHAR16 *gMinusString;
extern CHAR16 *gAdjustNumber;
extern CHAR16 *gSaveChanges;
extern CHAR16 *gNvUpdateMessage;
extern CHAR16 *gInputErrorMessage;
/**
Print banner info for front page.
@param[in] FormData Form Data to be shown in Page
**/
VOID
PrintBannerInfo (
IN FORM_DISPLAY_ENGINE_FORM *FormData
);
/**
Print framework and form title for a page.
@param[in] FormData Form Data to be shown in Page
**/
VOID
PrintFramework (
IN FORM_DISPLAY_ENGINE_FORM *FormData
);
/**
Validate the input screen diemenstion info.
@param FormData The input form data info.
@return EFI_SUCCESS The input screen info is acceptable.
@return EFI_INVALID_PARAMETER The input screen info is not acceptable.
**/
EFI_STATUS
ScreenDiemensionInfoValidate (
IN FORM_DISPLAY_ENGINE_FORM *FormData
);
/**
Get the string based on the StringId and HII Package List Handle.
@param Token The String's ID.
@param HiiHandle The package list in the HII database to search for
the specified string.
@return The output string.
**/
CHAR16 *
LibGetToken (
IN EFI_STRING_ID Token,
IN EFI_HII_HANDLE HiiHandle
);
/**
Count the storage space of a Unicode string.
This function handles the Unicode string with NARROW_CHAR
and WIDE_CHAR control characters. NARROW_HCAR and WIDE_CHAR
does not count in the resultant output. If a WIDE_CHAR is
hit, then 2 Unicode character will consume an output storage
space with size of CHAR16 till a NARROW_CHAR is hit.
If String is NULL, then ASSERT ().
@param String The input string to be counted.
@return Storage space for the input string.
**/
UINTN
LibGetStringWidth (
IN CHAR16 *String
);
/**
Show all registered HotKey help strings on bottom Rows.
@param FormData The curent input form data info.
**/
VOID
PrintHotKeyHelpString (
IN FORM_DISPLAY_ENGINE_FORM *FormData
);
/**
Get step info from numeric opcode.
@param[in] OpCode The input numeric op code.
@return step info for this opcode.
**/
UINT64
LibGetFieldFromNum (
IN EFI_IFR_OP_HEADER *OpCode
);
/**
Initialize the HII String Token to the correct values.
**/
VOID
InitializeLibStrings (
VOID
);
/**
Free the HII String.
**/
VOID
FreeLibStrings (
VOID
);
/**
Wait for a key to be pressed by user.
@param Key The key which is pressed by user.
@retval EFI_SUCCESS The function always completed successfully.
**/
EFI_STATUS
WaitForKeyStroke (
OUT EFI_INPUT_KEY *Key
);
/**
Set Buffer to Value for Size bytes.
@param Buffer Memory to set.
@param Size Number of bytes to set
@param Value Value of the set operation.
**/
VOID
LibSetUnicodeMem (
IN VOID *Buffer,
IN UINTN Size,
IN CHAR16 Value
);
/**
Prints a formatted unicode string to the default console, at
the supplied cursor position.
@param Width Width of String to be printed.
@param Column The cursor position to print the string at.
@param Row The cursor position to print the string at.
@param Fmt Format string.
@param ... Variable argument list for format string.
@return Length of string printed to the console
**/
UINTN
EFIAPI
PrintAt (
IN UINTN Width,
IN UINTN Column,
IN UINTN Row,
IN CHAR16 *Fmt,
...
);
/**
Process some op codes which is out side of current form.
@param FormData Pointer to the form data.
**/
VOID
ProcessExternedOpcode (
IN FORM_DISPLAY_ENGINE_FORM *FormData
);
#endif