diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-08-14 13:43:51 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2018-08-14 22:26:00 +0200 |
commit | 5a56b72413d5f555c854e36d3bd2fd50ec21644c (patch) | |
tree | e1ff1398f766b6c72265457a26d794baa37230b7 | |
parent | 704133f7cb76b29a86d97d776b594c5ebf9a1123 (diff) |
Resolves: tdf#119251 parse non-default units in user inputted values
Change-Id: I28f8338f5c318f2228b742e2e171d53820cb0cc8
Reviewed-on: https://gerrit.libreoffice.org/58985
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | include/vcl/field.hxx | 2 | ||||
-rw-r--r-- | include/vcl/weld.hxx | 2 | ||||
-rw-r--r-- | vcl/source/control/field.cxx | 10 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 11 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 2 |
5 files changed, 21 insertions, 6 deletions
diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx index 8f4bf5b07219..682c136c8a25 100644 --- a/include/vcl/field.hxx +++ b/include/vcl/field.hxx @@ -241,6 +241,8 @@ public: void SetCustomConvertHdl( const Link<MetricFormatter&,void>& rLink ) { maCustomConvertLink = rLink; } static FieldUnit StringToMetric(const OUString &rMetricString); + static bool TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue, sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit); + protected: sal_Int64 mnBaseValue; FieldUnit meUnit; diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 5cb39276ea62..17f2b5119049 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -569,6 +569,7 @@ protected: DECL_LINK(spin_button_value_changed, weld::SpinButton&, void); DECL_LINK(spin_button_output, weld::SpinButton&, void); + DECL_LINK(spin_button_input, int* result, bool); void signal_value_changed() { m_aValueChangedHdl.Call(*this); } @@ -583,6 +584,7 @@ public: { update_width_chars(); m_xSpinButton->connect_output(LINK(this, MetricSpinButton, spin_button_output)); + m_xSpinButton->connect_input(LINK(this, MetricSpinButton, spin_button_input)); m_xSpinButton->connect_value_changed( LINK(this, MetricSpinButton, spin_button_value_changed)); } diff --git a/vcl/source/control/field.cxx b/vcl/source/control/field.cxx index 1ebcfe95e9ad..5401e0300244 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -1314,8 +1314,8 @@ double MetricField::ConvertDoubleValue( double nValue, sal_uInt16 nDigits, return nValue; } -static bool ImplMetricGetValue( const OUString& rStr, double& rValue, sal_Int64 nBaseValue, - sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit ) +bool MetricFormatter::TextToValue(const OUString& rStr, double& rValue, sal_Int64 nBaseValue, + sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper, FieldUnit eUnit) { // Get value sal_Int64 nValue; @@ -1334,7 +1334,7 @@ static bool ImplMetricGetValue( const OUString& rStr, double& rValue, sal_Int64 bool MetricFormatter::ImplMetricReformat( const OUString& rStr, double& rValue, OUString& rOutStr ) { - if ( !ImplMetricGetValue( rStr, rValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) ) + if ( !TextToValue( rStr, rValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ) ) return true; else { @@ -1425,7 +1425,7 @@ sal_Int64 MetricFormatter::GetValueFromStringUnit(const OUString& rStr, FieldUni { double nTempValue; // caution: precision loss in double cast - if (!ImplMetricGetValue(rStr, nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit)) + if (!TextToValue(rStr, nTempValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit)) nTempValue = static_cast<double>(mnLastValue); // caution: precision loss in double cast @@ -1788,7 +1788,7 @@ void MetricBox::InsertValue( sal_Int64 nValue, FieldUnit eInUnit, sal_Int32 nPos sal_Int64 MetricBox::GetValue( sal_Int32 nPos ) const { double nValue = 0; - ImplMetricGetValue( ComboBox::GetEntry( nPos ), nValue, mnBaseValue, + TextToValue( ComboBox::GetEntry( nPos ), nValue, mnBaseValue, GetDecimalDigits(), ImplGetLocaleDataWrapper(), meUnit ); // convert to previously configured units diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index fa0f1dc4ef30..219fb2dcab0b 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -243,6 +243,17 @@ namespace weld return MetricField::ConvertValue(nValue, 0, m_xSpinButton->get_digits(), eInUnit, eOutUnit); } + IMPL_LINK(MetricSpinButton, spin_button_input, int*, result, bool) + { + const SvtSysLocale aSysLocale; + const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); + double fResult(0.0); + bool bRet = MetricFormatter::TextToValue(get_text(), fResult, 0, m_xSpinButton->get_digits(), rLocaleData, m_eSrcUnit); + if (bRet) + *result = fResult; + return bRet; + } + IMPL_LINK_NOARG(TimeSpinButton, spin_button_cursor_position, Entry&, void) { int nStartPos, nEndPos; diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 10610c089b4d..67db66dcdb08 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -3875,7 +3875,7 @@ private: return false; if (eHandled == TRISTATE_TRUE) { - *new_value = result; + *new_value = pThis->toGtk(result); return true; } return GTK_INPUT_ERROR; |