summaryrefslogtreecommitdiffstats
path: root/writerperfect/source/calc
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--writerperfect/source/calc/MSWorksCalcImportFilter.cxx471
-rw-r--r--writerperfect/source/calc/MSWorksCalcImportFilter.hxx48
-rw-r--r--writerperfect/source/calc/MWAWCalcImportFilter.cxx124
-rw-r--r--writerperfect/source/calc/MWAWCalcImportFilter.hxx43
-rw-r--r--writerperfect/source/calc/NumbersImportFilter.cxx65
-rw-r--r--writerperfect/source/calc/NumbersImportFilter.hxx43
-rw-r--r--writerperfect/source/calc/StarOfficeCalcImportFilter.cxx99
-rw-r--r--writerperfect/source/calc/StarOfficeCalcImportFilter.hxx44
-rw-r--r--writerperfect/source/calc/wpftcalc.component32
9 files changed, 969 insertions, 0 deletions
diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx
new file mode 100644
index 000000000..521b7c0db
--- /dev/null
+++ b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx
@@ -0,0 +1,471 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* MSWorksCalcImportFilter: Sets up the filter, and calls DocumentCollector
+ * to do the actual filtering
+ *
+ * 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/.
+ */
+
+#include <com/sun/star/awt/XWindow.hpp>
+#include <com/sun/star/container/XChild.hpp>
+#include <com/sun/star/sdbc/XResultSet.hpp>
+#include <com/sun/star/sdbc/XRow.hpp>
+#include <com/sun/star/ucb/XContent.hpp>
+#include <com/sun/star/ucb/XContentAccess.hpp>
+#include <sal/log.hxx>
+#include <comphelper/processfactory.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <sfx2/passwd.hxx>
+#include <tools/urlobj.hxx>
+#include <ucbhelper/content.hxx>
+
+#include <libwps/libwps.h>
+
+#include <DocumentHandlerForOds.hxx>
+#include <WPFTEncodingDialog.hxx>
+#include <WPFTResMgr.hxx>
+#include "MSWorksCalcImportFilter.hxx"
+#include <strings.hrc>
+
+#include <iostream>
+#include <map>
+
+using namespace ::com::sun::star;
+
+namespace MSWorksCalcImportFilterInternal
+{
+/// returns the list of stream name present in a folder
+static uno::Reference<sdbc::XResultSet>
+getResultSet(const css::uno::Reference<css::ucb::XContent>& xPackageContent)
+{
+ try
+ {
+ if (xPackageContent.is())
+ {
+ ucbhelper::Content packageContent(xPackageContent,
+ uno::Reference<ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
+ uno::Sequence<OUString> lPropNames{ "Title" };
+ uno::Reference<sdbc::XResultSet> xResultSet(
+ packageContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY));
+ return xResultSet;
+ }
+ return uno::Reference<sdbc::XResultSet>();
+ }
+ catch (...)
+ {
+ SAL_WARN("writerperfect",
+ "ignoring Exception in MSWorksCalcImportFilterInternal:getResultSet");
+ return uno::Reference<sdbc::XResultSet>();
+ }
+}
+
+namespace
+{
+/** internal class used to create a structured RVNGInputStream from a list of path and their short names
+ */
+class FolderStream : public librevenge::RVNGInputStream
+{
+public:
+ //! constructor
+ explicit FolderStream(const css::uno::Reference<css::ucb::XContent>& xContent)
+ : librevenge::RVNGInputStream()
+ , m_xContent(xContent)
+ , m_nameToPathMap()
+ {
+ }
+
+ //! add a file
+ void addFile(OUString const& path, std::string const& shortName)
+ {
+ m_nameToPathMap[shortName] = path;
+ }
+ /**! reads numbytes data.
+
+ * \return a pointer to the read elements
+ */
+ const unsigned char* read(unsigned long, unsigned long&) override { return nullptr; }
+ //! returns actual offset position
+ long tell() override { return 0; }
+ /*! \brief seeks to an offset position, from actual, beginning or ending position
+ * \return 0 if ok
+ */
+ int seek(long, librevenge::RVNG_SEEK_TYPE) override { return 1; }
+ //! returns true if we are at the end of the section/file
+ bool isEnd() override { return true; }
+
+ /** returns true if the stream is ole
+
+ \sa returns always false*/
+ bool isStructured() override { return true; }
+ /** returns the number of sub streams.
+
+ \sa returns always 2*/
+ unsigned subStreamCount() override { return unsigned(m_nameToPathMap.size()); }
+ /** returns the ith sub streams name */
+ const char* subStreamName(unsigned id) override
+ {
+ if (m_nameToPathMap.size() < id)
+ return nullptr;
+
+ std::map<std::string, OUString>::const_iterator it = m_nameToPathMap.begin();
+ std::advance(it, id);
+ return it->first.c_str();
+ }
+ /** returns true if a substream with name exists */
+ bool existsSubStream(const char* name) override
+ {
+ return name && m_nameToPathMap.find(name) != m_nameToPathMap.end();
+ }
+ /** return a new stream for an OLE zone */
+ librevenge::RVNGInputStream* getSubStreamByName(const char* name) override
+ {
+ if (m_nameToPathMap.find(name) == m_nameToPathMap.end() || !m_xContent.is())
+ return nullptr;
+
+ try
+ {
+ const uno::Reference<sdbc::XResultSet> xResultSet = getResultSet(m_xContent);
+ if (xResultSet.is() && xResultSet->first())
+ {
+ const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet,
+ uno::UNO_QUERY_THROW);
+ const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY_THROW);
+ OUString lPath = m_nameToPathMap.find(name)->second;
+ do
+ {
+ const OUString aTitle(xRow->getString(1));
+ if (aTitle != lPath)
+ continue;
+
+ const uno::Reference<ucb::XContent> xSubContent(xContentAccess->queryContent());
+ ucbhelper::Content aSubContent(xSubContent,
+ uno::Reference<ucb::XCommandEnvironment>(),
+ comphelper::getProcessComponentContext());
+ uno::Reference<io::XInputStream> xInputStream = aSubContent.openStream();
+ if (xInputStream.is())
+ return new writerperfect::WPXSvInputStream(xInputStream);
+ break;
+ } while (xResultSet->next());
+ }
+ }
+ catch (...)
+ {
+ SAL_WARN("writerperfect", "ignoring Exception in "
+ "MSWorksCalcImportFilterInternal::FolderStream::"
+ "getSubStreamByName");
+ }
+
+ return nullptr;
+ }
+ /** return a new stream for an OLE zone */
+ librevenge::RVNGInputStream* getSubStreamById(unsigned id) override
+ {
+ char const* name = subStreamName(id);
+ return name ? getSubStreamByName(name) : nullptr;
+ }
+
+private:
+ /// the main container
+ uno::Reference<ucb::XContent> m_xContent;
+ /// the map short name to path
+ std::map<std::string, OUString> m_nameToPathMap;
+ FolderStream(const FolderStream&) = delete;
+ FolderStream& operator=(const FolderStream&) = delete;
+};
+}
+}
+
+////////////////////////////////////////////////////////////
+bool MSWorksCalcImportFilter::doImportDocument(weld::Window* pParent,
+ librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator,
+ utl::MediaDescriptor& mediaDescriptor)
+{
+ libwps::WPSKind kind = libwps::WPS_TEXT;
+ libwps::WPSCreator creator;
+ bool needEncoding;
+ const libwps::WPSConfidence confidence
+ = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
+
+ if ((kind != libwps::WPS_SPREADSHEET && kind != libwps::WPS_DATABASE)
+ || (confidence == libwps::WPS_CONFIDENCE_NONE))
+ return false;
+ std::string fileEncoding;
+ if (needEncoding)
+ {
+ OUString encoding;
+ // first check if we can find the encoding in the filter options (headless mode)
+ mediaDescriptor[utl::MediaDescriptor::PROP_FILTEROPTIONS()] >>= encoding;
+ if (!encoding.isEmpty()) // TODO: check if the encoding string is valid
+ fileEncoding = encoding.toUtf8().getStr();
+ else
+ {
+ OUString title;
+ switch (creator)
+ {
+ case libwps::WPS_MSWORKS:
+ title = WpResId(STR_ENCODING_DIALOG_TITLE_MSWORKS);
+ encoding = "CP850";
+ break;
+ case libwps::WPS_LOTUS:
+ title = WpResId(STR_ENCODING_DIALOG_TITLE_LOTUS);
+ encoding = "CP437";
+ break;
+ case libwps::WPS_SYMPHONY:
+ title = WpResId(STR_ENCODING_DIALOG_TITLE_SYMPHONY);
+ encoding = "CP437";
+ break;
+ case libwps::WPS_QUATTRO_PRO:
+ title = WpResId(STR_ENCODING_DIALOG_TITLE_QUATTROPRO);
+ encoding = "CP437";
+ break;
+ case libwps::WPS_RESERVED_2:
+ title = WpResId(STR_ENCODING_DIALOG_TITLE_MSMULTIPLAN);
+ encoding = "CP437";
+ break;
+ default:
+ SAL_INFO("writerperfect", "unexpected creator: " << creator);
+ title = WpResId(STR_ENCODING_DIALOG_TITLE);
+ encoding = "CP437";
+ break;
+ }
+
+ fileEncoding = encoding.toUtf8().getStr(); // set default to the proposed encoding
+ try
+ {
+ writerperfect::WPFTEncodingDialog aDlg(pParent, title, encoding);
+ if (aDlg.run() == RET_OK)
+ {
+ if (!aDlg.GetEncoding().isEmpty())
+ fileEncoding = aDlg.GetEncoding().toUtf8().getStr();
+ }
+ // we can fail because we are in headless mode, the user has cancelled conversion, ...
+ else if (aDlg.hasUserCalledCancel())
+ return false;
+ }
+ catch (...)
+ {
+ SAL_WARN("writerperfect",
+ "ignoring Exception in MSWorksCalcImportFilter::doImportDocument");
+ }
+ }
+ }
+ OString aUtf8Passwd;
+ if (confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION)
+ {
+ OUString sPassword;
+ // now check if we can find the password in the properties
+ // (just in case, "soffice --headless" adds an option to send password)
+ mediaDescriptor[utl::MediaDescriptor::PROP_PASSWORD()] >>= sPassword;
+ if (!sPassword.isEmpty())
+ aUtf8Passwd = OUStringToOString(sPassword, RTL_TEXTENCODING_UTF8);
+ else
+ {
+ // ok, ask the user for a password
+ try
+ {
+ SfxPasswordDialog aPasswdDlg(pParent);
+ aPasswdDlg.SetMinLen(1);
+ if (!aPasswdDlg.run())
+ return false;
+ OUString aPasswd = aPasswdDlg.GetPassword();
+ aUtf8Passwd = OUStringToOString(aPasswd, RTL_TEXTENCODING_UTF8);
+ }
+ catch (...)
+ {
+ return false;
+ }
+ }
+ }
+ return libwps::WPS_OK
+ == libwps::WPSDocument::parse(&rInput, &rGenerator,
+ confidence == libwps::WPS_CONFIDENCE_SUPPORTED_ENCRYPTION
+ ? aUtf8Passwd.getStr()
+ : nullptr,
+ fileEncoding.c_str());
+}
+
+//XExtendedFilterDetection
+sal_Bool
+MSWorksCalcImportFilter::filter(const css::uno::Sequence<css::beans::PropertyValue>& rDescriptor)
+{
+ OUString sUrl;
+ css::uno::Reference<css::io::XInputStream> xInputStream;
+ css::uno::Reference<ucb::XContent> xContent;
+ css::uno::Reference<css::awt::XWindow> xDialogParent;
+
+ for (const auto& rValue : rDescriptor)
+ {
+ if (rValue.Name == "InputStream")
+ rValue.Value >>= xInputStream;
+ else if (rValue.Name == "UCBContent")
+ rValue.Value >>= xContent;
+ else if (rValue.Name == "FileName" || rValue.Name == "URL")
+ rValue.Value >>= sUrl;
+ else if (rValue.Name == "ParentWindow")
+ rValue.Value >>= xDialogParent;
+ }
+
+ if (!getXContext().is() || !xInputStream.is())
+ {
+ OSL_ASSERT(false);
+ return false;
+ }
+
+ // An XML import service: what we push sax messages to...
+ css::uno::Reference<css::xml::sax::XDocumentHandler> xInternalHandler(
+ getXContext()->getServiceManager()->createInstanceWithContext(
+ writerperfect::DocumentHandlerFor<OdsGenerator>::name(), getXContext()),
+ css::uno::UNO_QUERY_THROW);
+
+ // The XImporter sets up an empty target document for XDocumentHandler to write to...
+ css::uno::Reference<css::document::XImporter> xImporter(xInternalHandler, css::uno::UNO_QUERY);
+ xImporter->setTargetDocument(getTargetDocument());
+
+ // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here
+ // writes to in-memory target doc
+ writerperfect::DocumentHandler aHandler(xInternalHandler);
+
+ writerperfect::WPXSvInputStream input(xInputStream);
+ OdsGenerator exporter;
+ exporter.addDocumentHandler(&aHandler, ODF_FLAT_XML);
+ doRegisterHandlers(exporter);
+
+ utl::MediaDescriptor aDescriptor(rDescriptor);
+ try
+ {
+ // time to check if the file is a WK3 file and a FM3 file is
+ // present
+ bool checkForFM3 = false;
+ if (input.seek(0, librevenge::RVNG_SEEK_SET) == 0 && xContent.is()
+ && INetURLObject(sUrl).getExtension().equalsIgnoreAsciiCase("WK3"))
+ {
+ // check if the file header corresponds to a .wk3 file
+ unsigned long numBytesRead;
+ const unsigned char* data = input.read(6, numBytesRead);
+ if (data && numBytesRead == 6 && data[0] == 0 && data[1] == 0 && data[2] == 0x1a
+ && data[3] == 0 && data[4] < 2 && data[5] == 0x10)
+ checkForFM3 = true;
+ }
+ if (checkForFM3)
+ {
+ // check if the format file exists
+ const css::uno::Reference<container::XChild> xChild(xContent, uno::UNO_QUERY);
+ if (xChild.is())
+ {
+ OUString sWM3Name;
+ OUString sFM3Name;
+ const css::uno::Reference<ucb::XContent> xPackageContent(xChild->getParent(),
+ uno::UNO_QUERY);
+ uno::Reference<sdbc::XResultSet> xResultSet
+ = MSWorksCalcImportFilterInternal::getResultSet(xPackageContent);
+ if (xResultSet.is() && xResultSet->first())
+ {
+ const uno::Reference<ucb::XContentAccess> xContentAccess(xResultSet,
+ uno::UNO_QUERY_THROW);
+ const uno::Reference<sdbc::XRow> xRow(xResultSet, uno::UNO_QUERY_THROW);
+ INetURLObject aTmpUrl(sUrl);
+ sWM3Name = aTmpUrl.getName(INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DecodeMechanism::WithCharset);
+ aTmpUrl.setExtension("FM3");
+ const OUString& sTestFM3Name
+ = aTmpUrl.getName(INetURLObject::LAST_SEGMENT, true,
+ INetURLObject::DecodeMechanism::WithCharset);
+ do
+ {
+ const OUString& aTitle(xRow->getString(1));
+ if (aTitle.equalsIgnoreAsciiCase(sTestFM3Name))
+ sFM3Name = aTitle;
+ } while (xResultSet->next() && sFM3Name.isEmpty());
+ }
+ if (!sFM3Name.isEmpty())
+ {
+ MSWorksCalcImportFilterInternal::FolderStream structuredInput(xPackageContent);
+ structuredInput.addFile(sWM3Name, "WK3");
+ structuredInput.addFile(sFM3Name, "FM3");
+
+ libwps::WPSKind kind = libwps::WPS_TEXT;
+ libwps::WPSCreator creator;
+ bool needEncoding;
+ const libwps::WPSConfidence confidence
+ = libwps::WPSDocument::isFileFormatSupported(&structuredInput, kind,
+ creator, needEncoding);
+ if (confidence != libwps::WPS_CONFIDENCE_NONE)
+ return doImportDocument(Application::GetFrameWeld(xDialogParent),
+ structuredInput, exporter, aDescriptor);
+ }
+ }
+ }
+ }
+ catch (...)
+ {
+ }
+
+ return doImportDocument(Application::GetFrameWeld(xDialogParent), input, exporter, aDescriptor);
+}
+
+bool MSWorksCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput,
+ OUString& rTypeName)
+{
+ libwps::WPSKind kind = libwps::WPS_TEXT;
+ libwps::WPSCreator creator;
+ bool needEncoding;
+ const libwps::WPSConfidence confidence
+ = libwps::WPSDocument::isFileFormatSupported(&rInput, kind, creator, needEncoding);
+
+ if ((kind == libwps::WPS_SPREADSHEET || kind == libwps::WPS_DATABASE)
+ && confidence != libwps::WPS_CONFIDENCE_NONE)
+ {
+ switch (creator)
+ {
+ case libwps::WPS_MSWORKS:
+ rTypeName = "calc_MS_Works_Document";
+ break;
+ case libwps::WPS_LOTUS:
+ case libwps::WPS_SYMPHONY:
+ rTypeName = "calc_WPS_Lotus_Document";
+ break;
+ case libwps::WPS_QUATTRO_PRO:
+ rTypeName = "calc_WPS_QPro_Document";
+ break;
+ case libwps::WPS_RESERVED_2:
+ rTypeName = "calc_MS_Multiplan";
+ break;
+ default:
+ break;
+ }
+ }
+
+ return !rTypeName.isEmpty();
+}
+
+void MSWorksCalcImportFilter::doRegisterHandlers(OdsGenerator&) {}
+
+// XServiceInfo
+OUString SAL_CALL MSWorksCalcImportFilter::getImplementationName()
+{
+ return "com.sun.star.comp.Calc.MSWorksCalcImportFilter";
+}
+
+sal_Bool SAL_CALL MSWorksCalcImportFilter::supportsService(const OUString& rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+
+css::uno::Sequence<OUString> SAL_CALL MSWorksCalcImportFilter::getSupportedServiceNames()
+{
+ return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_Calc_MSWorksCalcImportFilter_get_implementation(
+ css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
+{
+ return cppu::acquire(new MSWorksCalcImportFilter(context));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.hxx b/writerperfect/source/calc/MSWorksCalcImportFilter.hxx
new file mode 100644
index 000000000..82cf76763
--- /dev/null
+++ b/writerperfect/source/calc/MSWorksCalcImportFilter.hxx
@@ -0,0 +1,48 @@
+/* -*- 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_WRITERPERFECT_SOURCE_CALC_MSWORKSCALCIMPORTFILTER_HXX
+#define INCLUDED_WRITERPERFECT_SOURCE_CALC_MSWORKSCALCIMPORTFILTER_HXX
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <DocumentHandlerForOds.hxx>
+#include <ImportFilter.hxx>
+
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class MSWorksCalcImportFilter : public writerperfect::ImportFilter<OdsGenerator>
+{
+public:
+ explicit MSWorksCalcImportFilter(
+ const css::uno::Reference<css::uno::XComponentContext>& rxContext)
+ : writerperfect::ImportFilter<OdsGenerator>(rxContext)
+ {
+ }
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+
+ //XFilter
+ virtual sal_Bool SAL_CALL
+ filter(const css::uno::Sequence<css::beans::PropertyValue>& rDescriptor) override;
+
+private:
+ virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override;
+ virtual bool doImportDocument(weld::Window* pParent, librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&) override;
+ virtual void doRegisterHandlers(OdsGenerator& rGenerator) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/MWAWCalcImportFilter.cxx b/writerperfect/source/calc/MWAWCalcImportFilter.cxx
new file mode 100644
index 000000000..186084b17
--- /dev/null
+++ b/writerperfect/source/calc/MWAWCalcImportFilter.cxx
@@ -0,0 +1,124 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* MWAWCalcImportFilter: Sets up the filter, and calls DocumentCollector
+ * to do the actual filtering
+ *
+ * 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/.
+ */
+
+#include <cppuhelper/supportsservice.hxx>
+
+#include <libmwaw/libmwaw.hxx>
+
+#include "MWAWCalcImportFilter.hxx"
+
+static bool handleEmbeddedMWAWGraphicObject(const librevenge::RVNGBinaryData& data,
+ OdfDocumentHandler* pHandler,
+ const OdfStreamType streamType)
+{
+ OdgGenerator exporter;
+ exporter.addDocumentHandler(pHandler, streamType);
+ return MWAWDocument::decodeGraphic(data, &exporter);
+}
+
+static bool handleEmbeddedMWAWSpreadsheetObject(const librevenge::RVNGBinaryData& data,
+ OdfDocumentHandler* pHandler,
+ const OdfStreamType streamType)
+{
+ OdsGenerator exporter;
+ exporter.addDocumentHandler(pHandler, streamType);
+ return MWAWDocument::decodeSpreadsheet(data, &exporter);
+}
+
+bool MWAWCalcImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&)
+{
+ return MWAWDocument::MWAW_R_OK == MWAWDocument::parse(&rInput, &rGenerator);
+}
+
+bool MWAWCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName)
+{
+ rTypeName.clear();
+
+ MWAWDocument::Type docType = MWAWDocument::MWAW_T_UNKNOWN;
+ MWAWDocument::Kind docKind = MWAWDocument::MWAW_K_UNKNOWN;
+ const MWAWDocument::Confidence confidence
+ = MWAWDocument::isFileFormatSupported(&rInput, docType, docKind);
+
+ if (confidence == MWAWDocument::MWAW_C_EXCELLENT)
+ {
+ switch (docKind)
+ {
+ case MWAWDocument::MWAW_K_DATABASE:
+ switch (docType)
+ {
+ case MWAWDocument::MWAW_T_CLARISWORKS:
+ rTypeName = "calc_ClarisWorks";
+ break;
+ case MWAWDocument::MWAW_T_MICROSOFTWORKS:
+ rTypeName = "calc_Mac_Works";
+ break;
+ default:
+ rTypeName = "MWAW_Database";
+ break;
+ }
+ break;
+ case MWAWDocument::MWAW_K_SPREADSHEET:
+ switch (docType)
+ {
+ case MWAWDocument::MWAW_T_CLARISRESOLVE:
+ rTypeName = "calc_Claris_Resolve";
+ break;
+ case MWAWDocument::MWAW_T_CLARISWORKS:
+ rTypeName = "calc_ClarisWorks";
+ break;
+ case MWAWDocument::MWAW_T_MICROSOFTWORKS:
+ rTypeName = "calc_Mac_Works";
+ break;
+ default:
+ rTypeName = "MWAW_Spreadsheet";
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ return !rTypeName.isEmpty();
+}
+
+void MWAWCalcImportFilter::doRegisterHandlers(OdsGenerator& rGenerator)
+{
+ rGenerator.registerEmbeddedObjectHandler("image/mwaw-odg", &handleEmbeddedMWAWGraphicObject);
+ rGenerator.registerEmbeddedObjectHandler("image/mwaw-ods",
+ &handleEmbeddedMWAWSpreadsheetObject);
+}
+
+// XServiceInfo
+OUString SAL_CALL MWAWCalcImportFilter::getImplementationName()
+{
+ return "com.sun.star.comp.Calc.MWAWCalcImportFilter";
+}
+
+sal_Bool SAL_CALL MWAWCalcImportFilter::supportsService(const OUString& rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+
+css::uno::Sequence<OUString> SAL_CALL MWAWCalcImportFilter::getSupportedServiceNames()
+{
+ return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+com_sun_star_comp_Calc_MWAWCalcImportFilter_get_implementation(
+ css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
+{
+ return cppu::acquire(new MWAWCalcImportFilter(context));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/MWAWCalcImportFilter.hxx b/writerperfect/source/calc/MWAWCalcImportFilter.hxx
new file mode 100644
index 000000000..97cfc1891
--- /dev/null
+++ b/writerperfect/source/calc/MWAWCalcImportFilter.hxx
@@ -0,0 +1,43 @@
+/* -*- 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_WRITERPERFECT_SOURCE_CALC_MWAWCALCIMPORTFILTER_HXX
+#define INCLUDED_WRITERPERFECT_SOURCE_CALC_MWAWCALCIMPORTFILTER_HXX
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <DocumentHandlerForOds.hxx>
+#include <ImportFilter.hxx>
+
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class MWAWCalcImportFilter : public writerperfect::ImportFilter<OdsGenerator>
+{
+public:
+ explicit MWAWCalcImportFilter(const css::uno::Reference<css::uno::XComponentContext>& rxContext)
+ : writerperfect::ImportFilter<OdsGenerator>(rxContext)
+ {
+ }
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+
+private:
+ virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override;
+ virtual bool doImportDocument(weld::Window* pParent, librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&) override;
+ virtual void doRegisterHandlers(OdsGenerator& rGenerator) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/NumbersImportFilter.cxx b/writerperfect/source/calc/NumbersImportFilter.cxx
new file mode 100644
index 000000000..813684361
--- /dev/null
+++ b/writerperfect/source/calc/NumbersImportFilter.cxx
@@ -0,0 +1,65 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* NumbersImportFilter: Sets up the filter, and calls DocumentCollector
+ * to do the actual filtering
+ *
+ * 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/.
+ */
+
+#include <libetonyek/libetonyek.h>
+
+#include <cppuhelper/supportsservice.hxx>
+
+#include "NumbersImportFilter.hxx"
+
+using libetonyek::EtonyekDocument;
+
+bool NumbersImportFilter::doImportDocument(weld::Window*, librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&)
+{
+ return EtonyekDocument::parse(&rInput, &rGenerator);
+}
+
+bool NumbersImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName)
+{
+ EtonyekDocument::Type type = EtonyekDocument::TYPE_UNKNOWN;
+ const EtonyekDocument::Confidence confidence = EtonyekDocument::isSupported(&rInput, &type);
+ if ((confidence == EtonyekDocument::CONFIDENCE_EXCELLENT)
+ && (type == EtonyekDocument::TYPE_NUMBERS))
+ {
+ rTypeName = "calc_AppleNumbers";
+ return true;
+ }
+
+ return false;
+}
+
+void NumbersImportFilter::doRegisterHandlers(OdsGenerator&) {}
+
+// XServiceInfo
+OUString SAL_CALL NumbersImportFilter::getImplementationName()
+{
+ return "org.libreoffice.comp.Calc.NumbersImportFilter";
+}
+
+sal_Bool SAL_CALL NumbersImportFilter::supportsService(const OUString& rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+
+css::uno::Sequence<OUString> SAL_CALL NumbersImportFilter::getSupportedServiceNames()
+{
+ return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+org_libreoffice_comp_Calc_NumbersImportFilter_get_implementation(
+ css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
+{
+ return cppu::acquire(new NumbersImportFilter(context));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/NumbersImportFilter.hxx b/writerperfect/source/calc/NumbersImportFilter.hxx
new file mode 100644
index 000000000..9bbbc174b
--- /dev/null
+++ b/writerperfect/source/calc/NumbersImportFilter.hxx
@@ -0,0 +1,43 @@
+/* -*- 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_WRITERPERFECT_SOURCE_WRITER_NUMBERSIMPORTFILTER_HXX
+#define INCLUDED_WRITERPERFECT_SOURCE_WRITER_NUMBERSIMPORTFILTER_HXX
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <DocumentHandlerForOds.hxx>
+#include <ImportFilter.hxx>
+
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class NumbersImportFilter : public writerperfect::ImportFilter<OdsGenerator>
+{
+public:
+ explicit NumbersImportFilter(const css::uno::Reference<css::uno::XComponentContext>& rxContext)
+ : writerperfect::ImportFilter<OdsGenerator>(rxContext)
+ {
+ }
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+
+private:
+ virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override;
+ virtual bool doImportDocument(weld::Window* pParent, librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&) override;
+ virtual void doRegisterHandlers(OdsGenerator& rGenerator) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/StarOfficeCalcImportFilter.cxx b/writerperfect/source/calc/StarOfficeCalcImportFilter.cxx
new file mode 100644
index 000000000..de7e30e44
--- /dev/null
+++ b/writerperfect/source/calc/StarOfficeCalcImportFilter.cxx
@@ -0,0 +1,99 @@
+/* -*- 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/.
+ */
+
+#include <cppuhelper/supportsservice.hxx>
+
+#include <libstaroffice/libstaroffice.hxx>
+
+#include "StarOfficeCalcImportFilter.hxx"
+
+using com::sun::star::uno::Sequence;
+using com::sun::star::uno::XComponentContext;
+using com::sun::star::uno::XInterface;
+
+static bool handleEmbeddedSTOFFGraphicObject(const librevenge::RVNGBinaryData& data,
+ OdfDocumentHandler* pHandler,
+ const OdfStreamType streamType)
+{
+ OdgGenerator exporter;
+ exporter.addDocumentHandler(pHandler, streamType);
+ return STOFFDocument::decodeGraphic(data, &exporter);
+}
+
+static bool handleEmbeddedSTOFFSpreadsheetObject(const librevenge::RVNGBinaryData& data,
+ OdfDocumentHandler* pHandler,
+ const OdfStreamType streamType)
+{
+ OdsGenerator exporter;
+ exporter.addDocumentHandler(pHandler, streamType);
+ return STOFFDocument::decodeSpreadsheet(data, &exporter);
+}
+
+bool StarOfficeCalcImportFilter::doImportDocument(weld::Window*,
+ librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&)
+{
+ return STOFFDocument::STOFF_R_OK == STOFFDocument::parse(&rInput, &rGenerator);
+}
+
+bool StarOfficeCalcImportFilter::doDetectFormat(librevenge::RVNGInputStream& rInput,
+ OUString& rTypeName)
+{
+ rTypeName.clear();
+ STOFFDocument::Kind docKind = STOFFDocument::STOFF_K_UNKNOWN;
+ const STOFFDocument::Confidence confidence
+ = STOFFDocument::isFileFormatSupported(&rInput, docKind);
+ if (confidence == STOFFDocument::STOFF_C_EXCELLENT
+ || confidence == STOFFDocument::STOFF_C_SUPPORTED_ENCRYPTION)
+ {
+ switch (docKind)
+ {
+ case STOFFDocument::STOFF_K_DATABASE:
+ case STOFFDocument::STOFF_K_SPREADSHEET:
+ rTypeName = "StarOffice_Spreadsheet";
+ break;
+ default:
+ break;
+ }
+ }
+
+ return !rTypeName.isEmpty();
+}
+
+void StarOfficeCalcImportFilter::doRegisterHandlers(OdsGenerator& rGenerator)
+{
+ rGenerator.registerEmbeddedObjectHandler("image/stoff-odg", &handleEmbeddedSTOFFGraphicObject);
+ rGenerator.registerEmbeddedObjectHandler("image/stoff-ods",
+ &handleEmbeddedSTOFFSpreadsheetObject);
+}
+
+// XServiceInfo
+OUString SAL_CALL StarOfficeCalcImportFilter::getImplementationName()
+{
+ return "org.libreoffice.comp.Calc.StarOfficeCalcImportFilter";
+}
+
+sal_Bool SAL_CALL StarOfficeCalcImportFilter::supportsService(const OUString& rServiceName)
+{
+ return cppu::supportsService(this, rServiceName);
+}
+
+Sequence<OUString> SAL_CALL StarOfficeCalcImportFilter::getSupportedServiceNames()
+{
+ return { "com.sun.star.document.ImportFilter", "com.sun.star.document.ExtendedTypeDetection" };
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+org_libreoffice_comp_Calc_StarOfficeCalcImportFilter_get_implementation(
+ css::uno::XComponentContext* const context, const css::uno::Sequence<css::uno::Any>&)
+{
+ return cppu::acquire(new StarOfficeCalcImportFilter(context));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/StarOfficeCalcImportFilter.hxx b/writerperfect/source/calc/StarOfficeCalcImportFilter.hxx
new file mode 100644
index 000000000..bef0e2cef
--- /dev/null
+++ b/writerperfect/source/calc/StarOfficeCalcImportFilter.hxx
@@ -0,0 +1,44 @@
+/* -*- 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_WRITERPERFECT_SOURCE_CALC_STAROFFICECALCIMPORTFILTER_HXX
+#define INCLUDED_WRITERPERFECT_SOURCE_CALC_STAROFFICECALCIMPORTFILTER_HXX
+
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <DocumentHandlerForOds.hxx>
+#include <ImportFilter.hxx>
+
+/* This component will be instantiated for both import or export. Whether it calls
+ * setSourceDocument or setTargetDocument determines which Impl function the filter
+ * member calls */
+class StarOfficeCalcImportFilter : public writerperfect::ImportFilter<OdsGenerator>
+{
+public:
+ explicit StarOfficeCalcImportFilter(
+ const css::uno::Reference<css::uno::XComponentContext>& rxContext)
+ : writerperfect::ImportFilter<OdsGenerator>(rxContext)
+ {
+ }
+
+ // XServiceInfo
+ virtual OUString SAL_CALL getImplementationName() override;
+ virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
+
+private:
+ virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) override;
+ virtual bool doImportDocument(weld::Window* pParent, librevenge::RVNGInputStream& rInput,
+ OdsGenerator& rGenerator, utl::MediaDescriptor&) override;
+ virtual void doRegisterHandlers(OdsGenerator& rGenerator) override;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/calc/wpftcalc.component b/writerperfect/source/calc/wpftcalc.component
new file mode 100644
index 000000000..404d09b6c
--- /dev/null
+++ b/writerperfect/source/calc/wpftcalc.component
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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/.
+ *
+-->
+<component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
+ xmlns="http://openoffice.org/2010/uno-components">
+ <implementation name="com.sun.star.comp.Calc.MSWorksCalcImportFilter"
+ constructor="com_sun_star_comp_Calc_MSWorksCalcImportFilter_get_implementation">
+ <service name="com.sun.star.document.ImportFilter"/>
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ </implementation>
+ <implementation name="com.sun.star.comp.Calc.MWAWCalcImportFilter"
+ constructor="com_sun_star_comp_Calc_MWAWCalcImportFilter_get_implementation">
+ <service name="com.sun.star.document.ImportFilter"/>
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ </implementation>
+ <implementation name="org.libreoffice.comp.Calc.NumbersImportFilter"
+ constructor="org_libreoffice_comp_Calc_NumbersImportFilter_get_implementation">
+ <service name="com.sun.star.document.ImportFilter"/>
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ </implementation>
+ <implementation name="org.libreoffice.comp.Calc.StarOfficeCalcImportFilter"
+ constructor="org_libreoffice_comp_Calc_StarOfficeCalcImportFilter_get_implementation">
+ <service name="com.sun.star.document.ImportFilter"/>
+ <service name="com.sun.star.document.ExtendedTypeDetection"/>
+ </implementation>
+</component>