include/vcl/fmtfield.hxx | 6 +++ include/vcl/uitest/formattedfielduiobject.hxx | 37 ++++++++++++++++++++ vcl/source/control/fmtfield.cxx | 39 +++++++++++++++++++++ vcl/source/uitest/uiobject.cxx | 47 ++++++++++++++++++++++++++ 4 files changed, 129 insertions(+)
New commits: commit b2f67c6839142cf77bea53f6c79e20928b961be9 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Wed May 6 14:06:27 2020 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Sun May 10 18:34:55 2020 +0200 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 <hcas...@collabora.com> diff --git a/include/vcl/fmtfield.hxx b/include/vcl/fmtfield.hxx index 918682e258c6..c61aca9170c1 100644 --- a/include/vcl/fmtfield.hxx +++ b/include/vcl/fmtfield.hxx @@ -119,6 +119,8 @@ public: void SetTextValue(const OUString& rText); // The String is transformed to a double (with a formatter) and SetValue is called afterwards + // + void SetValueFromString(const OUString& rStr); bool IsEmptyFieldEnabled() const { return m_bEnableEmptyField; } void EnableEmptyField(bool bEnable); @@ -235,6 +237,10 @@ public: void UseInputStringForFormatting(); bool IsUsingInputStringForFormatting() const { return m_bUseInputStringForFormatting;} + virtual boost::property_tree::ptree DumpAsPropertyTree() override; + + virtual FactoryFunction GetUITestFactory() const override; + protected: virtual bool EventNotify(NotifyEvent& rNEvt) override; void impl_Modify(bool makeValueDirty = true); diff --git a/include/vcl/uitest/formattedfielduiobject.hxx b/include/vcl/uitest/formattedfielduiobject.hxx new file mode 100644 index 000000000000..2408fe753e1b --- /dev/null +++ b/include/vcl/uitest/formattedfielduiobject.hxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_VCL_UITEST_FORMATTEDFIELDUIOBJECT_HXX +#define INCLUDED_VCL_UITEST_FORMATTEDFIELDUIOBJECT_HXX + +#include <vcl/uitest/uiobject.hxx> + +class FormattedField; + +class UITEST_DLLPUBLIC FormattedFieldUIObject : public SpinFieldUIObject +{ + VclPtr<FormattedField> mxFormattedField; + +public: + FormattedFieldUIObject(const VclPtr<FormattedField>& xEdit); + virtual ~FormattedFieldUIObject() override; + + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +protected: + virtual OUString get_name() const override; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits