framework/source/uielement/spinfieldtoolbarcontroller.cxx | 6 +- include/vcl/formatter.hxx | 4 - include/vcl/toolkit/longcurr.hxx | 6 -- include/vcl/weldutils.hxx | 6 +- vcl/inc/salvtables.hxx | 2 vcl/source/app/salvtables.cxx | 6 +- vcl/source/control/field2.cxx | 4 - vcl/source/control/fmtfield.cxx | 9 +--- vcl/source/control/longcurr.cxx | 31 +++----------- 9 files changed, 25 insertions(+), 49 deletions(-)
New commits: commit b8249ed9265d34ad0bddc9b3d199fe1553a4a5ec Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Feb 17 18:25:20 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Feb 18 08:59:38 2025 +0100 weld: Let Formatter:m_aInputHdl use double instead of sal_Int64 Switch the param for the out param in Formatter:m_aInputHdl from sal_Int64* to double* and adjust the methods/Links that get set via Formatter::SetInputHdl. Formatter itself otherwise already uses double for its value (and min/max, etc.), so using double here as well is consistent with that. It also matches what SalInstanceSpinButton, one of the classes that uses Formatter internally does since Change-Id: I31bc2b95b46bae8174388cddc9a383ed61e6763e Author: Michael Weghorn <m.wegh...@posteo.de> Date: Mon Feb 17 13:10:16 2025 +0100 tdf#130857 Pass double values to/from weld::SpinButton subclasses Formatter:m_aInputHdl gets used in Formatter::ImplGetValue to convert text into a number. While Formatter:m_aInputHdl was returning sal_Int64 so far, that was already converted to a double value there anyways, depending on the number of digits (s. call to `GetDecimalDigits()`), with basically the same logic that the weld::SpinButton base class does it by now since the above commit (while SalInstanceSpinButton was implementing the logic previously.) Notes on the methods/Links that are being passed via Formatter::SetInputHdl: * SpinfieldControl::ParseInputHdl already had a double value that it was multiplying by the same factor that Formatter::ImplGetValue was earlier then dividing by, so the multiplication there can simply be dropped. * SalInstanceSpinButton now uses weld::convert_value_to_double to get a double value as needed. In an upcoming step, weld::SpinButton::parse_text will be adjusted to also use double right away, as another step to let its subclasses use double directly. (Preparing for this was the main motivation for this commit.) * LongCurrencyFormatter can have decimals and now does the division previously done in Formatter::ImplGetValue to achieve the same result as previously. * DateFormatter and TimeFormatter both use values that don't have any decimals, so the conversion should already have been a no-op (dividing by 1) and therefore doesn't need to be added elswhere. In case anything was missed in a handler here, adding a division by weld::SpinButton::Power10(m_xWidget->GetFormatter().GetDecimalDigits()) as was previously done in Formatter::ImplGetValue should likely fix the issue. Change-Id: Ibc297928f76ac1dab0080c36cef44ddddefab7b8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181804 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/framework/source/uielement/spinfieldtoolbarcontroller.cxx b/framework/source/uielement/spinfieldtoolbarcontroller.cxx index d2e4e6d33252..65ed36e3be9b 100644 --- a/framework/source/uielement/spinfieldtoolbarcontroller.cxx +++ b/framework/source/uielement/spinfieldtoolbarcontroller.cxx @@ -62,7 +62,7 @@ public: DECL_LINK(ValueChangedHdl, weld::FormattedSpinButton&, void); DECL_LINK(FormatOutputHdl, LinkParamNone*, bool); - DECL_LINK(ParseInputHdl, sal_Int64*, TriState); + DECL_LINK(ParseInputHdl, double*, TriState); DECL_LINK(ModifyHdl, weld::Entry&, void); DECL_LINK(ActivateHdl, weld::Entry&, bool); DECL_LINK(FocusInHdl, weld::Widget&, void); @@ -103,9 +103,9 @@ IMPL_LINK(SpinfieldControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool) return ChildKeyInput(rKEvt); } -IMPL_LINK(SpinfieldControl, ParseInputHdl, sal_Int64*, result, TriState) +IMPL_LINK(SpinfieldControl, ParseInputHdl, double*, result, TriState) { - *result = m_xWidget->get_text().toDouble() * weld::SpinButton::Power10(m_xWidget->GetFormatter().GetDecimalDigits()); + *result = m_xWidget->get_text().toDouble(); return TRISTATE_TRUE; } diff --git a/include/vcl/formatter.hxx b/include/vcl/formatter.hxx index 54d6745587e1..cb1665459904 100644 --- a/include/vcl/formatter.hxx +++ b/include/vcl/formatter.hxx @@ -143,7 +143,7 @@ protected: bool m_bUseInputStringForFormatting; - Link<sal_Int64*, TriState> m_aInputHdl; + Link<double*, TriState> m_aInputHdl; Link<LinkParamNone*, bool> m_aOutputHdl; public: @@ -242,7 +242,7 @@ public: bool TreatingAsNumber() const { return m_bTreatAsNumber; } void TreatAsNumber(bool bDoSo) { m_bTreatAsNumber = bDoSo; } - void SetInputHdl(const Link<sal_Int64*,TriState>& rLink) { m_aInputHdl = rLink; } + void SetInputHdl(const Link<double*,TriState>& rLink) { m_aInputHdl = rLink; } void SetOutputHdl(const Link<LinkParamNone*, bool>& rLink) { m_aOutputHdl = rLink; } public: diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index db3a8169001a..dcf7128c2b7f 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -285,7 +285,7 @@ public: private: DECL_DLLPRIVATE_LINK(FormatOutputHdl, LinkParamNone*, bool); - DECL_DLLPRIVATE_LINK(ParseInputHdl, sal_Int64*, TriState); + DECL_DLLPRIVATE_LINK(ParseInputHdl, double*, TriState); SAL_DLLPRIVATE void Init(); @@ -313,7 +313,7 @@ public: private: DECL_DLLPRIVATE_LINK(FormatOutputHdl, LinkParamNone*, bool); - DECL_DLLPRIVATE_LINK(ParseInputHdl, sal_Int64*, TriState); + DECL_DLLPRIVATE_LINK(ParseInputHdl, double*, TriState); DECL_DLLPRIVATE_LINK(CursorChangedHdl, weld::Entry&, void); SAL_DLLPRIVATE void Init(); @@ -346,7 +346,7 @@ public: private: DECL_DLLPRIVATE_LINK(FormatOutputHdl, LinkParamNone*, bool); - DECL_DLLPRIVATE_LINK(ParseInputHdl, sal_Int64*, TriState); + DECL_DLLPRIVATE_LINK(ParseInputHdl, double*, TriState); DECL_DLLPRIVATE_LINK(CursorChangedHdl, weld::Entry&, void); SAL_DLLPRIVATE void Init(); diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx index e26ac2619bcb..66750a2444d9 100644 --- a/vcl/inc/salvtables.hxx +++ b/vcl/inc/salvtables.hxx @@ -681,7 +681,7 @@ private: DECL_LINK(UpDownHdl, SpinField&, void); DECL_LINK(LoseFocusHdl, Control&, void); DECL_LINK(OutputHdl, LinkParamNone*, bool); - DECL_LINK(InputHdl, sal_Int64*, TriState); + DECL_LINK(InputHdl, double*, TriState); DECL_LINK(ActivateHdl, Edit&, bool); public: diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 547f95e44687..e997a64ea8d2 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -5913,7 +5913,7 @@ SalInstanceSpinButton::~SalInstanceSpinButton() pEdit->SetActivateHdl(Link<Edit&, bool>()); else m_xButton->SetActivateHdl(Link<Edit&, bool>()); - m_rFormatter.SetInputHdl(Link<sal_Int64*, TriState>()); + m_rFormatter.SetInputHdl(Link<double*, TriState>()); m_rFormatter.SetOutputHdl(Link<LinkParamNone*, bool>()); m_xButton->SetLoseFocusHdl(Link<Control&, void>()); m_xButton->SetDownHdl(Link<SpinField&, void>()); @@ -5941,12 +5941,12 @@ IMPL_LINK_NOARG(SalInstanceSpinButton, OutputHdl, LinkParamNone*, bool) return true; } -IMPL_LINK(SalInstanceSpinButton, InputHdl, sal_Int64*, pResult, TriState) +IMPL_LINK(SalInstanceSpinButton, InputHdl, double*, pResult, TriState) { int nResult; TriState eRet = parse_text(get_text(), &nResult); if (eRet == TRISTATE_TRUE) - *pResult = nResult; + *pResult = convert_value_to_double(nResult); return eRet; } diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx index f082b08f798d..ac47e1166567 100644 --- a/vcl/source/control/field2.cxx +++ b/vcl/source/control/field2.cxx @@ -2254,7 +2254,7 @@ namespace weld return true; } - IMPL_LINK(DateFormatter, ParseInputHdl, sal_Int64*, result, TriState) + IMPL_LINK(DateFormatter, ParseInputHdl, double*, result, TriState) { const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); @@ -3152,7 +3152,7 @@ namespace weld return true; } - IMPL_LINK(TimeFormatter, ParseInputHdl, sal_Int64*, result, TriState) + IMPL_LINK(TimeFormatter, ParseInputHdl, double*, result, TriState) { const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx index be59ca353e4c..0210f4e8727a 100644 --- a/vcl/source/control/fmtfield.cxx +++ b/vcl/source/control/fmtfield.cxx @@ -793,16 +793,13 @@ bool Formatter::ImplGetValue(double& dNewVal) bool bUseExternalFormatterValue = false; if (m_aInputHdl.IsSet()) { - sal_Int64 nResult; - auto eState = m_aInputHdl.Call(&nResult); + double fResult; + auto eState = m_aInputHdl.Call(&fResult); bUseExternalFormatterValue = eState != TRISTATE_INDET; if (bUseExternalFormatterValue) { if (eState == TRISTATE_TRUE) - { - dNewVal = nResult; - dNewVal /= weld::SpinButton::Power10(GetDecimalDigits()); - } + dNewVal = fResult; else dNewVal = m_dCurrentValue; } diff --git a/vcl/source/control/longcurr.cxx b/vcl/source/control/longcurr.cxx index fc9ed93a2042..39f3e295147a 100644 --- a/vcl/source/control/longcurr.cxx +++ b/vcl/source/control/longcurr.cxx @@ -227,7 +227,7 @@ namespace weld return true; } - IMPL_LINK(LongCurrencyFormatter, ParseInputHdl, sal_Int64*, result, TriState) + IMPL_LINK(LongCurrencyFormatter, ParseInputHdl, double*, result, TriState) { const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); @@ -235,7 +235,7 @@ namespace weld bool bRet = ImplCurrencyGetValue(GetEntryText(), value, GetDecimalDigits(), rLocaleDataWrapper); if (bRet) - *result = double(value); + *result = double(value) / weld::SpinButton::Power10(GetDecimalDigits()); return bRet ? TRISTATE_TRUE : TRISTATE_FALSE; } commit 20970269b70c9a7c0b94dc705ec73c2c326624b9 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Feb 17 16:49:02 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Feb 18 08:59:32 2025 +0100 vcl: Drop ImplLongCurrencyGetValue It was just calling ImplCurrencyGetValue with the same params. Adjust callers do do that right away instead. Change-Id: If13a28fc99734d605d93974e109aa36ff33cb18c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181803 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/vcl/source/control/longcurr.cxx b/vcl/source/control/longcurr.cxx index d9591f493909..fc9ed93a2042 100644 --- a/vcl/source/control/longcurr.cxx +++ b/vcl/source/control/longcurr.cxx @@ -209,12 +209,6 @@ bool ImplCurrencyGetValue( const OUString& rStr, BigInt& rValue, } // namespace -static bool ImplLongCurrencyGetValue( const OUString& rStr, BigInt& rValue, - sal_uInt16 nDecDigits, const LocaleDataWrapper& rLocaleDataWrapper ) -{ - return ImplCurrencyGetValue( rStr, rValue, nDecDigits, rLocaleDataWrapper ); -} - namespace weld { IMPL_LINK_NOARG(LongCurrencyFormatter, FormatOutputHdl, LinkParamNone*, bool) @@ -238,7 +232,7 @@ namespace weld const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper(); BigInt value; - bool bRet = ImplLongCurrencyGetValue(GetEntryText(), value, GetDecimalDigits(), rLocaleDataWrapper); + bool bRet = ImplCurrencyGetValue(GetEntryText(), value, GetDecimalDigits(), rLocaleDataWrapper); if (bRet) *result = double(value); @@ -328,7 +322,7 @@ BigInt LongCurrencyFormatter::GetValue() const return 0; BigInt nTempValue; - if ( ImplLongCurrencyGetValue( GetField()->GetText(), nTempValue, GetDecimalDigits(), GetLocaleDataWrapper() ) ) + if (ImplCurrencyGetValue(GetField()->GetText(), nTempValue, GetDecimalDigits(), GetLocaleDataWrapper())) { if ( nTempValue > mnMax ) nTempValue = mnMax; @@ -358,7 +352,7 @@ void LongCurrencyFormatter::Reformat() { GetField()->SetText( aStr ); MarkToBeReformatted( false ); - ImplLongCurrencyGetValue( aStr, mnLastValue, GetDecimalDigits(), GetLocaleDataWrapper() ); + ImplCurrencyGetValue(aStr, mnLastValue, GetDecimalDigits(), GetLocaleDataWrapper()); } else SetValue( mnLastValue ); commit f7fb355759b2295bba5d6225cabbebae06d4bd7c Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Feb 17 16:45:11 2025 +0100 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Feb 18 08:59:26 2025 +0100 vcl: Drop LongCurrencyFormatter::SetDecimalDigits It's only ever called with a value of 0 from the ctor. Drop the method and LongCurrencyFormatter::mnDecimalDigits and call ReformatAll() in the ctor directly (which was previously called from LongCurrencyFormatter::SetDecimalDigits. Let LongCurrencyFormatter::GetDecimalDigits simply return 0 for now. This could be simplified further to adjust all callers. Note that this class is a different class from weld::LongCurrencyFormatter (defined in include/vcl/weldutils.hxx). Change-Id: I571f2edf79d1e203d5c05acf684a3e50e593f477 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181802 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/toolkit/longcurr.hxx b/include/vcl/toolkit/longcurr.hxx index 3206f39806c8..427274bd4e17 100644 --- a/include/vcl/toolkit/longcurr.hxx +++ b/include/vcl/toolkit/longcurr.hxx @@ -40,8 +40,7 @@ public: OUString const & GetCurrencySymbol() const; - void SetDecimalDigits( sal_uInt16 nDigits ); - sal_uInt16 GetDecimalDigits() const { return mnDecimalDigits;} + static sal_uInt16 GetDecimalDigits() { return 0;} void SetValue(const BigInt& rNewValue); void SetUserValue( BigInt nNewValue ); BigInt GetValue() const; @@ -55,9 +54,6 @@ protected: private: friend bool ImplLongCurrencyReformat( const OUString&, BigInt const &, BigInt const &, sal_uInt16, const LocaleDataWrapper&, OUString&, LongCurrencyFormatter const & ); SAL_DLLPRIVATE void ImpInit(); - - sal_uInt16 mnDecimalDigits; - }; class UNLESS_MERGELIBS(VCL_DLLPUBLIC) LongCurrencyBox final : public ComboBox, public LongCurrencyFormatter diff --git a/vcl/source/control/longcurr.cxx b/vcl/source/control/longcurr.cxx index 96afc509dfa2..d9591f493909 100644 --- a/vcl/source/control/longcurr.cxx +++ b/vcl/source/control/longcurr.cxx @@ -274,8 +274,8 @@ void LongCurrencyFormatter::ImpInit() mnMin = 0; mnMax = 0x7FFFFFFF; mnMax *= 0x7FFFFFFF; - mnDecimalDigits = 0; - SetDecimalDigits( 0 ); + + ReformatAll(); } LongCurrencyFormatter::LongCurrencyFormatter(Edit* pEdit) @@ -369,17 +369,6 @@ void LongCurrencyFormatter::ReformatAll() Reformat(); } -void LongCurrencyFormatter::SetDecimalDigits( sal_uInt16 nDigits ) -{ - if ( nDigits > 9 ) - nDigits = 9; - - mnDecimalDigits = nDigits; - ReformatAll(); -} - - - LongCurrencyBox::LongCurrencyBox(vcl::Window* pParent, WinBits nWinStyle) : ComboBox(pParent, nWinStyle) , LongCurrencyFormatter(this)