diff options
author | Henry Castro <hcastro@collabora.com> | 2020-05-06 14:06:27 -0400 |
---|---|---|
committer | Henry Castro <hcastro@collabora.com> | 2020-05-10 18:34:55 +0200 |
commit | b2f67c6839142cf77bea53f6c79e20928b961be9 (patch) | |
tree | 24569d76c5680680e62d9248fa48476fe1d85f15 /vcl | |
parent | 701f62c023e7a8febe3f9d7294d0ca2bec8a13bc (diff) |
lok: add FormattedFieldUIObject class
Required by mobile device to set "VALUE" number
Change-Id: Ie18fa3c58b8ba107917a8b12a7b98c74a385975c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93585
Tested-by: Jenkins
Reviewed-by: Henry Castro <hcastro@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/control/fmtfield.cxx | 39 | ||||
-rw-r--r-- | vcl/source/uitest/uiobject.cxx | 47 |
2 files changed, 86 insertions, 0 deletions
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx index 07b2d4e63713..ba50e98f4c11 100644 --- a/vcl/source/control/fmtfield.cxx +++ b/vcl/source/control/fmtfield.cxx @@ -18,6 +18,7 @@ */ #include <tools/debug.hxx> +#include <boost/property_tree/json_parser.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/string.hxx> #include <unotools/localedatawrapper.hxx> @@ -27,6 +28,8 @@ #include <vcl/commandevent.hxx> #include <svl/zformat.hxx> #include <vcl/fmtfield.hxx> +#include <vcl/uitest/uiobject.hxx> +#include <vcl/uitest/formattedfielduiobject.hxx> #include <vcl/weld.hxx> #include <i18nlangtag/languagetag.hxx> #include <unotools/syslocale.hxx> @@ -833,6 +836,24 @@ void FormattedField::SetTextValue(const OUString& rText) ReFormat(); } +// currently used by online +void FormattedField::SetValueFromString(const OUString& rStr) +{ + sal_Int32 nEnd; + rtl_math_ConversionStatus eStatus; + double fValue = ::rtl::math::stringToDouble(rStr, '.', GetDecimalDigits(), &eStatus, &nEnd ); + + if (eStatus == rtl_math_ConversionStatus_Ok && + nEnd == rStr.getLength()) + { + SetValue(fValue); + } + else + { + SAL_WARN("vcl", "fail to convert the value: " << rStr); + } +} + void FormattedField::EnableEmptyField(bool bEnable) { if (bEnable == m_bEnableEmptyField) @@ -1065,6 +1086,24 @@ void FormattedField::UseInputStringForFormatting() m_bUseInputStringForFormatting = true; } +boost::property_tree::ptree FormattedField::DumpAsPropertyTree() +{ + boost::property_tree::ptree aTree(SpinField::DumpAsPropertyTree()); + aTree.put("min", rtl::math::doubleToString(GetMinValue(), + rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr()); + aTree.put("max", rtl::math::doubleToString(GetMaxValue(), + rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr()); + aTree.put("value", rtl::math::doubleToString(GetValue(), + rtl_math_StringFormat_F, GetDecimalDigits(), '.').getStr()); + + return aTree; +} + +FactoryFunction FormattedField::GetUITestFactory() const +{ + return FormattedFieldUIObject::create; +} + DoubleNumericField::DoubleNumericField(vcl::Window* pParent, WinBits nStyle) : FormattedField(pParent, nStyle) { diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx index d4a7855bcf97..4dde9aa09874 100644 --- a/vcl/source/uitest/uiobject.cxx +++ b/vcl/source/uitest/uiobject.cxx @@ -9,6 +9,7 @@ #include <vcl/uitest/uiobject.hxx> #include <vcl/uitest/metricfielduiobject.hxx> +#include <vcl/uitest/formattedfielduiobject.hxx> #include <vcl/svapp.hxx> #include <vcl/combobox.hxx> @@ -18,6 +19,7 @@ #include <vcl/tabctrl.hxx> #include <vcl/lstbox.hxx> #include <vcl/toolkit/spin.hxx> +#include <vcl/fmtfield.hxx> #include <vcl/spinfld.hxx> #include <vcl/toolkit/button.hxx> #include <vcl/toolkit/dialog.hxx> @@ -1338,6 +1340,51 @@ std::unique_ptr<UIObject> MetricFieldUIObject::create(vcl::Window* pWindow) return std::unique_ptr<UIObject>(new MetricFieldUIObject(pMetricField)); } +FormattedFieldUIObject::FormattedFieldUIObject(const VclPtr<FormattedField>& xFormattedField): + SpinFieldUIObject(xFormattedField), + mxFormattedField(xFormattedField) +{ +} + +FormattedFieldUIObject::~FormattedFieldUIObject() +{ +} + +void FormattedFieldUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + if (rAction == "VALUE") + { + auto itPos = rParameters.find("VALUE"); + if (itPos != rParameters.end()) + { + mxFormattedField->SetValueFromString(itPos->second); + } + } + else + SpinFieldUIObject::execute(rAction, rParameters); +} + +StringMap FormattedFieldUIObject::get_state() +{ + StringMap aMap = EditUIObject::get_state(); + aMap["Value"] = OUString::number(mxFormattedField->GetValue()); + + return aMap; +} + +OUString FormattedFieldUIObject::get_name() const +{ + return "FormattedFieldUIObject"; +} + +std::unique_ptr<UIObject> FormattedFieldUIObject::create(vcl::Window* pWindow) +{ + FormattedField* pFormattedField = dynamic_cast<FormattedField*>(pWindow); + assert(pFormattedField); + return std::unique_ptr<UIObject>(new FormattedFieldUIObject(pFormattedField)); +} + TabControlUIObject::TabControlUIObject(const VclPtr<TabControl>& xTabControl): WindowUIObject(xTabControl), mxTabControl(xTabControl) |