]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/BootManagerMenuApp: Limit string drawing within one line
authorZhichao Gao <zhichao.gao@intel.com>
Thu, 9 Sep 2021 06:17:04 +0000 (14:17 +0800)
committerLiming Gao <gaoliming@byosoft.com.cn>
Wed, 29 Sep 2021 01:38:58 +0000 (09:38 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3590

Limit the draw box always within the screen's column and row.
Limit the string drawing within one line.
For the incompleted string the last 3 characters in one line would
be replaced with "...".

Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
Reviewed-by: Ray Ni <ray.ni@intel.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c

index 9e729074ece8152d86f3cd5008a4ddf745879637..d4bdeba07390f1b9d7843fd64030d5ea44473873 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   The application to show the Boot Manager Menu.\r
 \r
-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>\r
 SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -45,9 +45,56 @@ PrintStringAt (
   IN CHAR16    *String\r
   )\r
 {\r
+  UINTN         ScreenWidth;\r
+  UINTN         ScreenRows;\r
+  CHAR16        *TurncateString;\r
+  EFI_STATUS    Status;\r
+  UINTN         ShowingLength;\r
 \r
   gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);\r
-  return Print (L"%s", String);\r
+\r
+  gST->ConOut->QueryMode (\r
+                 gST->ConOut,\r
+                 gST->ConOut->Mode->Mode,\r
+                 &ScreenWidth,\r
+                 &ScreenRows\r
+                 );\r
+\r
+  if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {\r
+    return 0;\r
+  }\r
+\r
+  if ((StrLen (String) + Column) > (ScreenWidth - 1)) {\r
+    //\r
+    // |      - ScreenWidth -       |\r
+    // ...Column.....................\r
+    // TurncateString length should leave one character for draw box and\r
+    // require one character for string end.\r
+    //\r
+    ShowingLength = ScreenWidth - Column - 1;\r
+    TurncateString = AllocatePool ((ShowingLength + 1) * sizeof (CHAR16));\r
+\r
+    if (TurncateString == NULL) {\r
+      return 0;\r
+    }\r
+\r
+    Status = StrnCpyS (TurncateString, ShowingLength + 1, String, ShowingLength - 3);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      FreePool (TurncateString);\r
+      return 0;\r
+    }\r
+\r
+    *(TurncateString + ShowingLength - 3) = L'.';\r
+    *(TurncateString + ShowingLength - 2) = L'.';\r
+    *(TurncateString + ShowingLength - 1) = L'.';\r
+    *(TurncateString + ShowingLength)     = L'\0';\r
+    ShowingLength = Print (L"%s", TurncateString);\r
+    FreePool (TurncateString);\r
+    return ShowingLength;\r
+  } else {\r
+    return Print (L"%s", String);\r
+  }\r
 }\r
 \r
 /**\r
@@ -68,7 +115,22 @@ PrintCharAt (
   CHAR16       Character\r
   )\r
 {\r
+  UINTN         ScreenWidth;\r
+  UINTN         ScreenRows;\r
+\r
   gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);\r
+\r
+  gST->ConOut->QueryMode (\r
+                 gST->ConOut,\r
+                 gST->ConOut->Mode->Mode,\r
+                 &ScreenWidth,\r
+                 &ScreenRows\r
+                 );\r
+\r
+  if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {\r
+    return 0;\r
+  }\r
+\r
   return Print (L"%c", Character);\r
 }\r
 \r
@@ -193,7 +255,11 @@ InitializeBootMenuScreen (
 \r
   MaxPrintRows = Row - 6;\r
   UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;\r
-  BootMenuData->MenuScreen.Width = MaxStrWidth + 8;\r
+  if (MaxStrWidth + 8 > Column) {\r
+    BootMenuData->MenuScreen.Width = Column;\r
+  } else {\r
+    BootMenuData->MenuScreen.Width = MaxStrWidth + 8;\r
+  }\r
   if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {\r
     BootMenuData->MenuScreen.Height = MaxPrintRows;\r
     BootMenuData->ScrollBarControl.HasScrollBar = TRUE;\r