Related: tdf#122780 skip GetTextWidth() when we don't need the result
Change-Id: I1919d3da162e05ea6fec6269a53344b0625338e9
Reviewed-on: https://gerrit.libreoffice.org/67174
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index f15daa8..bd5c6c8 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -1131,14 +1131,19 @@
void Edit::ImplAlign()
{
if (mnAlign == EDIT_ALIGN_LEFT && !mnXOffset)
{
// short circuit common case and avoid slow GetTextWidth() calc
return;
}
long nTextWidth = GetTextWidth( ImplGetText() );
long nOutWidth = GetOutputSizePixel().Width();
if ( mnAlign == EDIT_ALIGN_LEFT )
{
if( mnXOffset && ( nTextWidth < nOutWidth ) )
if (nTextWidth < nOutWidth)
mnXOffset = 0;
}
else if ( mnAlign == EDIT_ALIGN_RIGHT )
{
@@ -1161,8 +1166,8 @@
}
else if( mnAlign == EDIT_ALIGN_CENTER )
{
// would be nicer with check while scrolling but then it's not centred in scrolled state
mnXOffset = (nOutWidth - nTextWidth) / 2;
// would be nicer with check while scrolling but then it's not centred in scrolled state
mnXOffset = (nOutWidth - nTextWidth) / 2;
}
}