include/vcl/weld.hxx | 13 +++++++++++++ vcl/source/app/salvtables.cxx | 39 +++++++++++++++++++++++++++++++++++++++ vcl/unx/gtk3/gtk3gtkinst.cxx | 17 +++++++++++++++++ 3 files changed, 69 insertions(+)
New commits: commit bda370031e669d4a9b19d0a8247da0db230ebf00 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Fri Jun 26 11:22:46 2020 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Jun 26 15:18:39 2020 +0200 extend FormattedSpinButton to allow custom input/output Change-Id: Ie84c1d46bc6fa3e29ed97147de486911dc6ecc0c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/97217 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index fe03d0ed3958..05d5eeeb50d4 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -1588,6 +1588,8 @@ class VCL_DLLPUBLIC FormattedSpinButton : virtual public Entry { protected: Link<FormattedSpinButton&, void> m_aValueChangedHdl; + Link<FormattedSpinButton&, void> m_aOutputHdl; + Link<double*, bool> m_aInputHdl; void signal_value_changed() { m_aValueChangedHdl.Call(*this); } @@ -1596,6 +1598,14 @@ public: virtual double get_value() const = 0; virtual void set_range(double min, double max) = 0; virtual void get_range(double& min, double& max) const = 0; + virtual void set_increments(double step, double page) = 0; + + void set_min(double min) + { + double max, dummy; + get_range(dummy, max); + set_range(min, max); + } void set_max(double max) { @@ -1617,6 +1627,9 @@ public: { m_aValueChangedHdl = rLink; } + + void connect_output(const Link<FormattedSpinButton&, void>& rLink) { m_aOutputHdl = rLink; } + void connect_input(const Link<double*, bool>& rLink) { m_aInputHdl = rLink; } }; class VCL_DLLPUBLIC Image : virtual public Widget diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index f395d5240182..6a299156b404 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -5317,12 +5317,18 @@ class SalInstanceFormattedSpinButton : public SalInstanceEntry, private: VclPtr<FormattedField> m_xButton; + DECL_LINK(OutputHdl, Edit&, bool); + DECL_LINK(InputHdl, sal_Int64*, TriState); + public: SalInstanceFormattedSpinButton(FormattedField* pButton, SalInstanceBuilder* pBuilder, bool bTakeOwnership) : SalInstanceEntry(pButton, pBuilder, bTakeOwnership) , m_xButton(pButton) { + m_xButton->SetOutputHdl(LINK(this, SalInstanceFormattedSpinButton, OutputHdl)); + m_xButton->SetInputHdl(LINK(this, SalInstanceFormattedSpinButton, InputHdl)); + // #i6278# allow more decimal places than the output format. As // the numbers shown in the edit fields are used for input, it makes more // sense to display the values in the input format rather than the output @@ -5330,6 +5336,12 @@ public: m_xButton->UseInputStringForFormatting(); } + virtual ~SalInstanceFormattedSpinButton() override + { + m_xButton->SetInputHdl(Link<sal_Int64*, TriState>()); + m_xButton->SetOutputHdl(Link<Edit&, bool>()); + } + virtual double get_value() const override { return m_xButton->GetValue(); } virtual void set_value(double value) override { m_xButton->SetValue(value); } @@ -5346,6 +5358,11 @@ public: max = m_xButton->GetMaxValue(); } + virtual void set_increments(double step, double /*page*/) override + { + m_xButton->SetSpinSize(step); + } + virtual void set_formatter(SvNumberFormatter* pFormatter) override { m_xButton->SetFormatter(pFormatter); @@ -5365,6 +5382,28 @@ public: virtual void set_digits(unsigned int digits) override { m_xButton->SetDecimalDigits(digits); } }; +IMPL_LINK_NOARG(SalInstanceFormattedSpinButton, OutputHdl, Edit&, bool) +{ + // allow an explicit handler + if (!m_aOutputHdl.IsSet()) + return false; + m_aOutputHdl.Call(*this); + return true; +} + +IMPL_LINK(SalInstanceFormattedSpinButton, InputHdl, sal_Int64*, pResult, TriState) +{ + // allow an explicit handler + if (!m_aInputHdl.IsSet()) + return TRISTATE_INDET; + + double value; + TriState eRet = m_aInputHdl.Call(&value) ? TRISTATE_TRUE : TRISTATE_FALSE; + if (eRet == TRISTATE_TRUE) + *pResult = std::round(value * weld::SpinButton::Power10(m_xButton->GetDecimalDigits())); + return eRet; +} + } SalInstanceLabel::SalInstanceLabel(Control* pLabel, SalInstanceBuilder* pBuilder, diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 7270e3e21be5..804fa0ec7df3 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -12128,6 +12128,12 @@ private: bool signal_output() { + // allow an explicit handler + if (m_aOutputHdl.IsSet()) + { + m_aOutputHdl.Call(*this); + return true; + } if (!m_pFormatter) return false; double dVal = get_value(); @@ -12157,6 +12163,10 @@ private: gint signal_input(double* value) { + // allow an explicit handler + if (m_aInputHdl.IsSet()) + return m_aInputHdl.Call(value) ? 1 : GTK_INPUT_ERROR; + if (!m_pFormatter) return 0; @@ -12244,6 +12254,13 @@ public: gtk_spin_button_get_range(m_pButton, &min, &max); } + virtual void set_increments(double step, double page) override + { + disable_notify_events(); + gtk_spin_button_set_increments(m_pButton, step, page); + enable_notify_events(); + } + virtual void set_formatter(SvNumberFormatter* pFormatter) override { m_pFormatter = pFormatter; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits