summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/app/salvtables.cxx76
-rw-r--r--vcl/source/app/weldutils.cxx76
-rw-r--r--vcl/source/control/fmtfield.cxx17
3 files changed, 96 insertions, 73 deletions
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 22b8329cb9f5..f646beb64d9a 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -65,6 +65,7 @@
#include <vcl/toolkit/throbber.hxx>
#include <vcl/toolkit/unowrap.hxx>
#include <vcl/weld.hxx>
+#include <vcl/weldutils.hxx>
#include <vcl/vclmedit.hxx>
#include <vcl/viewdataentry.hxx>
#include <vcl/virdev.hxx>
@@ -5325,96 +5326,41 @@ class SalInstanceFormattedSpinButton : public SalInstanceEntry,
{
private:
VclPtr<FormattedField> m_xButton;
- Formatter* m_pFormatter;
-
- DECL_LINK(OutputHdl, LinkParamNone*, bool);
- DECL_LINK(InputHdl, sal_Int64*, TriState);
public:
SalInstanceFormattedSpinButton(FormattedField* pButton, SalInstanceBuilder* pBuilder,
bool bTakeOwnership)
: SalInstanceEntry(pButton, pBuilder, bTakeOwnership)
, m_xButton(pButton)
- , m_pFormatter(m_xButton->GetFormatter())
- {
- m_pFormatter->SetOutputHdl(LINK(this, SalInstanceFormattedSpinButton, OutputHdl));
- m_pFormatter->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
- // format.
- m_pFormatter->UseInputStringForFormatting();
- }
-
- virtual ~SalInstanceFormattedSpinButton() override
{
- m_pFormatter->SetInputHdl(Link<sal_Int64*, TriState>());
- m_pFormatter->SetOutputHdl(Link<LinkParamNone*, bool>());
}
- virtual double get_value() const override { return m_pFormatter->GetValue(); }
-
- virtual void set_value(double value) override { m_pFormatter->SetValue(value); }
-
- virtual void set_range(double min, double max) override
+ virtual void SetFormatter(weld::EntryFormatter* pFormatter) override
{
- m_pFormatter->SetMinValue(min);
- m_pFormatter->SetMaxValue(max);
+ m_xButton->SetFormatter(pFormatter);
}
- virtual void get_range(double& min, double& max) const override
+ virtual void sync_value_from_formatter() override
{
- min = m_pFormatter->GetMinValue();
- max = m_pFormatter->GetMaxValue();
+ // no-op for gen
}
- virtual void set_increments(double step, double /*page*/) override
+ virtual void sync_range_from_formatter() override
{
- m_pFormatter->SetSpinSize(step);
+ // no-op for gen
}
- virtual void set_formatter(SvNumberFormatter* pFormatter) override
+ virtual void sync_increments_from_formatter() override
{
- m_pFormatter->SetFormatter(pFormatter);
+ // no-op for gen
}
- virtual SvNumberFormatter* get_formatter() override { return m_pFormatter->GetFormatter(); }
-
- virtual sal_Int32 get_format_key() const override { return m_pFormatter->GetFormatKey(); }
-
- virtual void set_format_key(sal_Int32 nFormatKey) override
+ virtual Formatter& GetFormatter() override
{
- m_pFormatter->SetFormatKey(nFormatKey);
+ return *m_xButton->GetFormatter();
}
-
- virtual void treat_as_number(bool bSet) override { m_pFormatter->TreatAsNumber(bSet); }
-
- virtual void set_digits(unsigned int digits) override { m_pFormatter->SetDecimalDigits(digits); }
};
-IMPL_LINK_NOARG(SalInstanceFormattedSpinButton, OutputHdl, LinkParamNone*, 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_pFormatter->GetDecimalDigits()));
- return eRet;
-}
-
}
SalInstanceLabel::SalInstanceLabel(Control* pLabel, SalInstanceBuilder* pBuilder,
diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx
index d9d237cef5c4..f560923e5609 100644
--- a/vcl/source/app/weldutils.cxx
+++ b/vcl/source/app/weldutils.cxx
@@ -125,10 +125,30 @@ void RemoveParentKeepChildren(weld::TreeView& rTreeView, weld::TreeIter& rParent
rTreeView.remove(rParent);
}
+EntryFormatter::EntryFormatter(weld::FormattedSpinButton& rSpinButton)
+ : m_rEntry(rSpinButton)
+ , m_pSpinButton(&rSpinButton)
+ , m_eOptions(Application::GetSettings().GetStyleSettings().GetSelectionOptions())
+{
+ Init();
+}
+
EntryFormatter::EntryFormatter(weld::Entry& rEntry)
: m_rEntry(rEntry)
+ , m_pSpinButton(nullptr)
, m_eOptions(Application::GetSettings().GetStyleSettings().GetSelectionOptions())
{
+ Init();
+}
+
+EntryFormatter::~EntryFormatter()
+{
+ m_rEntry.connect_changed(Link<weld::Entry&, void>());
+ m_rEntry.connect_focus_out(Link<weld::Widget&, void>());
+}
+
+void EntryFormatter::Init()
+{
m_rEntry.connect_changed(LINK(this, EntryFormatter, ModifyHdl));
m_rEntry.connect_focus_out(LINK(this, EntryFormatter, FocusOutHdl));
}
@@ -155,13 +175,65 @@ void EntryFormatter::SetEntryTextColor(const Color* pColor)
m_rEntry.set_font_color(pColor ? *pColor : COL_AUTO);
}
+void EntryFormatter::UpdateCurrentValue(double dCurrentValue)
+{
+ Formatter::UpdateCurrentValue(dCurrentValue);
+ if (m_pSpinButton)
+ m_pSpinButton->sync_value_from_formatter();
+}
+
+void EntryFormatter::ClearMinValue()
+{
+ Formatter::ClearMinValue();
+ if (m_pSpinButton)
+ m_pSpinButton->sync_range_from_formatter();
+}
+
+void EntryFormatter::SetMinValue(double dMin)
+{
+ Formatter::SetMinValue(dMin);
+ if (m_pSpinButton)
+ m_pSpinButton->sync_range_from_formatter();
+}
+
+void EntryFormatter::ClearMaxValue()
+{
+ Formatter::ClearMaxValue();
+ if (m_pSpinButton)
+ m_pSpinButton->sync_range_from_formatter();
+}
+
+void EntryFormatter::SetMaxValue(double dMin)
+{
+ Formatter::SetMaxValue(dMin);
+ if (m_pSpinButton)
+ m_pSpinButton->sync_range_from_formatter();
+}
+
+void EntryFormatter::SetSpinSize(double dStep)
+{
+ Formatter::SetSpinSize(dStep);
+ if (m_pSpinButton)
+ m_pSpinButton->sync_increments_from_formatter();
+}
+
SelectionOptions EntryFormatter::GetEntrySelectionOptions() const { return m_eOptions; }
void EntryFormatter::FieldModified() { m_aModifyHdl.Call(m_rEntry); }
-IMPL_LINK_NOARG(EntryFormatter, ModifyHdl, weld::Entry&, void) { Modify(); }
+IMPL_LINK_NOARG(EntryFormatter, ModifyHdl, weld::Entry&, void)
+{
+ // This leads to FieldModified getting called at the end of Modify() and
+ // FieldModified then calls any modification callback
+ Modify();
+}
+
+IMPL_LINK_NOARG(EntryFormatter, FocusOutHdl, weld::Widget&, void)
+{
+ EntryLostFocus();
+ m_aFocusOutHdl.Call(m_rEntry);
+}
-IMPL_LINK_NOARG(EntryFormatter, FocusOutHdl, weld::Widget&, void) { EntryLostFocus(); }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index d67b0b9ba792..5f1cb134b9d4 100644
--- a/vcl/source/control/fmtfield.cxx
+++ b/vcl/source/control/fmtfield.cxx
@@ -699,7 +699,6 @@ void Formatter::ReFormat()
}
}
-
void Formatter::SetMinValue(double dMin)
{
DBG_ASSERT(m_bTreatAsNumber, "FormattedField::SetMinValue : only to be used in numeric mode !");
@@ -754,7 +753,7 @@ void Formatter::ImplSetValue(double dVal, bool bForce)
DBG_ASSERT(GetOrCreateFormatter() != nullptr, "FormattedField::ImplSetValue : can't set a value without a formatter !");
m_ValueState = valueDouble;
- m_dCurrentValue = dVal;
+ UpdateCurrentValue(dVal);
if (!m_aOutputHdl.IsSet() || !m_aOutputHdl.Call(nullptr))
{
@@ -860,13 +859,14 @@ void Formatter::SetValue(double dVal)
double Formatter::GetValue()
{
-
if ( !ImplGetValue( m_dCurrentValue ) )
{
- if ( m_bEnableNaN )
- ::rtl::math::setNan( &m_dCurrentValue );
+ double dValue;
+ if (m_bEnableNaN)
+ ::rtl::math::setNan(&dValue);
else
- m_dCurrentValue = m_dDefaultValue;
+ dValue = m_dDefaultValue;
+ UpdateCurrentValue(dValue);
}
m_ValueState = valueDouble;
@@ -1308,6 +1308,11 @@ Formatter* FormattedField::GetFormatter()
return m_xFormatter.get();
}
+void FormattedField::SetFormatter(Formatter* pFormatter)
+{
+ m_xFormatter.reset(pFormatter);
+}
+
// currently used by online
void FormattedField::SetValueFromString(const OUString& rStr)
{