summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2020-08-26 13:12:21 +0200
committerLászló Németh <nemeth@numbertext.org>2020-08-27 09:19:19 +0200
commit947b7357cc2bb0bd591e4519fa43c4b4bc3cbf2a (patch)
tree06eb350fc32fadb55451e2a09adf0457c5803356 /sw
parent3e6f5176bf433a3f1b543b3bb9fc10d6ad72545f (diff)
tdf#123354 sw: add table formula ABS
for DOCX interoperability. See also commit e1aea22f3f4fbf0cc412a8867165a85a3c55f49c (tdf#123354 DOCX import: fix ABS formula). Change-Id: I8633ff4d4727a1e7a596312cdd62e87c07cbe730 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101402 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/calc.hxx3
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf123354.fodt40
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport15.cxx20
-rw-r--r--sw/source/core/bastyp/calc.cxx8
-rw-r--r--sw/uiconfig/swriter/ui/inputwinmenu.ui14
5 files changed, 83 insertions, 2 deletions
diff --git a/sw/inc/calc.hxx b/sw/inc/calc.hxx
index 41b3cd0a8cec..99c024bcac35 100644
--- a/sw/inc/calc.hxx
+++ b/sw/inc/calc.hxx
@@ -55,7 +55,7 @@ enum SwCalcOper
CALC_ACOS=278, CALC_ATAN=279, CALC_TDIF=280,
CALC_ROUND=281, CALC_DATE=282, CALC_MONTH=283,
CALC_DAY=284, CALC_PRODUCT=285, CALC_AVERAGE=286,
- CALC_COUNT=287, CALC_SIGN=288
+ CALC_COUNT=287, CALC_SIGN=288, CALC_ABS=289
};
// Calculate Operations Strings
@@ -92,6 +92,7 @@ extern const char sCalc_Atan[];
extern const char sCalc_Round[];
extern const char sCalc_Date[];
extern const char sCalc_Sign[];
+extern const char sCalc_Abs[];
// Calculate ErrorCodes
enum class SwCalcError
diff --git a/sw/qa/extras/ooxmlexport/data/tdf123354.fodt b/sw/qa/extras/ooxmlexport/data/tdf123354.fodt
new file mode 100644
index 000000000000..5e75b212957e
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf123354.fodt
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:officeooo="http://openoffice.org/2009/office" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" xmlns:ooow="http://openoffice.org/2004/writer" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:styles>
+ <style:style style:name="Standard" style:family="paragraph" style:class="text"/>
+ <style:default-style style:family="paragraph">
+ <style:text-properties fo:language="en" fo:country="US"/>
+ </style:default-style>
+ </office:styles>
+ <office:body>
+ <office:text>
+ <table:table>
+ <table:table-column/>
+ <table:table-column/>
+ <table:table-column/>
+ <table:table-row>
+ <table:table-cell office:value-type="string">
+ <text:p>-10</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string">
+ <text:p>0</text:p>
+ </table:table-cell>
+ <table:table-cell office:value-type="string">
+ <text:p>10</text:p>
+ </table:table-cell>
+ </table:table-row>
+ <table:table-row>
+ <table:table-cell table:formula="ooow:ABS(&lt;A1&gt;)" office:value-type="float" office:value="10">
+ <text:p>10</text:p>
+ </table:table-cell>
+ <table:table-cell table:formula="ooow:ABS(&lt;B1&gt;)" office:value-type="float" office:value="10">
+ <text:p>0</text:p>
+ </table:table-cell>
+ <table:table-cell table:formula="ooow:ABS(&lt;C1&gt;)" office:value-type="float" office:value="0">
+ <text:p>10</text:p>
+ </table:table-cell>
+ </table:table-row>
+ </table:table>
+ </office:text>
+ </office:body>
+</office:document>
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
index e46f99e0c3e9..e78e7fba8179 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx
@@ -139,6 +139,26 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123390, "tdf123390.fodt")
CPPUNIT_ASSERT_EQUAL(OUString("0"), xEnumerationAccess3->getPresentation(false).trim());
}
+DECLARE_OOXMLEXPORT_TEST(testTdf123354, "tdf123354.fodt")
+{
+ uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
+ uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
+
+ // Tests new cell formula SIGN
+ uno::Reference<text::XTextField> xEnumerationAccess1(xFields->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("ABS(<A1>)"), xEnumerationAccess1->getPresentation(true).trim());
+ CPPUNIT_ASSERT_EQUAL(OUString("10"), xEnumerationAccess1->getPresentation(false).trim());
+
+ uno::Reference<text::XTextField> xEnumerationAccess2(xFields->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("ABS(<C1>)"), xEnumerationAccess2->getPresentation(true).trim());
+ CPPUNIT_ASSERT_EQUAL(OUString("10"), xEnumerationAccess2->getPresentation(false).trim());
+
+ uno::Reference<text::XTextField> xEnumerationAccess3(xFields->nextElement(), uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("ABS(<B1>)"), xEnumerationAccess3->getPresentation(true).trim());
+ CPPUNIT_ASSERT_EQUAL(OUString("0"), xEnumerationAccess3->getPresentation(false).trim());
+}
+
DECLARE_OOXMLEXPORT_TEST(testTdf98000_changePageStyle, "tdf98000_changePageStyle.odt")
{
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
diff --git a/sw/source/core/bastyp/calc.cxx b/sw/source/core/bastyp/calc.cxx
index 3750aead867c..17179f472352 100644
--- a/sw/source/core/bastyp/calc.cxx
+++ b/sw/source/core/bastyp/calc.cxx
@@ -86,7 +86,8 @@ const char sCalc_Date[] = "date";
const char sCalc_Product[] = "product";
const char sCalc_Average[] = "average";
const char sCalc_Count[]= "count";
-const char sCalc_Sign[]= "sign";
+const char sCalc_Sign[] = "sign";
+const char sCalc_Abs[] = "abs";
// ATTENTION: sorted list of all operators
struct CalcOp
@@ -99,6 +100,7 @@ struct CalcOp
};
CalcOp const aOpTable[] = {
+/* ABS */ {{sCalc_Abs}, CALC_ABS}, // Abs (since LibreOffice 7.1)
/* ACOS */ {{sCalc_Acos}, CALC_ACOS}, // Arc cosine
/* ADD */ {{sCalc_Add}, CALC_PLUS}, // Addition
/* AND */ {{sCalc_And}, CALC_AND}, // log. AND
@@ -1072,6 +1074,10 @@ SwSbxValue SwCalc::PrimFunc(bool &rChkPow)
SAL_INFO("sw.calc", "acos");
return StdFunc(&acos, true);
break;
+ case CALC_ABS:
+ SAL_INFO("sw.calc", "abs");
+ return StdFunc(&abs, false);
+ break;
case CALC_SIGN:
{
SAL_INFO("sw.calc", "sign");
diff --git a/sw/uiconfig/swriter/ui/inputwinmenu.ui b/sw/uiconfig/swriter/ui/inputwinmenu.ui
index 947e78697c77..a8cb41547753 100644
--- a/sw/uiconfig/swriter/ui/inputwinmenu.ui
+++ b/sw/uiconfig/swriter/ui/inputwinmenu.ui
@@ -266,6 +266,20 @@
</object>
</child>
<child>
+ <object class="GtkSeparatorMenuItem" id="separator2">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkMenuItem" id="abs">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes" context="inputwinmenu|abs">Abs</property>
+ <property name="use_underline">True</property>
+ </object>
+ </child>
+ <child>
<object class="GtkMenuItem" id="sign">
<property name="visible">True</property>
<property name="can_focus">False</property>