summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2020-05-06 14:06:27 -0400
committerHenry Castro <hcastro@collabora.com>2020-05-09 14:39:28 +0200
commit3e325cfd1fa58b63ee2606de792b2560eaa43b24 (patch)
treede6513de190a4c4d80a0ab5ca82e1a1a4c812853 /vcl
parentfe36f2133981fe7dc7b75873b3880f57ffdad574 (diff)
lok: add FormattedFieldUIObject class
Required by mobile device to set "VALUE" number Change-Id: Ie18fa3c58b8ba107917a8b12a7b98c74a385975c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93777 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Henry Castro <hcastro@collabora.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/control/fmtfield.cxx38
-rw-r--r--vcl/source/uitest/uiobject.cxx46
2 files changed, 84 insertions, 0 deletions
diff --git a/vcl/source/control/fmtfield.cxx b/vcl/source/control/fmtfield.cxx
index 1f502e3102db..4014e0ebd1e5 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 <com/sun/star/lang/Locale.hpp>
@@ -836,6 +838,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 c32a118017cb..efbf8e06dcf4 100644
--- a/vcl/source/uitest/uiobject.cxx
+++ b/vcl/source/uitest/uiobject.cxx
@@ -14,6 +14,7 @@
#include <vcl/lstbox.hxx>
#include <vcl/combobox.hxx>
#include <vcl/spin.hxx>
+#include <vcl/fmtfield.hxx>
#include <vcl/spinfld.hxx>
#include <vcl/button.hxx>
#include <vcl/dialog.hxx>
@@ -1251,6 +1252,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)