summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2025-02-18 20:29:20 +0100
committerMichael Weghorn <m.weghorn@posteo.de>2025-02-19 22:41:50 +0100
commit20e1c3d2f35afba1adf0e5852a83a753efaf500d (patch)
tree6dbd565cac229da1929384f419b73cd2d50ee4ca /vcl
parentf310b47ead5bf4a85a1c93d15b3c5f78f6675f7a (diff)
tdf#130857 Let Formatter:m_aOutputHdl convert double to text
So far, the Formatter:m_aOutputHdl output handler set via Formatter::SetOutputHdl did not receive any parameter and had the responsibility to set the text based on the current value, i.e. first retrieve the current value, then convert it to a text representation, and then set that text in the formatter. Change semantics so that the method instead receives the (double) value to format as a parameter and returns the formatted string. Passing the current value as a double and using the returned string to update the text is now the responsibility of the only caller, Formatter::ImplSetValue. Adjust the naming accordingly: * Formatter:m_aOutputHdl -> Formatter::m_aFormatValueHdl * Formatter::SetOutputHdl -> Formatter::SetFormatValueHdl This is similar to the change done elsewhere in commit 76396a371eb7dfef79963d00fea54a989f54fbbc Author: Michael Weghorn <m.weghorn@posteo.de> Date: Sat Feb 15 13:44:50 2025 +0100 tdf#130857 weld: Abstract from "input"/"output" SpinButton signals (and changes referenced from its commit message) and is one step towards supporting value <-> text conversion in QtInstanceFormattedSpinButton as well. No change in behavior is intended by this commit. Change-Id: I6b3fbccc89b89446a1ea367a80aeed3a7b583298 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181911 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/salvtables.hxx2
-rw-r--r--vcl/source/app/salvtables.cxx13
-rw-r--r--vcl/source/app/weldutils.cxx6
-rw-r--r--vcl/source/control/field2.cxx12
-rw-r--r--vcl/source/control/fmtfield.cxx13
-rw-r--r--vcl/source/control/longcurr.cxx6
6 files changed, 24 insertions, 28 deletions
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 19b292e500ab..5be5314157c9 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -680,7 +680,7 @@ protected:
private:
DECL_LINK(UpDownHdl, SpinField&, void);
DECL_LINK(LoseFocusHdl, Control&, void);
- DECL_LINK(OutputHdl, LinkParamNone*, bool);
+ DECL_LINK(OutputHdl, double, std::optional<OUString>);
DECL_LINK(InputHdl, double*, TriState);
DECL_LINK(ActivateHdl, Edit&, bool);
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index ca2078879c26..89c024ab220d 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -5855,7 +5855,7 @@ SalInstanceSpinButton::SalInstanceSpinButton(FormattedField* pButton, SalInstanc
m_xButton->SetUpHdl(LINK(this, SalInstanceSpinButton, UpDownHdl));
m_xButton->SetDownHdl(LINK(this, SalInstanceSpinButton, UpDownHdl));
m_xButton->SetLoseFocusHdl(LINK(this, SalInstanceSpinButton, LoseFocusHdl));
- m_rFormatter.SetOutputHdl(LINK(this, SalInstanceSpinButton, OutputHdl));
+ m_rFormatter.SetFormatValueHdl(LINK(this, SalInstanceSpinButton, OutputHdl));
m_rFormatter.SetInputHdl(LINK(this, SalInstanceSpinButton, InputHdl));
if (Edit* pEdit = m_xButton->GetSubEdit())
pEdit->SetActivateHdl(LINK(this, SalInstanceSpinButton, ActivateHdl));
@@ -5914,7 +5914,7 @@ SalInstanceSpinButton::~SalInstanceSpinButton()
else
m_xButton->SetActivateHdl(Link<Edit&, bool>());
m_rFormatter.SetInputHdl(Link<double*, TriState>());
- m_rFormatter.SetOutputHdl(Link<LinkParamNone*, bool>());
+ m_rFormatter.SetFormatValueHdl(Link<double, std::optional<OUString>>());
m_xButton->SetLoseFocusHdl(Link<Control&, void>());
m_xButton->SetDownHdl(Link<SpinField&, void>());
m_xButton->SetUpHdl(Link<SpinField&, void>());
@@ -5931,14 +5931,9 @@ IMPL_LINK_NOARG(SalInstanceSpinButton, UpDownHdl, SpinField&, void) { signal_val
IMPL_LINK_NOARG(SalInstanceSpinButton, LoseFocusHdl, Control&, void) { signal_value_changed(); }
-IMPL_LINK_NOARG(SalInstanceSpinButton, OutputHdl, LinkParamNone*, bool)
+IMPL_LINK(SalInstanceSpinButton, OutputHdl, double, fValue, std::optional<OUString>)
{
- std::optional<OUString> aText = format_floating_point_value(get_floating_point_value());
- if (!aText.has_value())
- return false;
-
- set_text(aText.value());
- return true;
+ return format_floating_point_value(fValue);
}
IMPL_LINK(SalInstanceSpinButton, InputHdl, double*, pResult, TriState)
diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx
index 9cc759dcdf12..92b421757e1e 100644
--- a/vcl/source/app/weldutils.cxx
+++ b/vcl/source/app/weldutils.cxx
@@ -317,7 +317,7 @@ LongCurrencyFormatter::LongCurrencyFormatter(weld::FormattedSpinButton& rSpinBut
void LongCurrencyFormatter::Init()
{
- SetOutputHdl(LINK(this, LongCurrencyFormatter, FormatOutputHdl));
+ SetFormatValueHdl(LINK(this, LongCurrencyFormatter, FormatOutputHdl));
SetInputHdl(LINK(this, LongCurrencyFormatter, ParseInputHdl));
}
@@ -357,7 +357,7 @@ void TimeFormatter::Init()
{
DisableRemainderFactor(); //so with hh::mm::ss, incrementing mm will not reset ss
- SetOutputHdl(LINK(this, TimeFormatter, FormatOutputHdl));
+ SetFormatValueHdl(LINK(this, TimeFormatter, FormatOutputHdl));
SetInputHdl(LINK(this, TimeFormatter, ParseInputHdl));
SetMin(tools::Time(0, 0));
@@ -441,7 +441,7 @@ DateFormatter::DateFormatter(weld::Entry& rEntry)
void DateFormatter::Init()
{
- SetOutputHdl(LINK(this, DateFormatter, FormatOutputHdl));
+ SetFormatValueHdl(LINK(this, DateFormatter, FormatOutputHdl));
SetInputHdl(LINK(this, DateFormatter, ParseInputHdl));
SetMin(Date(1, 1, 1900));
diff --git a/vcl/source/control/field2.cxx b/vcl/source/control/field2.cxx
index ac47e1166567..fc0cab000da8 100644
--- a/vcl/source/control/field2.cxx
+++ b/vcl/source/control/field2.cxx
@@ -2247,11 +2247,9 @@ namespace weld
return ::DateFormatter::FormatDate(Date(nValue), m_eFormat, rLocaleData, m_aStaticFormatter);
}
- IMPL_LINK_NOARG(DateFormatter, FormatOutputHdl, LinkParamNone*, bool)
+ IMPL_LINK(DateFormatter, FormatOutputHdl, double, fValue, std::optional<OUString>)
{
- OUString sText = FormatNumber(GetValue());
- ImplSetTextImpl(sText, nullptr);
- return true;
+ return std::optional<OUString>(FormatNumber(fValue));
}
IMPL_LINK(DateFormatter, ParseInputHdl, double*, result, TriState)
@@ -3145,11 +3143,9 @@ namespace weld
return ::TimeFormatter::FormatTime(ConvertValue(nValue), m_eFormat, m_eTimeFormat, m_bDuration, rLocaleData);
}
- IMPL_LINK_NOARG(TimeFormatter, FormatOutputHdl, LinkParamNone*, bool)
+ IMPL_LINK(TimeFormatter, FormatOutputHdl, double, fValue, std::optional<OUString>)
{
- OUString sText = FormatNumber(GetValue());
- ImplSetTextImpl(sText, nullptr);
- return true;
+ return std::optional<OUString>(FormatNumber(fValue));
}
IMPL_LINK(TimeFormatter, ParseInputHdl, double*, result, TriState)
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index 0210f4e8727a..3dc7f1ac9a29 100644
--- a/vcl/source/control/fmtfield.cxx
+++ b/vcl/source/control/fmtfield.cxx
@@ -746,7 +746,11 @@ void Formatter::ImplSetValue(double dVal, bool bForce)
m_ValueState = valueDouble;
UpdateCurrentValue(dVal);
- if (!m_aOutputHdl.IsSet() || !m_aOutputHdl.Call(nullptr))
+ std::optional<OUString> aText;
+ if (m_aFormatValueHdl.IsSet())
+ aText = m_aFormatValueHdl.Call(dVal);
+
+ if (!aText.has_value())
{
OUString sNewText;
if (GetOrCreateFormatter()->IsTextFormat(m_nFormatKey))
@@ -768,10 +772,13 @@ void Formatter::ImplSetValue(double dVal, bool bForce)
GetOrCreateFormatter()->GetOutputString(dVal, m_nFormatKey, sNewText, &m_pLastOutputColor);
}
}
- ImplSetTextImpl(sNewText, nullptr);
- DBG_ASSERT(CheckText(sNewText), "FormattedField::ImplSetValue : formatted string doesn't match the criteria !");
+ aText = sNewText;
}
+ assert(aText.has_value());
+ ImplSetTextImpl(*aText, nullptr);
+ DBG_ASSERT(CheckText(*aText), "FormattedField::ImplSetValue : formatted string doesn't match the criteria !");
+
m_ValueState = valueDouble;
}
diff --git a/vcl/source/control/longcurr.cxx b/vcl/source/control/longcurr.cxx
index 39f3e295147a..a1698afb1f90 100644
--- a/vcl/source/control/longcurr.cxx
+++ b/vcl/source/control/longcurr.cxx
@@ -211,11 +211,10 @@ bool ImplCurrencyGetValue( const OUString& rStr, BigInt& rValue,
namespace weld
{
- IMPL_LINK_NOARG(LongCurrencyFormatter, FormatOutputHdl, LinkParamNone*, bool)
+ IMPL_LINK(LongCurrencyFormatter, FormatOutputHdl, double, fValue, std::optional<OUString>)
{
const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
const OUString& rCurrencySymbol = !m_aCurrencySymbol.isEmpty() ? m_aCurrencySymbol : rLocaleDataWrapper.getCurrSymbol();
- double fValue = GetValue();
sal_uInt16 nDecimalDigits = GetDecimalDigits();
if (nDecimalDigits)
{
@@ -223,8 +222,7 @@ namespace weld
fValue = std::round(fValue * weld::SpinButton::Power10(nDecimalDigits));
}
OUString aText = ImplGetCurr(rLocaleDataWrapper, fValue, GetDecimalDigits(), rCurrencySymbol, m_bThousandSep);
- ImplSetTextImpl(aText, nullptr);
- return true;
+ return std::optional<OUString>(aText);
}
IMPL_LINK(LongCurrencyFormatter, ParseInputHdl, double*, result, TriState)