summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-06-17 23:32:04 -0400
committerAndras Timar <andras.timar@collabora.com>2019-09-03 13:44:22 +0200
commite9a48869fe1f1e90c03d299ae419ea5b1f43de50 (patch)
tree60e467b9b8479f7cb2f93c54d02f4636db55554b /vcl
parent2cd1ac593a3a47f7331d161fd113417c97313a01 (diff)
vcl: better decimal handling in NumericFormatter
When the user deletes the decimal point from MetricBox, it ends up with the number with the fractional portion (to the right of the decimal point) appended to it, which is (with two decimal points) a 100x larger value. This makes such editing smarter. In the case that we detect that the user deleted the decimal point (which we know should've been there, because we have a configured fixed number of decimal points,) we restore it. This makes it more intuitive, since when the user enters digits, they get the correct and expected result, but when they delete the decimal point, they almost always didn't mean to grow the number 100x. If that was the goal, they could enter two extra digits before the decimal point. In addition, we set the default maximum to a more user-friendly value of a million, instead of int-max, which seems like a random number to the uninitiated. Change-Id: Ib535f06e4f111d20f35c4209ad65969dca5928e8 Reviewed-on: https://gerrit.libreoffice.org/75511 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Jan Holesovsky <kendy@collabora.com> (cherry picked from commit 42761c688053155ae87628e69eb4d2a28e6c78e6) Reviewed-on: https://gerrit.libreoffice.org/78453 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/field.cxx25
1 files changed, 24 insertions, 1 deletions
diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx
index 59220ac21258..bbbdbceb86e4 100644
--- a/vcl/source/control/field.cxx
+++ b/vcl/source/control/field.cxx
@@ -131,6 +131,29 @@ bool ImplNumericGetValue( const OUString& rStr, sal_Int64& rValue,
aStr1.appendCopy(aStr, 0, nDecPos);
aStr2.appendCopy(aStr, nDecPos+1);
}
+ else if (nDecDigits > 0 && aStr.getLength() > nDecDigits)
+ {
+ // We expect a decimal point and a certain number of decimal digits,
+ // but seems the user has deleted the decimal point, so we restore it.
+ // Otherwise, they end up with unexpectedly (to them) large numbers.
+
+ // Find the first digit from the right.
+ sal_Int32 nVirtualDecPos = aStr.getLength();
+ while (--nVirtualDecPos > 0)
+ {
+ if ((aStr[nVirtualDecPos] >= '0') && (aStr[nVirtualDecPos] <= '9'))
+ break;
+ }
+
+ if (nVirtualDecPos >= nDecDigits)
+ {
+ nVirtualDecPos -= nDecDigits - 1; // nVirtualDecPos is already on a digit (so discount it).
+ aStr1.append(aStr.getStr(), nVirtualDecPos);
+ aStr2.append(aStr.getStr() + nVirtualDecPos);
+ }
+ else
+ aStr1 = aStr;
+ }
else
aStr1 = aStr;
@@ -470,7 +493,7 @@ void NumericFormatter::ImplInit()
mnFieldValue = 0;
mnLastValue = 0;
mnMin = 0;
- mnMax = SAL_MAX_INT32;
+ mnMax = 100000000; // A user-friendly round number.
// a "large" value substantially smaller than SAL_MAX_INT64, to avoid
// overflow in computations using this "dummy" value
mnDecimalDigits = 2;