desktop/source/lib/init.cxx | 5 +++++ include/vcl/field.hxx | 3 +++ include/vcl/uitest/uiobject.hxx | 22 +++++++++++++++++++++- vcl/source/control/field.cxx | 22 ++++++++++++++++++++++ vcl/source/uitest/uiobject.cxx | 38 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 89 insertions(+), 1 deletion(-)
New commits: commit 2be52555c2cbf504283addf883ddd5176e1ee457 Author: Henry Castro <hcas...@collabora.com> AuthorDate: Wed Apr 22 18:22:33 2020 -0400 Commit: Henry Castro <hcas...@collabora.com> CommitDate: Thu May 21 00:43:05 2020 +0200 lok: add MetricFieldUIObject class Add new action "VALUE" to set the value number for metric input controls Change-Id: I5058260c2e1562cfc6d10508d5981d185c5f2212 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92738 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Henry Castro <hcas...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94520 Tested-by: Henry Castro <hcas...@collabora.com> diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 34adc76124fd..a11f780b5714 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -3671,6 +3671,11 @@ static void doc_sendDialogEvent(LibreOfficeKitDocument* /*pThis*/, unsigned nWin else bIsClickAction = true; } + else if (aMap["cmd"] == "value") + { + aMap["VALUE"] = aMap["data"]; + pUIWindow->execute(sValue, aMap); + } else bIsClickAction = true; diff --git a/include/vcl/field.hxx b/include/vcl/field.hxx index 3fb2a5468861..b116615488e1 100644 --- a/include/vcl/field.hxx +++ b/include/vcl/field.hxx @@ -154,6 +154,8 @@ public: sal_Int64 Normalize( sal_Int64 nValue ) const; sal_Int64 Denormalize( sal_Int64 nValue ) const; + virtual void SetValueFromString(const OUString& rStr); + protected: sal_Int64 mnFieldValue; sal_Int64 mnLastValue; @@ -518,6 +520,7 @@ public: virtual void dispose() override; virtual boost::property_tree::ptree DumpAsPropertyTree() override; + virtual FactoryFunction GetUITestFactory() const override; }; diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx index 9afbdbc5a3b4..d1377a811f12 100644 --- a/include/vcl/uitest/uiobject.hxx +++ b/include/vcl/uitest/uiobject.hxx @@ -29,6 +29,7 @@ class Edit; class SpinButton; class SpinField; +class MetricField; typedef std::map<const OUString, OUString> StringMap; @@ -359,7 +360,7 @@ private: virtual OUString get_name() const override; }; -class SpinFieldUIObject final : public EditUIObject +class SpinFieldUIObject : public EditUIObject { VclPtr<SpinField> mxSpinField; @@ -382,6 +383,25 @@ private: virtual OUString get_name() const override; }; +class MetricFieldUIObject : public SpinFieldUIObject +{ + VclPtr<MetricField> mxMetricField; + +public: + + MetricFieldUIObject(const VclPtr<MetricField>& xEdit); + virtual ~MetricFieldUIObject() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) 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/field.cxx b/vcl/source/control/field.cxx index d534309ac090..13dac4cc8ac9 100644 --- a/vcl/source/control/field.cxx +++ b/vcl/source/control/field.cxx @@ -31,6 +31,7 @@ #include <vcl/event.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> +#include <vcl/uitest/uiobject.hxx> #include <svdata.hxx> @@ -665,6 +666,22 @@ sal_Int64 NumericFormatter::GetValueFromString(const OUString& rStr) const return mnLastValue; } +// currently used by online +void NumericFormatter::SetValueFromString(const OUString& rStr) +{ + sal_Int64 nValue; + + if (ImplNumericGetValue(rStr, nValue, GetDecimalDigits(), + Application::GetSettings().GetNeutroLocaleDataWrapper())) + { + SetValue(nValue); + } + else + { + SAL_WARN("vcl", "fail to convert the value: " << rStr ); + } +} + sal_Int64 NumericFormatter::GetValue() const { if (mbFormatting) //don't parse the entry if we're currently formatting what to put in it @@ -1780,6 +1797,11 @@ boost::property_tree::ptree MetricField::DumpAsPropertyTree() return aTree; } +FactoryFunction MetricField::GetUITestFactory() const +{ + return MetricFieldUIObject::create; +} + MetricBox::MetricBox(vcl::Window* pParent, WinBits nWinStyle) : ComboBox(pParent, nWinStyle) , MetricFormatter(this) diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx index 95a300416734..2fd1a1b0dcaa 100644 --- a/vcl/source/uitest/uiobject.cxx +++ b/vcl/source/uitest/uiobject.cxx @@ -1287,6 +1287,44 @@ std::unique_ptr<UIObject> SpinFieldUIObject::create(vcl::Window* pWindow) return std::unique_ptr<UIObject>(new SpinFieldUIObject(pSpinField)); } + +MetricFieldUIObject::MetricFieldUIObject(const VclPtr<MetricField>& xMetricField): + SpinFieldUIObject(xMetricField), + mxMetricField(xMetricField) +{ +} + +MetricFieldUIObject::~MetricFieldUIObject() +{ +} + +void MetricFieldUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + if (rAction == "VALUE") + { + auto itPos = rParameters.find("VALUE"); + if (itPos != rParameters.end()) + { + mxMetricField->SetValueFromString(itPos->second); + } + } + else + SpinFieldUIObject::execute(rAction, rParameters); +} + +OUString MetricFieldUIObject::get_name() const +{ + return OUString("MetricFieldUIObject"); +} + +std::unique_ptr<UIObject> MetricFieldUIObject::create(vcl::Window* pWindow) +{ + MetricField* pMetricField = dynamic_cast<MetricField*>(pWindow); + assert(pMetricField); + return std::unique_ptr<UIObject>(new MetricFieldUIObject(pMetricField)); +} + 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