]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkCompatibilityPkg/Compatibility/FrameworkHiiOnUefiHiiThunk/SetupBrowser.c
MdeModulePkg/SdMmcPciHcDxe: Execute card detect only for RemovableSlot
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiOnUefiHiiThunk / SetupBrowser.c
index 807e8396d032948453e85dfee94a6feba19f169e..1a8219ac46a311fa8b1e7b5f4cc1e3290610dde2 100644 (file)
@@ -1,9 +1,9 @@
-/**@file\r
+/** @file\r
 Framework to UEFI 2.1 Setup Browser Thunk. The file consume EFI_FORM_BROWSER2_PROTOCOL\r
 to produce a EFI_FORM_BROWSER_PROTOCOL.\r
 \r
-Copyright (c) 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
@@ -16,7 +16,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include "HiiDatabase.h"\r
 #include "SetupBrowser.h"\r
 \r
-EFI_GUID gFrameworkBdsFrontPageFormsetGuid = FRAMEWORK_BDS_FRONTPAGE_FORMSET_GUID;\r
 EFI_HII_HANDLE gStringPackHandle = NULL;\r
 BOOLEAN mFrontPageDisplayed = FALSE;\r
 //\r
@@ -102,7 +101,7 @@ PlatformBdsShowProgress (
                     (VOID **) &UgaDraw\r
                     );\r
   }\r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (GraphicsOutput == NULL && UgaDraw == NULL)) {\r
     return EFI_UNSUPPORTED;\r
   }\r
 \r
@@ -399,12 +398,17 @@ GetTimeout (
                         current settings and the caller needs to provide to the browser the\r
                         current settings for the the "fake" NV variable. If used, no saving of\r
                         an NV variable is possbile. This parameter is also ignored if Handle is NULL.\r
+  @param ScreenDimensions \r
+                        Allows the browser to be called so that it occupies a portion of the physical \r
+                        screen instead of dynamically determining the screen dimensions.\r
+  @param ResetRequired  This BOOLEAN value denotes whether a reset is required based on the data that \r
+                        might have been changed. The ResetRequired parameter is primarily applicable \r
+                        for configuration applications, and is an optional parameter.\r
 \r
   @retval EFI_SUCCESS             If the Formset is displayed correctly.\r
   @retval EFI_UNSUPPORTED         If UseDatabase is FALSE or HandleCount is not 1.\r
   @retval EFI_INVALID_PARAMETER   If the *Handle passed in is not found in the database.\r
 **/\r
