From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from atlmailgw1.ami.com (atlmailgw1.ami.com [63.147.10.40]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 32C9581C94 for ; Wed, 9 Nov 2016 07:44:23 -0800 (PST) X-AuditID: ac1060b2-a7fff7000000467b-f5-582344504704 Received: from atlms2.us.megatrends.com (atlms2.us.megatrends.com [172.16.96.152]) (using TLS with cipher AES128-SHA (128/128 bits)) (Client did not present a certificate) by (Symantec Messaging Gateway) with SMTP id 3D.80.18043.15443285; Wed, 9 Nov 2016 10:44:20 -0500 (EST) Received: from ATLMS1.us.megatrends.com ([fe80::8c55:daf0:ef05:5605]) by atlms2.us.megatrends.com ([fe80::29dc:a91e:ea0c:cdeb%12]) with mapi id 14.03.0123.003; Wed, 9 Nov 2016 10:44:16 -0500 From: Felix Poludov To: "edk2-devel@lists.01.org" Thread-Topic: [PATCH 1/2] MdePkg: UiLib library. Add UiLib. Update UefiLib. Thread-Index: AdI6npWPXC0aMTZaRXK0ZerWknEBxQ== Date: Wed, 9 Nov 2016 15:44:16 +0000 Message-ID: <9333E191E0D52B4999CE63A99BA663A00270FF9988@atlms1.us.megatrends.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.16.99.93] MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmplleLIzCtJLcpLzFFi42JZI5AwQzfURTnC4P1uEYs9h44yOzB6dM/+ xxLAGNXAaJOYl5dfkliSqpCSWpxsqxRQlFmWmFyppJCZYqtkqKRQkJOYnJqbmldiq5RYUJCa l6Jkx6WAAWyAyjLzFFLzkvNTMvPSbZU8g/11LSxMLXUNlexCMlIVMvPS8otyE0sy8/MUkvPz SoCqU1OAogoJXZwZ18/cYCmY+oStYsv6IywNjJ/fsXYxcnJICJhILP/XzNTFyMUhJDCbSWLD m7VQziFGiZ5lX9lAqtgEVCQ2nb3ADGKLCJhLtM6/wgRiCwu4Sdy8+IMVIu4tMXHLZihbT+LP odcsIDYLUO+ZjwfZQWxegUCJRVu3gtUwCohJfD+1BmwOs4C4xK0n85kgLhKQWLLnPDOELSrx 8vE/qEsVJLa872SHqM+X6D49gwlipqDEyZlPWCYwCs5CMmoWkrJZSMog4joSC3Z/YoOwtSWW LXzNDGOfOfCYCVl8ASP7KkahxJKc3MTMnPRyQ73E3Ey95PzcTYyQWN+0g7HlovkhRgEORiUe Xmk+5Qgh1sSy4spcYPBxMCuJ8B6zBArxpiRWVqUW5ccXleakFh9idAIGy0RmKW5QLAGjPd7Y wEBKFMYxNDEzMTcyN7Q0MTc2VhLnLfrjGy4kkA5MPtmpqQWpRTBDmDg4pRoYOYrlis9Fn/b5 qbwvOoxHeCtrbPTO+bwvF+g6743VP/RNpeCTkn31baOfH1k2TLvTERT4Lk+g51chs3vPrQlP eZOv3hI8v+/ngrLuqtjAPaYTm2f32Lk/unfKMJv5Pme4VrVsRdrxF/+stV/Os9hrMl/52lXX kJjXZdrvOD9vk5/XKcvwYMZZJZbijERDLeai4kQAg00H1hgDAAA= X-Content-Filtered-By: Mailman/MimeDel 2.1.21 Subject: [PATCH 1/2] MdePkg: UiLib library. Add UiLib. Update UefiLib. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Nov 2016 15:44:23 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 1. New UiLib library class is added to MdePkg. The library is intended for functions that produce UI elements. The patch introduces two functions that produce a popup window: UiCreatePopUp and UiCreatePopUpVaList. 2. An instance of UiLib library class is added to MdePkg. Popup implementation is copied from UefiLib (CreatePopUp function in UefiLib/Console.c). 3. MdePkg/UefiLib library is updated to implement CreatePopUp by calling UiCreatePopUpVaList. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Felix Polyudov --- MdePkg/Include/Library/UiLib.h | 71 +++++++ MdePkg/Library/UefiLib/Console.c | 252 +---------------------- MdePkg/Library/UefiLib/UefiLib.inf | 1 + MdePkg/Library/UefiLib/UefiLibInternal.h | 1 + MdePkg/Library/UiLib/UiLib.c | 334 +++++++++++++++++++++++++++++= ++ MdePkg/Library/UiLib/UiLib.inf | 38 ++++ MdePkg/Library/UiLib/UiLib.uni | 21 ++ MdePkg/MdePkg.dec | 3 + 8 files changed, 470 insertions(+), 251 deletions(-) create mode 100644 MdePkg/Include/Library/UiLib.h create mode 100644 MdePkg/Library/UiLib/UiLib.c create mode 100644 MdePkg/Library/UiLib/UiLib.inf create mode 100644 MdePkg/Library/UiLib/UiLib.uni diff --git a/MdePkg/Include/Library/UiLib.h b/MdePkg/Include/Library/UiLib.h new file mode 100644 index 0000000..0f6b687 --- /dev/null +++ b/MdePkg/Include/Library/UiLib.h @@ -0,0 +1,71 @@ +/** @file + Provides library functions to construct UI elements. + +Copyright (c) 2016, American Megatrends, Inc. All rights reserved.
+This program and the accompanying materials are licensed and made available= under +the terms and conditions of the BSD License that accompanies this distribut= ion. +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 IMPLIE= D. + +**/ + +#ifndef __UI_LIB_H__ +#define __UI_LIB_H__ + +/** + Draws a dialog box to the console output device specified by + ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke + from the console input device specified by ConIn defined in the + EFI_SYSTEM_TABLE. + + If there are no strings in the variable argument list, then ASSERT(). + If all the strings in the variable argument list are empty, then ASSERT()= . + + @param[in] Attribute Specifies the foreground and background color of= the popup. + @param[out] Key A pointer to the EFI_KEY value of the key that wa= s + pressed. This is an optional parameter that may= be NULL. + If it is NULL then no wait for a keypress will be= performed. + @param[in] ... The variable argument list that contains pointers= to Null- + terminated Unicode strings to display in the dial= og box. + The variable argument list is terminated by a NUL= L. + +**/ +VOID +EFIAPI +UiCreatePopUp ( + IN UINTN Attribute, + OUT EFI_INPUT_KEY *Key, OPTIONAL + ... + ); + +/** + Draws a dialog box to the console output device specified by + ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke + from the console input device specified by ConIn defined in the + EFI_SYSTEM_TABLE. + + If there are no strings in the variable argument list, then ASSERT(). + If all the strings in the variable argument list are empty, then ASSERT()= . + + @param[in] Attribute Specifies the foreground and background color of= the popup. + @param[out] Key A pointer to the EFI_KEY value of the key that wa= s + pressed. This is an optional parameter that may= be NULL. + If it is NULL then no wait for a keypress will be= performed. + @param[in] Args VA_LIST marker for the variable argument list tha= t contains + pointers to Null-terminated Unicode strings to di= splay + = in the dialog box. + The variable argument list is terminated by a NUL= L. + +**/ +VOID +EFIAPI +UiCreatePopUpVaList ( + IN UINTN Attribute, + OUT EFI_INPUT_KEY *Key, OPTIONAL + IN VA_LIST Args + ); + +#endif diff --git a/MdePkg/Library/UefiLib/Console.c b/MdePkg/Library/UefiLib/Conso= le.c index ecaf425..8e7e986 100644 --- a/MdePkg/Library/UefiLib/Console.c +++ b/MdePkg/Library/UefiLib/Console.c @@ -22,9 +22,6 @@ typedef struct { UINT32 Width; } UNICODE_WIDTH_ENTRY; -#define NARROW_CHAR 0xFFF0 -#define WIDE_CHAR 0xFFF1 - GLOBAL_REMOVE_IF_UNREFERENCED CONST UNICODE_WIDTH_ENTRY mUnicodeWidthTable[]= =3D { // // General script area @@ -292,89 +289,6 @@ UnicodeStringDisplayLength ( } /** - 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. - - @param String The input string to be counted. - @param LimitLen Whether need to limit the string length. - @param MaxWidth The max length this function supported. - @param Offset The max index of the string can be show out. - - @return Storage space for the input string. - -**/ -UINTN -UefiLibGetStringWidth ( - IN CHAR16 *String, - IN BOOLEAN LimitLen, - IN UINTN MaxWidth, - OUT UINTN *Offset - ) -{ - UINTN Index; - UINTN Count; - UINTN IncrementValue; - - if (String =3D=3D NULL) { - return 0; - } - - Index =3D 0; - Count =3D 0; - IncrementValue =3D 1; - - do { - // - // Advance to the null-terminator or to the first width directive - // - for (;(String[Index] !=3D NARROW_CHAR) && (String[Index] !=3D WIDE_CHAR= ) && (String[Index] !=3D 0); Index++) { - Count =3D Count + IncrementValue; - - if (LimitLen && Count > MaxWidth) { - break; - } - } - - // - // We hit the null-terminator, we now have a count - // - if (String[Index] =3D=3D 0) { - break; - } - - if (LimitLen && Count > MaxWidth) { - *Offset =3D Index; - break; - } - - // - // We encountered a narrow directive - strip it from the size calculati= on since it doesn't get printed - // and also set the flag that determines what we increment by.(if narro= w, increment by 1, if wide increment by 2) - // - if (String[Index] =3D=3D NARROW_CHAR) { - // - // Skip to the next character - // - Index++; - IncrementValue =3D 1; - } else { - // - // Skip to the next character - // - Index++; - IncrementValue =3D 2; - } - } while (String[Index] !=3D 0); - - return Count * sizeof (CHAR16); -} - -/** Draws a dialog box to the console output device specified by ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke from the console input device specified by ConIn defined in the @@ -400,173 +314,9 @@ CreatePopUp ( ... ) { - EFI_STATUS Status; VA_LIST Args; - EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; - EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; - UINTN Columns; - UINTN Rows; - UINTN Column; - UINTN Row; - UINTN NumberOfLines; - UINTN MaxLength; - CHAR16 *String; - UINTN Length; - CHAR16 *Line; - UINTN EventIndex; - CHAR16 *TmpString; - - // - // Determine the length of the longest line in the popup and the the tota= l - // number of lines in the popup - // - VA_START (Args, Key); - MaxLength =3D 0; - NumberOfLines =3D 0; - while ((String =3D VA_ARG (Args, CHAR16 *)) !=3D NULL) { - MaxLength =3D MAX (MaxLength, UefiLibGetStringWidth (String, FALSE, 0,= NULL) / 2); - NumberOfLines++; - } - VA_END (Args); - - // - // If the total number of lines in the popup is zero, then ASSERT() - // - ASSERT (NumberOfLines !=3D 0); - - // - // If the maximum length of all the strings is zero, then ASSERT() - // - ASSERT (MaxLength !=3D 0); - - // - // Cache a pointer to the Simple Text Output Protocol in the EFI System T= able - // - ConOut =3D gST->ConOut; - - // - // Save the current console cursor position and attributes - // - CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode)); - - // - // Retrieve the number of columns and rows in the current console mode - // - ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows); - - // - // Disable cursor and set the foreground and background colors specified= by Attribute - // - ConOut->EnableCursor (ConOut, FALSE); - ConOut->SetAttribute (ConOut, Attribute); - - // - // Limit NumberOfLines to height of the screen minus 3 rows for the box i= tself - // - NumberOfLines =3D MIN (NumberOfLines, Rows - 3); - - // - // Limit MaxLength to width of the screen minus 2 columns for the box its= elf - // - MaxLength =3D MIN (MaxLength, Columns - 2); - - // - // Compute the starting row and starting column for the popup - // - Row =3D (Rows - (NumberOfLines + 3)) / 2; - Column =3D (Columns - (MaxLength + 2)) / 2; - - // - // Allocate a buffer for a single line of the popup with borders and a Nu= ll-terminator - // - Line =3D AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16)); - ASSERT (Line !=3D NULL); - // - // Draw top of popup box - // - SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); - Line[0] =3D BOXDRAW_DOWN_RIGHT; - Line[MaxLength + 1] =3D BOXDRAW_DOWN_LEFT; - Line[MaxLength + 2] =3D L'\0'; - ConOut->SetCursorPosition (ConOut, Column, Row++); - ConOut->OutputString (ConOut, Line); - - // - // Draw middle of the popup with strings - // VA_START (Args, Key); - while ((String =3D VA_ARG (Args, CHAR16 *)) !=3D NULL && NumberOfLines >= 0) { - SetMem16 (Line, (MaxLength + 2) * 2, L' '); - Line[0] =3D BOXDRAW_VERTICAL; - Line[MaxLength + 1] =3D BOXDRAW_VERTICAL; - Line[MaxLength + 2] =3D L'\0'; - ConOut->SetCursorPosition (ConOut, Column, Row); - ConOut->OutputString (ConOut, Line); - Length =3D UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2; - if (Length <=3D MaxLength) { - // - // Length <=3D MaxLength - // - ConOut->SetCursorPosition (ConOut, Column + 1 + (MaxLength - Length)= / 2, Row++); - ConOut->OutputString (ConOut, String); - } else { - // - // Length > MaxLength - // - UefiLibGetStringWidth (String, TRUE, MaxLength, &Length); - TmpString =3D AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); - ASSERT (TmpString !=3D NULL); - StrnCpyS (TmpString, Length + 1, String, Length - 3); - StrCatS (TmpString, Length + 1, L"..."); - - ConOut->SetCursorPosition (ConOut, Column + 1, Row++); - ConOut->OutputString (ConOut, TmpString); - FreePool (TmpString); - } - NumberOfLines--; - } + UiCreatePopUpVaList(Attribute, Key, Args); VA_END (Args); - - // - // Draw bottom of popup box - // - SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); - Line[0] =3D BOXDRAW_UP_RIGHT; - Line[MaxLength + 1] =3D BOXDRAW_UP_LEFT; - Line[MaxLength + 2] =3D L'\0'; - ConOut->SetCursorPosition (ConOut, Column, Row++); - ConOut->OutputString (ConOut, Line); - - // - // Free the allocated line buffer - // - FreePool (Line); - - // - // Restore the cursor visibility, position, and attributes - // - ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible); - ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedCo= nsoleMode.CursorRow); - ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute); - - // - // Wait for a keystroke - // - if (Key !=3D NULL) { - while (TRUE) { - Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, Key); - if (!EFI_ERROR (Status)) { - break; - } - - // - // If we encounter error, continue to read another key in. - // - if (Status !=3D EFI_NOT_READY) { - continue; - } - gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); - } - } } diff --git a/MdePkg/Library/UefiLib/UefiLib.inf b/MdePkg/Library/UefiLib/Uef= iLib.inf index 8284dc5..0767aff 100644 --- a/MdePkg/Library/UefiLib/UefiLib.inf +++ b/MdePkg/Library/UefiLib/UefiLib.inf @@ -57,6 +57,7 @@ UefiBootServicesTableLib DevicePathLib UefiRuntimeServicesTableLib + UiLib [Guids] gEfiEventReadyToBootGuid ## SOMETIMES_CONSUMES ## E= vent diff --git a/MdePkg/Library/UefiLib/UefiLibInternal.h b/MdePkg/Library/UefiL= ib/UefiLibInternal.h index 2311f27..96c6e88 100644 --- a/MdePkg/Library/UefiLib/UefiLibInternal.h +++ b/MdePkg/Library/UefiLib/UefiLibInternal.h @@ -40,6 +40,7 @@ #include #include #include +#include /** An empty function to pass error checking of CreateEventEx (). diff --git a/MdePkg/Library/UiLib/UiLib.c b/MdePkg/Library/UiLib/UiLib.c new file mode 100644 index 0000000..823dd0a --- /dev/null +++ b/MdePkg/Library/UiLib/UiLib.c @@ -0,0 +1,334 @@ +/** @file + The UI Library provides functions that are used to construct UI elements. + + Copyright (c) 2016, American Megatrends, Inc. All rights reserved.
+ Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.
+ 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 IMPL= IED. + +**/ + +#include +#include +#include +#include +#include +#include +#include + +#define NARROW_CHAR 0xFFF0 +#define WIDE_CHAR 0xFFF1 + +/** + 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. + + @param String The input string to be counted. + @param LimitLen Whether need to limit the string length. + @param MaxWidth The max length this function supported. + @param Offset The max index of the string can be show out. + + @return Storage space for the input string. + +**/ +UINTN +UefiLibGetStringWidth ( + IN CHAR16 *String, + IN BOOLEAN LimitLen, + IN UINTN MaxWidth, + OUT UINTN *Offset + ) +{ + UINTN Index; + UINTN Count; + UINTN IncrementValue; + + if (String =3D=3D NULL) { + return 0; + } + + Index =3D 0; + Count =3D 0; + IncrementValue =3D 1; + + do { + // + // Advance to the null-terminator or to the first width directive + // + for (;(String[Index] !=3D NARROW_CHAR) && (String[Index] !=3D WIDE_CHAR= ) && (String[Index] !=3D 0); Index++) { + Count =3D Count + IncrementValue; + + if (LimitLen && Count > MaxWidth) { + break; + } + } + + // + // We hit the null-terminator, we now have a count + // + if (String[Index] =3D=3D 0) { + break; + } + + if (LimitLen && Count > MaxWidth) { + *Offset =3D Index; + break; + } + + // + // We encountered a narrow directive - strip it from the size calculati= on since it doesn't get printed + // and also set the flag that determines what we increment by.(if narro= w, increment by 1, if wide increment by 2) + // + if (String[Index] =3D=3D NARROW_CHAR) { + // + // Skip to the next character + // + Index++; + IncrementValue =3D 1; + } else { + // + // Skip to the next character + // + Index++; + IncrementValue =3D 2; + } + } while (String[Index] !=3D 0); + + return Count * sizeof (CHAR16); +} + +/** + Draws a dialog box to the console output device specified by + ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke + from the console input device specified by ConIn defined in the + EFI_SYSTEM_TABLE. + + If there are no strings in the variable argument list, then ASSERT(). + If all the strings in the variable argument list are empty, then ASSERT()= . + + @param[in] Attribute Specifies the foreground and background color of= the popup. + @param[out] Key A pointer to the EFI_KEY value of the key that wa= s + pressed. This is an optional parameter that may= be NULL. + If it is NULL then no wait for a keypress will be= performed. + @param[in] Args VA_LIST marker for the variable argument list tha= t contains + pointers to Null-terminated Unicode strings to di= splay + = in the dialog box. + The variable argument list is terminated by a NUL= L. + +**/ +VOID +EFIAPI +UiCreatePopUpVaList ( + IN UINTN Attribute, + OUT EFI_INPUT_KEY *Key, OPTIONAL + IN VA_LIST Args + ) +{ + EFI_STATUS Status; + EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut; + EFI_SIMPLE_TEXT_OUTPUT_MODE SavedConsoleMode; + UINTN Columns; + UINTN Rows; + UINTN Column; + UINTN Row; + UINTN NumberOfLines; + UINTN MaxLength; + CHAR16 *String; + UINTN Length; + CHAR16 *Line; + UINTN EventIndex; + CHAR16 *TmpString; + + // + // Determine the length of the longest line in the popup and the the tota= l + // number of lines in the popup + // + MaxLength =3D 0; + NumberOfLines =3D 0; + while ((String =3D VA_ARG (Args, CHAR16 *)) !=3D NULL) { + MaxLength =3D MAX (MaxLength, UefiLibGetStringWidth (String, FALSE, 0,= NULL) / 2); + NumberOfLines++; + } + + // + // If the total number of lines in the popup is zero, then ASSERT() + // + ASSERT (NumberOfLines !=3D 0); + + // + // If the maximum length of all the strings is zero, then ASSERT() + // + ASSERT (MaxLength !=3D 0); + + // + // Cache a pointer to the Simple Text Output Protocol in the EFI System T= able + // + ConOut =3D gST->ConOut; + + // + // Save the current console cursor position and attributes + // + CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode)); + + // + // Retrieve the number of columns and rows in the current console mode + // + ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows); + + // + // Disable cursor and set the foreground and background colors specified= by Attribute + // + ConOut->EnableCursor (ConOut, FALSE); + ConOut->SetAttribute (ConOut, Attribute); + + // + // Limit NumberOfLines to height of the screen minus 3 rows for the box i= tself + // + NumberOfLines =3D MIN (NumberOfLines, Rows - 3); + + // + // Limit MaxLength to width of the screen minus 2 columns for the box its= elf + // + MaxLength =3D MIN (MaxLength, Columns - 2); + + // + // Compute the starting row and starting column for the popup + // + Row =3D (Rows - (NumberOfLines + 3)) / 2; + Column =3D (Columns - (MaxLength + 2)) / 2; + + // + // Allocate a buffer for a single line of the popup with borders and a Nu= ll-terminator + // + Line =3D AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16)); + ASSERT (Line !=3D NULL); + + // + // Draw top of popup box + // + SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); + Line[0] =3D BOXDRAW_DOWN_RIGHT; + Line[MaxLength + 1] =3D BOXDRAW_DOWN_LEFT; + Line[MaxLength + 2] =3D L'\0'; + ConOut->SetCursorPosition (ConOut, Column, Row++); + ConOut->OutputString (ConOut, Line); + + // + // Draw middle of the popup with strings + // + while ((String =3D VA_ARG (Args, CHAR16 *)) !=3D NULL && NumberOfLines >= 0) { + SetMem16 (Line, (MaxLength + 2) * 2, L' '); + Line[0] =3D BOXDRAW_VERTICAL; + Line[MaxLength + 1] =3D BOXDRAW_VERTICAL; + Line[MaxLength + 2] =3D L'\0'; + ConOut->SetCursorPosition (ConOut, Column, Row); + ConOut->OutputString (ConOut, Line); + Length =3D UefiLibGetStringWidth (String, FALSE, 0, NULL) / 2; + if (Length <=3D MaxLength) { + // + // Length <=3D MaxLength + // + ConOut->SetCursorPosition (ConOut, Column + 1 + (MaxLength - Length)= / 2, Row++); + ConOut->OutputString (ConOut, String); + } else { + // + // Length > MaxLength + // + UefiLibGetStringWidth (String, TRUE, MaxLength, &Length); + TmpString =3D AllocateZeroPool ((Length + 1) * sizeof (CHAR16)); + ASSERT (TmpString !=3D NULL); + StrnCpyS (TmpString, Length + 1, String, Length - 3); + StrCatS (TmpString, Length + 1, L"..."); + + ConOut->SetCursorPosition (ConOut, Column + 1, Row++); + ConOut->OutputString (ConOut, TmpString); + FreePool (TmpString); + } + NumberOfLines--; + } + + // + // Draw bottom of popup box + // + SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL); + Line[0] =3D BOXDRAW_UP_RIGHT; + Line[MaxLength + 1] =3D BOXDRAW_UP_LEFT; + Line[MaxLength + 2] =3D L'\0'; + ConOut->SetCursorPosition (ConOut, Column, Row++); + ConOut->OutputString (ConOut, Line); + + // + // Free the allocated line buffer + // + FreePool (Line); + + // + // Restore the cursor visibility, position, and attributes + // + ConOut->EnableCursor (ConOut, SavedConsoleMode.CursorVisible); + ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedCo= nsoleMode.CursorRow); + ConOut->SetAttribute (ConOut, SavedConsoleMode.Attribute); + + // + // Wait for a keystroke + // + if (Key !=3D NULL) { + while (TRUE) { + Status =3D gST->ConIn->ReadKeyStroke (gST->ConIn, Key); + if (!EFI_ERROR (Status)) { + break; + } + + // + // If we encounter error, continue to read another key in. + // + if (Status !=3D EFI_NOT_READY) { + continue; + } + gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex); + } + } +} + +/** + Draws a dialog box to the console output device specified by + ConOut defined in the EFI_SYSTEM_TABLE and waits for a keystroke + from the console input device specified by ConIn defined in the + EFI_SYSTEM_TABLE. + + If there are no strings in the variable argument list, then ASSERT(). + If all the strings in the variable argument list are empty, then ASSERT()= . + + @param[in] Attribute Specifies the foreground and background color of= the popup. + @param[out] Key A pointer to the EFI_KEY value of the key that wa= s + pressed. This is an optional parameter that may= be NULL. + If it is NULL then no wait for a keypress will be= performed. + @param[in] ... The variable argument list that contains pointers= to Null- + terminated Unicode strings to display in the dial= og box. + The variable argument list is terminated by a NUL= L. + +**/ +VOID +EFIAPI +UiCreatePopUp ( + IN UINTN Attribute, + OUT EFI_INPUT_KEY *Key, OPTIONAL + ... + ) +{ + VA_LIST Args; + + VA_START (Args, Key); + UiCreatePopUpVaList(Attribute, Key, Args); + VA_END (Args); +} diff --git a/MdePkg/Library/UiLib/UiLib.inf b/MdePkg/Library/UiLib/UiLib.inf new file mode 100644 index 0000000..056b9bf --- /dev/null +++ b/MdePkg/Library/UiLib/UiLib.inf @@ -0,0 +1,38 @@ +## @file +# Instance of UI Library. +# +# The UI Library provides functions that are used to construct UI elements. +# +# Copyright (c) 2016, American Megatrends, Inc. All rights reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BS= D 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 IMP= LIED. +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D UiLib + MODULE_UNI_FILE =3D UiLib.uni + FILE_GUID =3D ffea9b78-9bb6-4ed8-bc61-bcd0a07c3e83 + MODULE_TYPE =3D UEFI_DRIVER + LIBRARY_CLASS =3D UiLib|DXE_CORE DXE_DRIVER DXE_RUNTIME_= DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER SMM_CORE + + +[Sources] + UiLib.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + MemoryAllocationLib + DebugLib + BaseMemoryLib + UefiLib + UefiBootServicesTableLib diff --git a/MdePkg/Library/UiLib/UiLib.uni b/MdePkg/Library/UiLib/UiLib.uni new file mode 100644 index 0000000..87089e7 --- /dev/null +++ b/MdePkg/Library/UiLib/UiLib.uni @@ -0,0 +1,21 @@ +// /** @file +// Instance of UI Library. +// +// The UI Library provides functions that are used to construct UI elements= . +// +// Copyright (c) 2016, American Megatrends, Inc. All rights reserved.
+// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BS= D 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 IMP= LIED. +// +// **/ + + +#string STR_MODULE_ABSTRACT #language en-US "Instance of UI Lib= rary" + +#string STR_MODULE_DESCRIPTION #language en-US "The UI Library pro= vides functions that are used to construct UI elements." + diff --git a/MdePkg/MdePkg.dec b/MdePkg/MdePkg.dec index 3e08bed..a8a0a0f 100644 --- a/MdePkg/MdePkg.dec +++ b/MdePkg/MdePkg.dec @@ -233,6 +233,9 @@ ## @libraryclass provides EFI_FILE_HANDLE services FileHandleLib|Include/Library/FileHandleLib.h + ## @libraryclass provides functions to construct UI elements. + UiLib|Include/Library/CustomizedUiLib.h + [LibraryClasses.IA32, LibraryClasses.X64] ## @libraryclass Abstracts both S/W SMI generation and detection. ## -- 2.10.0.windows.1 Please consider the environment before printing this email. The information contained in this message may be confidential and proprietar= y to American Megatrends, Inc. This communication is intended to be read on= ly by the individual or entity to whom it is addressed or by their designee.= If the reader of this message is not the intended recipient, you are on not= ice that any distribution of this message, in any form, is strictly prohibit= ed. Please promptly notify the sender by reply e-mail or by telephone at 77= 0-246-8600, and then delete or destroy all copies of the transmission.