include/vcl/fmtfield.hxx        |    6 +++++
 include/vcl/uitest/uiobject.hxx |   18 +++++++++++++++
 vcl/source/control/fmtfield.cxx |   38 ++++++++++++++++++++++++++++++++
 vcl/source/uitest/uiobject.cxx  |   47 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+)

New commits:
commit a56cbb4fedbb918ab2bc483099c3ffad6c5487b6
Author:     Henry Castro <hcas...@collabora.com>
AuthorDate: Wed May 6 14:06:27 2020 -0400
Commit:     Henry Castro <hcas...@collabora.com>
CommitDate: Thu May 21 00:45:49 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>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94525
    Tested-by: Henry Castro <hcas...@collabora.com>

diff --git a/include/vcl/fmtfield.hxx b/include/vcl/fmtfield.hxx
index f8e5e210416e..8637209add00 100644
--- a/include/vcl/fmtfield.hxx
+++ b/include/vcl/fmtfield.hxx
@@ -118,6 +118,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);
@@ -234,6 +236,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/uiobject.hxx b/include/vcl/uitest/uiobject.hxx
index 03d45ba59051..43035e2fa39e 100644
--- a/include/vcl/uitest/uiobject.hxx
+++ b/include/vcl/uitest/uiobject.hxx
@@ -404,6 +404,24 @@ protected:
     virtual OUString get_name() const override;
 };
 
+class 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;
+};
+
 class TabControlUIObject final : public WindowUIObject
 {
 private:
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index 30c29d5796b2..65c25ba83c6f 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,7 @@
 #include <vcl/commandevent.hxx>
 #include <svl/zformat.hxx>
 #include <vcl/fmtfield.hxx>
+#include <vcl/uitest/uiobject.hxx>
 #include <vcl/weld.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <unotools/syslocale.hxx>
@@ -829,6 +831,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)
@@ -1061,6 +1081,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 a7bb1ae2e288..f2361fad3965 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -14,6 +14,8 @@
 #include <vcl/lstbox.hxx>
 #include <vcl/combobox.hxx>
 #include <vcl/toolkit/spin.hxx>
+#include <vcl/field.hxx>
+#include <vcl/fmtfield.hxx>
 #include <vcl/spinfld.hxx>
 #include <vcl/button.hxx>
 #include <vcl/dialog.hxx>
@@ -1333,6 +1335,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

Reply via email to