-\r
 EFI_STATUS\r
 EFIAPI \r
 ThunkSendForm (\r
@@ -412,7 +416,7 @@ ThunkSendForm (
   IN  BOOLEAN                           UseDatabase,\r
   IN  FRAMEWORK_EFI_HII_HANDLE          *Handle,\r
   IN  UINTN                             HandleCount,\r
-  IN  FRAMEWORK_EFI_IFR_PACKET          *Packet, OPTIONAL\r
+  IN  EFI_IFR_PACKET                    *Packet, OPTIONAL\r
   IN  EFI_HANDLE                        CallbackHandle, OPTIONAL\r
   IN  UINT8                             *NvMapOverride, OPTIONAL\r
   IN  FRAMEWORK_EFI_SCREEN_DESCRIPTOR   *ScreenDimensions, OPTIONAL\r
@@ -487,14 +491,13 @@ ThunkSendForm (
   Rountine used to display a generic dialog interface and return \r
   the Key or Input from user input.\r
 \r
-  @param NumberOfLines The number of lines for the dialog box.\r
+  @param LinesNumber   The number of lines for the dialog box.\r
   @param HotKey        Defines if a single character is parsed (TRUE) and returned in KeyValue\r
                        or if a string is returned in StringBuffer.\r
   @param MaximumStringSize The maximum size in bytes of a typed-in string.\r
-  @param StringBuffer  On return contains the typed-in string if HotKey\r
-         is FALSE.\r
-  @param KeyValue      The EFI_INPUT_KEY value returned if HotKey is TRUE.\r
-  @param String        The pointer to the first string in the list of strings\r
+  @param StringBuffer  On return contains the typed-in string if HotKey is FALSE.\r
+  @param Key           The EFI_INPUT_KEY value returned if HotKey is TRUE.\r
+  @param FirstString   The pointer to the first string in the list of strings\r
                        that comprise the dialog box.\r
   @param ...           A series of NumberOfLines text strings that will be used\r
                        to construct the dialog box.\r
@@ -505,29 +508,182 @@ ThunkSendForm (
 EFI_STATUS\r
 EFIAPI \r
 ThunkCreatePopUp (\r
-  IN  UINTN                           NumberOfLines,\r
+  IN  UINTN                           LinesNumber,\r
   IN  BOOLEAN                         HotKey,\r
   IN  UINTN                           MaximumStringSize,\r
   OUT CHAR16                          *StringBuffer,\r
-  OUT EFI_INPUT_KEY                   *KeyValue,\r
-  IN  CHAR16                          *String,\r
+  OUT EFI_INPUT_KEY                   *Key,\r
+  IN  CHAR16                          *FirstString,\r
   ...\r
   )\r
 {\r
-  EFI_STATUS                        Status;\r
-  VA_LIST                           Marker;\r
-\r
-  if (HotKey != TRUE) {\r
+  VA_LIST                          Args;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *ConOut;\r
+  EFI_SIMPLE_TEXT_OUTPUT_MODE      SavedConsoleMode;\r
+  UINTN                            Columns;\r
+  UINTN                            Rows;\r
+  UINTN                            Column;\r
+  UINTN                            Row;\r
+  UINTN                            NumberOfLines;\r
+  UINTN                            MaxLength;\r
+  CHAR16                           *String;\r
+  UINTN                            Length;\r
+  CHAR16                           *Line;\r
+  UINTN                            EventIndex;\r
+\r
+  if (!HotKey) {\r
     return EFI_UNSUPPORTED;\r
   }\r
+  \r
+  if (MaximumStringSize == 0) {\r
+    //\r
+    // Blank strint to output\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Determine the length of the longest line in the popup and the the total \r
+  // number of lines in the popup\r
+  //\r
+  MaxLength = StrLen (FirstString);\r
+  NumberOfLines = 1;\r
+  VA_START (Args, FirstString);\r
+  while ((String = VA_ARG (Args, CHAR16 *)) != NULL) {\r
+    MaxLength = MAX (MaxLength, StrLen (String));\r
+    NumberOfLines++;\r
+  }\r
+  VA_END (Args);\r
+\r
+  //\r
+  // If the total number of lines in the popup is not same to the input NumberOfLines\r
+  // the parameter is not valid. Not check.\r
+  //\r
+  //  if (NumberOfLines != LinesNumber) {\r
+  //    return EFI_INVALID_PARAMETER;\r
+  //  }\r
+\r
+  //\r
+  // If the maximum length of all the strings is not same to the input MaximumStringSize\r
+  // the parameter is not valid. Not check.\r
+  //\r
+  // if (MaxLength != MaximumStringSize) {\r
+  //   return EFI_INVALID_PARAMETER;\r
+  // }\r
 \r
-  VA_START (Marker, String);\r
+  //\r
+  // Cache a pointer to the Simple Text Output Protocol in the EFI System Table\r
+  //\r
+  ConOut = gST->ConOut;\r
   \r
-  Status = IfrLibCreatePopUp2 (NumberOfLines, KeyValue, String, Marker);\r
+  //\r
+  // Save the current console cursor position and attributes\r
+  //\r
+  CopyMem (&SavedConsoleMode, ConOut->Mode, sizeof (SavedConsoleMode));\r
+\r
+  //\r
+  // Retrieve the number of columns and rows in the current console mode\r
+  //\r
+  ConOut->QueryMode (ConOut, SavedConsoleMode.Mode, &Columns, &Rows);\r
+\r
+  //\r
+  // Disable cursor and set the foreground and background colors specified by Attribute\r
+  //\r
+  ConOut->EnableCursor (ConOut, FALSE);\r
+  ConOut->SetAttribute (ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE);\r
+\r
+  //\r
+  // Limit NumberOfLines to height of the screen minus 3 rows for the box itself\r
+  //\r
+  NumberOfLines = MIN (NumberOfLines, Rows - 3);\r
+\r
+  //\r
+  // Limit MaxLength to width of the screen minus 2 columns for the box itself\r
+  //\r
+  MaxLength = MIN (MaxLength, Columns - 2);\r
+\r
+  //\r
+  // Compute the starting row and starting column for the popup\r
+  //\r
+  Row    = (Rows - (NumberOfLines + 3)) / 2;\r
+  Column = (Columns - (MaxLength + 2)) / 2;\r
+\r
+  //\r
+  // Allocate a buffer for a single line of the popup with borders and a Null-terminator\r
+  //\r
+  Line = AllocateZeroPool ((MaxLength + 3) * sizeof (CHAR16));\r
+  ASSERT (Line != NULL);\r
+\r
+  //\r
+  // Draw top of popup box   \r
+  //\r
+  SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
+  Line[0]             = BOXDRAW_DOWN_RIGHT;\r
+  Line[MaxLength + 1] = BOXDRAW_DOWN_LEFT;\r
+  Line[MaxLength + 2] = L'\0';\r
+  ConOut->SetCursorPosition (ConOut, Column, Row++);\r
+  ConOut->OutputString (ConOut, Line);\r
+\r
+  //\r
+  // Draw middle of the popup with strings\r
+  //\r
+  VA_START (Args, FirstString);\r
+  String = FirstString;\r
+  while ((String != NULL) && (NumberOfLines > 0)) {\r
+    Length = StrLen (String);\r
+    SetMem16 (Line, (MaxLength + 2) * 2, L' ');\r
+    if (Length <= MaxLength) {\r
+      //\r
+      // Length <= MaxLength\r
+      //\r
+      CopyMem (Line + 1 + (MaxLength - Length) / 2, String , Length * sizeof (CHAR16));\r
+    } else {\r
+      //\r
+      // Length > MaxLength\r
+      //\r
+      CopyMem (Line + 1, String + (Length - MaxLength) / 2 , MaxLength * sizeof (CHAR16));\r
+    }\r
+    Line[0]             = BOXDRAW_VERTICAL;\r
+    Line[MaxLength + 1] = BOXDRAW_VERTICAL;\r
+    Line[MaxLength + 2] = L'\0';\r
+    ConOut->SetCursorPosition (ConOut, Column, Row++);\r
+    ConOut->OutputString (ConOut, Line);\r
+    String = VA_ARG (Args, CHAR16 *);\r
+    NumberOfLines--;\r
+  }\r
+  VA_END (Args);\r
+\r
+  //\r
+  // Draw bottom of popup box\r
+  //\r
+  SetMem16 (Line, (MaxLength + 2) * 2, BOXDRAW_HORIZONTAL);\r
+  Line[0]             = BOXDRAW_UP_RIGHT;\r
+  Line[MaxLength + 1] = BOXDRAW_UP_LEFT;\r
+  Line[MaxLength + 2] = L'\0';\r
+  ConOut->SetCursorPosition (ConOut, Column, Row++);\r
+  ConOut->OutputString (ConOut, Line);\r
+\r
+  //\r
+  // Free the allocated line buffer\r
+  //\r
+  FreePool (Line);\r
 \r
-  VA_END (Marker);\r
+  //\r
+  // Restore the cursor visibility, position, and attributes\r
+  //\r
+  ConOut->EnableCursor      (ConOut, SavedConsoleMode.CursorVisible);\r
+  ConOut->SetCursorPosition (ConOut, SavedConsoleMode.CursorColumn, SavedConsoleMode.CursorRow);\r
+  ConOut->SetAttribute      (ConOut, SavedConsoleMode.Attribute);\r
+\r
+  //\r
+  // Wait for a keystroke\r
+  //\r
+  if (Key != NULL) {\r
+    gBS->WaitForEvent (1, &gST->ConIn->WaitForKey, &EventIndex);\r
+    gST->ConIn->ReadKeyStroke (gST->ConIn, Key);\r
+  }\r
   \r
-  return Status;\r
+  return EFI_SUCCESS;\r
 }\r
 \r
 /** \r