[PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit string drawing within one line


Gao, Zhichao
 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3590

Limit the draw box always within the screen's column and row.
Limit the string drawing within one line.

Change-Id: Ib7bd63cb07b23875a1e4f37ae80a422e1d5ed54f
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>
---=0D
V2:=0D
Drop the change in UefiBootManagerLib in V1.=0D
Add the limitation in BootManagerMenuApp instead.=0D

.../BootManagerMenuApp/BootManagerMenu.c | 72 ++++++++++++++++++-
1 file changed, 69 insertions(+), 3 deletions(-)

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


Ni, Ray
 

I remember that HII can tell the width of a string.
Have you evaluated using HII? +@Bi, Dandan

-----Original Message-----
From: Gao, Zhichao <zhichao.gao@intel.com>
Sent: Thursday, September 9, 2021 3:26 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit string drawing within one line

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.

Change-Id: Ib7bd63cb07b23875a1e4f37ae80a422e1d5ed54f
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>
---

V2:

Drop the change in UefiBootManagerLib in V1.

Add the limitation in BootManagerMenuApp instead.


.../BootManagerMenuApp/BootManagerMenu.c | 72 ++++++++++++++++++-
1 file changed, 69 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
index 9e729074ec..d4bdeba073 100644
--- a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
+++ b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
@@ -1,7 +1,7 @@
/** @file

The application to show the Boot Manager Menu.



-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -45,9 +45,56 @@ PrintStringAt (
IN CHAR16 *String

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+ CHAR16 *TurncateString;

+ EFI_STATUS Status;

+ UINTN ShowingLength;



gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

- return Print (L"%s", String);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

+ if ((StrLen (String) + Column) > (ScreenWidth - 1)) {

+ //

+ // | - ScreenWidth - |

+ // ...Column.....................

+ // TurncateString length should leave one character for draw box and

+ // require one character for string end.

+ //

+ ShowingLength = ScreenWidth - Column - 1;

+ TurncateString = AllocatePool ((ShowingLength + 1) * sizeof (CHAR16));

+

+ if (TurncateString == NULL) {

+ return 0;

+ }

+

+ Status = StrnCpyS (TurncateString, ShowingLength + 1, String, ShowingLength - 3);

+

+ if (EFI_ERROR (Status)) {

+ FreePool (TurncateString);

+ return 0;

+ }

+

+ *(TurncateString + ShowingLength - 3) = L'.';

+ *(TurncateString + ShowingLength - 2) = L'.';

+ *(TurncateString + ShowingLength - 1) = L'.';

+ *(TurncateString + ShowingLength) = L'\0';

+ ShowingLength = Print (L"%s", TurncateString);

+ FreePool (TurncateString);

+ return ShowingLength;

+ } else {

+ return Print (L"%s", String);

+ }

}



/**

@@ -68,7 +115,22 @@ PrintCharAt (
CHAR16 Character

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+

gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

return Print (L"%c", Character);

}



@@ -193,7 +255,11 @@ InitializeBootMenuScreen (


MaxPrintRows = Row - 6;

UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;

- BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ if (MaxStrWidth + 8 > Column) {

+ BootMenuData->MenuScreen.Width = Column;

+ } else {

+ BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ }

if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {

BootMenuData->MenuScreen.Height = MaxPrintRows;

BootMenuData->ScrollBarControl.HasScrollBar = TRUE;

--
2.31.1.windows.1


Gao, Zhichao
 

No. My point is the HII usage would require the HII browser engine. That's too complex for this simple app.

Dandan,
If I am wrong, please help to correct.

Thanks,
Zhichao

-----Original Message-----
From: Ni, Ray <ray.ni@intel.com>
Sent: Thursday, September 9, 2021 10:55 PM
To: Gao, Zhichao <zhichao.gao@intel.com>; Bi, Dandan
<dandan.bi@intel.com>
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; devel@edk2.groups.io
Subject: RE: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit
string drawing within one line

I remember that HII can tell the width of a string.
Have you evaluated using HII? +@Bi, Dandan

-----Original Message-----
From: Gao, Zhichao <zhichao.gao@intel.com>
Sent: Thursday, September 9, 2021 3:26 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit string
drawing within one line

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.

Change-Id: Ib7bd63cb07b23875a1e4f37ae80a422e1d5ed54f
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>
---

V2:

Drop the change in UefiBootManagerLib in V1.

Add the limitation in BootManagerMenuApp instead.


.../BootManagerMenuApp/BootManagerMenu.c | 72
++++++++++++++++++-
1 file changed, 69 insertions(+), 3 deletions(-)

diff --git
a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
index 9e729074ec..d4bdeba073 100644
---
a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
+++
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
@@ -1,7 +1,7 @@
/** @file

The application to show the Boot Manager Menu.



-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -45,9 +45,56 @@ PrintStringAt (
IN CHAR16 *String

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+ CHAR16 *TurncateString;

+ EFI_STATUS Status;

+ UINTN ShowingLength;



gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

- return Print (L"%s", String);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

+ if ((StrLen (String) + Column) > (ScreenWidth - 1)) {

+ //

+ // | - ScreenWidth - |

+ // ...Column.....................

+ // TurncateString length should leave one character for draw box and

+ // require one character for string end.

+ //

+ ShowingLength = ScreenWidth - Column - 1;

+ TurncateString = AllocatePool ((ShowingLength + 1) * sizeof (CHAR16));

+

+ if (TurncateString == NULL) {

+ return 0;

+ }

+

+ Status = StrnCpyS (TurncateString, ShowingLength + 1, String,
ShowingLength - 3);

+

+ if (EFI_ERROR (Status)) {

+ FreePool (TurncateString);

+ return 0;

+ }

+

+ *(TurncateString + ShowingLength - 3) = L'.';

+ *(TurncateString + ShowingLength - 2) = L'.';

+ *(TurncateString + ShowingLength - 1) = L'.';

+ *(TurncateString + ShowingLength) = L'\0';

+ ShowingLength = Print (L"%s", TurncateString);

+ FreePool (TurncateString);

+ return ShowingLength;

+ } else {

+ return Print (L"%s", String);

+ }

}



/**

@@ -68,7 +115,22 @@ PrintCharAt (
CHAR16 Character

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+

gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

return Print (L"%c", Character);

}



@@ -193,7 +255,11 @@ InitializeBootMenuScreen (


MaxPrintRows = Row - 6;

UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT +
2;

- BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ if (MaxStrWidth + 8 > Column) {

+ BootMenuData->MenuScreen.Width = Column;

+ } else {

+ BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ }

if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {

BootMenuData->MenuScreen.Height = MaxPrintRows;

BootMenuData->ScrollBarControl.HasScrollBar = TRUE;

--
2.31.1.windows.1


Gao, Zhichao
 

Can we make a decision on this issue?

Thanks,
Zhichao

-----Original Message-----
From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Gao,
Zhichao
Sent: Friday, September 10, 2021 2:20 PM
To: Ni, Ray <ray.ni@intel.com>; Bi, Dandan <dandan.bi@intel.com>
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; devel@edk2.groups.io
Subject: Re: [edk2-devel] [PATCH V2]
MdeModulePkg/BootManagerMenuApp: Limit string drawing within one line

No. My point is the HII usage would require the HII browser engine. That's
too complex for this simple app.

Dandan,
If I am wrong, please help to correct.

Thanks,
Zhichao

-----Original Message-----
From: Ni, Ray <ray.ni@intel.com>
Sent: Thursday, September 9, 2021 10:55 PM
To: Gao, Zhichao <zhichao.gao@intel.com>; Bi, Dandan
<dandan.bi@intel.com>
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; devel@edk2.groups.io
Subject: RE: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit
string
drawing within one line

I remember that HII can tell the width of a string.
Have you evaluated using HII? +@Bi, Dandan

-----Original Message-----
From: Gao, Zhichao <zhichao.gao@intel.com>
Sent: Thursday, September 9, 2021 3:26 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit
string
drawing within one line

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.

Change-Id: Ib7bd63cb07b23875a1e4f37ae80a422e1d5ed54f
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>
---

V2:

Drop the change in UefiBootManagerLib in V1.

Add the limitation in BootManagerMenuApp instead.


.../BootManagerMenuApp/BootManagerMenu.c | 72
++++++++++++++++++-
1 file changed, 69 insertions(+), 3 deletions(-)

diff --git
a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
index 9e729074ec..d4bdeba073 100644
---
a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
+++
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
@@ -1,7 +1,7 @@
/** @file

The application to show the Boot Manager Menu.



-Copyright (c) 2011 - 2018, Intel Corporation. All rights
reserved.<BR>

+Copyright (c) 2011 - 2021, Intel Corporation. All rights
+reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -45,9 +45,56 @@ PrintStringAt (
IN CHAR16 *String

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+ CHAR16 *TurncateString;

+ EFI_STATUS Status;

+ UINTN ShowingLength;



gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

- return Print (L"%s", String);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

+ if ((StrLen (String) + Column) > (ScreenWidth - 1)) {

+ //

+ // | - ScreenWidth - |

+ // ...Column.....................

+ // TurncateString length should leave one character for draw
+ box and

+ // require one character for string end.

+ //

+ ShowingLength = ScreenWidth - Column - 1;

+ TurncateString = AllocatePool ((ShowingLength + 1) * sizeof
+ (CHAR16));

+

+ if (TurncateString == NULL) {

+ return 0;

+ }

+

+ Status = StrnCpyS (TurncateString, ShowingLength + 1, String,
ShowingLength - 3);

+

+ if (EFI_ERROR (Status)) {

+ FreePool (TurncateString);

+ return 0;

+ }

+

+ *(TurncateString + ShowingLength - 3) = L'.';

+ *(TurncateString + ShowingLength - 2) = L'.';

+ *(TurncateString + ShowingLength - 1) = L'.';

+ *(TurncateString + ShowingLength) = L'\0';

+ ShowingLength = Print (L"%s", TurncateString);

+ FreePool (TurncateString);

+ return ShowingLength;

+ } else {

+ return Print (L"%s", String);

+ }

}



/**

@@ -68,7 +115,22 @@ PrintCharAt (
CHAR16 Character

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+

gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

return Print (L"%c", Character);

}



@@ -193,7 +255,11 @@ InitializeBootMenuScreen (


MaxPrintRows = Row - 6;

UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT
+
2;

- BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ if (MaxStrWidth + 8 > Column) {

+ BootMenuData->MenuScreen.Width = Column;

+ } else {

+ BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ }

if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {

BootMenuData->MenuScreen.Height = MaxPrintRows;

BootMenuData->ScrollBarControl.HasScrollBar = TRUE;

--
2.31.1.windows.1





Ni, Ray
 

Reviewed-by: Ray Ni <ray.ni@intel.com>

-----Original Message-----
From: Gao, Zhichao <zhichao.gao@intel.com>
Sent: Thursday, September 9, 2021 3:26 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit string drawing within one line

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.

Change-Id: Ib7bd63cb07b23875a1e4f37ae80a422e1d5ed54f
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>
---

V2:

Drop the change in UefiBootManagerLib in V1.

Add the limitation in BootManagerMenuApp instead.


.../BootManagerMenuApp/BootManagerMenu.c | 72 ++++++++++++++++++-
1 file changed, 69 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
index 9e729074ec..d4bdeba073 100644
--- a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
+++ b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.c
@@ -1,7 +1,7 @@
/** @file

The application to show the Boot Manager Menu.



-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -45,9 +45,56 @@ PrintStringAt (
IN CHAR16 *String

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+ CHAR16 *TurncateString;

+ EFI_STATUS Status;

+ UINTN ShowingLength;



gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

- return Print (L"%s", String);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

+ if ((StrLen (String) + Column) > (ScreenWidth - 1)) {

+ //

+ // | - ScreenWidth - |

+ // ...Column.....................

+ // TurncateString length should leave one character for draw box and

+ // require one character for string end.

+ //

+ ShowingLength = ScreenWidth - Column - 1;

+ TurncateString = AllocatePool ((ShowingLength + 1) * sizeof (CHAR16));

+

+ if (TurncateString == NULL) {

+ return 0;

+ }

+

+ Status = StrnCpyS (TurncateString, ShowingLength + 1, String, ShowingLength - 3);

+

+ if (EFI_ERROR (Status)) {

+ FreePool (TurncateString);

+ return 0;

+ }

+

+ *(TurncateString + ShowingLength - 3) = L'.';

+ *(TurncateString + ShowingLength - 2) = L'.';

+ *(TurncateString + ShowingLength - 1) = L'.';

+ *(TurncateString + ShowingLength) = L'\0';

+ ShowingLength = Print (L"%s", TurncateString);

+ FreePool (TurncateString);

+ return ShowingLength;

+ } else {

+ return Print (L"%s", String);

+ }

}



/**

@@ -68,7 +115,22 @@ PrintCharAt (
CHAR16 Character

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+

gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

return Print (L"%c", Character);

}



@@ -193,7 +255,11 @@ InitializeBootMenuScreen (


MaxPrintRows = Row - 6;

UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;

- BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ if (MaxStrWidth + 8 > Column) {

+ BootMenuData->MenuScreen.Width = Column;

+ } else {

+ BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ }

if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {

BootMenuData->MenuScreen.Height = MaxPrintRows;

BootMenuData->ScrollBarControl.HasScrollBar = TRUE;

--
2.31.1.windows.1


Gao, Zhichao
 

Hi Liming,

The solution is different with the first time we discussed on the Bugzilla. Can you review if it is OK to you?

Thanks,
Zhichao

-----Original Message-----
From: Ni, Ray <ray.ni@intel.com>
Sent: Wednesday, September 22, 2021 11:28 AM
To: Gao, Zhichao <zhichao.gao@intel.com>; devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>
Subject: RE: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit
string drawing within one line

Reviewed-by: Ray Ni <ray.ni@intel.com>

-----Original Message-----
From: Gao, Zhichao <zhichao.gao@intel.com>
Sent: Thursday, September 9, 2021 3:26 PM
To: devel@edk2.groups.io
Cc: Wang, Jian J <jian.j.wang@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; Ni, Ray <ray.ni@intel.com>
Subject: [PATCH V2] MdeModulePkg/BootManagerMenuApp: Limit string
drawing within one line

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.

Change-Id: Ib7bd63cb07b23875a1e4f37ae80a422e1d5ed54f
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>
---

V2:

Drop the change in UefiBootManagerLib in V1.

Add the limitation in BootManagerMenuApp instead.


.../BootManagerMenuApp/BootManagerMenu.c | 72
++++++++++++++++++-
1 file changed, 69 insertions(+), 3 deletions(-)

diff --git
a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
index 9e729074ec..d4bdeba073 100644
---
a/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
+++
b/MdeModulePkg/Application/BootManagerMenuApp/BootManagerMenu.
c
@@ -1,7 +1,7 @@
/** @file

The application to show the Boot Manager Menu.



-Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<BR>

+Copyright (c) 2011 - 2021, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent



**/

@@ -45,9 +45,56 @@ PrintStringAt (
IN CHAR16 *String

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+ CHAR16 *TurncateString;

+ EFI_STATUS Status;

+ UINTN ShowingLength;



gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

- return Print (L"%s", String);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

+ if ((StrLen (String) + Column) > (ScreenWidth - 1)) {

+ //

+ // | - ScreenWidth - |

+ // ...Column.....................

+ // TurncateString length should leave one character for draw box and

+ // require one character for string end.

+ //

+ ShowingLength = ScreenWidth - Column - 1;

+ TurncateString = AllocatePool ((ShowingLength + 1) * sizeof (CHAR16));

+

+ if (TurncateString == NULL) {

+ return 0;

+ }

+

+ Status = StrnCpyS (TurncateString, ShowingLength + 1, String,
ShowingLength - 3);

+

+ if (EFI_ERROR (Status)) {

+ FreePool (TurncateString);

+ return 0;

+ }

+

+ *(TurncateString + ShowingLength - 3) = L'.';

+ *(TurncateString + ShowingLength - 2) = L'.';

+ *(TurncateString + ShowingLength - 1) = L'.';

+ *(TurncateString + ShowingLength) = L'\0';

+ ShowingLength = Print (L"%s", TurncateString);

+ FreePool (TurncateString);

+ return ShowingLength;

+ } else {

+ return Print (L"%s", String);

+ }

}



/**

@@ -68,7 +115,22 @@ PrintCharAt (
CHAR16 Character

)

{

+ UINTN ScreenWidth;

+ UINTN ScreenRows;

+

gST->ConOut->SetCursorPosition (gST->ConOut, Column, Row);

+

+ gST->ConOut->QueryMode (

+ gST->ConOut,

+ gST->ConOut->Mode->Mode,

+ &ScreenWidth,

+ &ScreenRows

+ );

+

+ if (Column > (ScreenWidth - 1) || Row > (ScreenRows - 1)) {

+ return 0;

+ }

+

return Print (L"%c", Character);

}



@@ -193,7 +255,11 @@ InitializeBootMenuScreen (


MaxPrintRows = Row - 6;

UnSelectableItmes = TITLE_TOKEN_COUNT + 2 + HELP_TOKEN_COUNT + 2;

- BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ if (MaxStrWidth + 8 > Column) {

+ BootMenuData->MenuScreen.Width = Column;

+ } else {

+ BootMenuData->MenuScreen.Width = MaxStrWidth + 8;

+ }

if (BootMenuData->ItemCount + UnSelectableItmes > MaxPrintRows) {

BootMenuData->MenuScreen.Height = MaxPrintRows;

BootMenuData->ScrollBarControl.HasScrollBar = TRUE;

--
2.31.1.windows.1