From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- .../source/calc/MSWorksCalcImportFilter.cxx | 475 +++++++++++++++++++++ .../source/calc/MSWorksCalcImportFilter.hxx | 45 ++ writerperfect/source/calc/MWAWCalcImportFilter.cxx | 124 ++++++ writerperfect/source/calc/MWAWCalcImportFilter.hxx | 40 ++ writerperfect/source/calc/NumbersImportFilter.cxx | 65 +++ writerperfect/source/calc/NumbersImportFilter.hxx | 40 ++ .../source/calc/StarOfficeCalcImportFilter.cxx | 99 +++++ .../source/calc/StarOfficeCalcImportFilter.hxx | 41 ++ writerperfect/source/calc/wpftcalc.component | 33 ++ .../source/calc/wpftcalc.component.extended | 7 + 10 files changed, 969 insertions(+) create mode 100644 writerperfect/source/calc/MSWorksCalcImportFilter.cxx create mode 100644 writerperfect/source/calc/MSWorksCalcImportFilter.hxx create mode 100644 writerperfect/source/calc/MWAWCalcImportFilter.cxx create mode 100644 writerperfect/source/calc/MWAWCalcImportFilter.hxx create mode 100644 writerperfect/source/calc/NumbersImportFilter.cxx create mode 100644 writerperfect/source/calc/NumbersImportFilter.hxx create mode 100644 writerperfect/source/calc/StarOfficeCalcImportFilter.cxx create mode 100644 writerperfect/source/calc/StarOfficeCalcImportFilter.hxx create mode 100644 writerperfect/source/calc/wpftcalc.component create mode 100644 writerperfect/source/calc/wpftcalc.component.extended (limited to 'writerperfect/source/calc') diff --git a/writerperfect/source/calc/MSWorksCalcImportFilter.cxx b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx new file mode 100644 index 0000000000..bc13f9fc74 --- /dev/null +++ b/writerperfect/source/calc/MSWorksCalcImportFilter.cxx @@ -0,0 +1,475 @@ +/* -*- 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include "MSWorksCalcImportFilter.hxx" +#include + +#include +#include +#include + +using namespace ::com::sun::star; + +namespace MSWorksCalcImportFilterInternal +{ +/// returns the list of stream name present in a folder +static uno::Reference +getResultSet(const css::uno::Reference& xPackageContent) +{ + try + { + if (xPackageContent.is()) + { + ucbhelper::Content packageContent(xPackageContent, + uno::Reference(), + comphelper::getProcessComponentContext()); + uno::Sequence lPropNames{ "Title" }; + uno::Reference xResultSet( + packageContent.createCursor(lPropNames, ucbhelper::INCLUDE_DOCUMENTS_ONLY)); + return xResultSet; + } + return uno::Reference(); + } + catch (...) + { + SAL_WARN("writerperfect", + "ignoring Exception in MSWorksCalcImportFilterInternal:getResultSet"); + return uno::Reference(); + } +} + +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(css::uno::Reference xContent) + : m_xContent(std::move(xContent)) + { + } + + //! 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::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 xResultSet = getResultSet(m_xContent); + if (xResultSet.is() && xResultSet->first()) + { + const uno::Reference xContentAccess(xResultSet, + uno::UNO_QUERY_THROW); + const uno::Reference 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 xSubContent(xContentAccess->queryContent()); + ucbhelper::Content aSubContent(xSubContent, + uno::Reference(), + comphelper::getProcessComponentContext()); + uno::Reference 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 m_xContent; + /// the map short name to path + std::map 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& rDescriptor) +{ + OUString sUrl; + css::uno::Reference xInputStream; + css::uno::Reference xContent; + css::uno::Reference 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 xInternalFilter + = getXContext()->getServiceManager()->createInstanceWithContext( + writerperfect::DocumentHandlerFor::name(), getXContext()); + assert(xInternalFilter); + css::uno::Reference xInternalHandler(xInternalFilter, + css::uno::UNO_QUERY); + assert(xInternalHandler); + + // The XImporter sets up an empty target document for XDocumentHandler to write to... + css::uno::Reference xImporter(xInternalHandler, css::uno::UNO_QUERY); + assert(xImporter); + 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( + new SvXMLLegacyToFastDocHandler(static_cast(xInternalHandler.get()))); + + 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 xChild(xContent, uno::UNO_QUERY); + if (xChild.is()) + { + OUString sWM3Name; + OUString sFM3Name; + const css::uno::Reference xPackageContent(xChild->getParent(), + uno::UNO_QUERY); + uno::Reference xResultSet + = MSWorksCalcImportFilterInternal::getResultSet(xPackageContent); + if (xResultSet.is() && xResultSet->first()) + { + const uno::Reference xContentAccess(xResultSet, + uno::UNO_QUERY_THROW); + const uno::Reference xRow(xResultSet, uno::UNO_QUERY_THROW); + INetURLObject aTmpUrl(sUrl); + sWM3Name = aTmpUrl.getName(INetURLObject::LAST_SEGMENT, true, + INetURLObject::DecodeMechanism::WithCharset); + aTmpUrl.setExtension(u"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 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&) +{ + 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 0000000000..d0ce3e1fcc --- /dev/null +++ b/writerperfect/source/calc/MSWorksCalcImportFilter.hxx @@ -0,0 +1,45 @@ +/* -*- 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/. + */ + +#pragma once + +#include + +#include +#include + +/* 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 +{ +public: + explicit MSWorksCalcImportFilter( + const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence SAL_CALL getSupportedServiceNames() override; + + //XFilter + virtual sal_Bool SAL_CALL + filter(const css::uno::Sequence& 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; +}; + +/* 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 0000000000..186084b177 --- /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 + +#include + +#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 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&) +{ + 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 0000000000..aa574315d5 --- /dev/null +++ b/writerperfect/source/calc/MWAWCalcImportFilter.hxx @@ -0,0 +1,40 @@ +/* -*- 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/. + */ + +#pragma once + +#include + +#include +#include + +/* 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 +{ +public: + explicit MWAWCalcImportFilter(const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence 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; +}; + +/* 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 0000000000..813684361a --- /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 + +#include + +#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 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&) +{ + 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 0000000000..96db0b6893 --- /dev/null +++ b/writerperfect/source/calc/NumbersImportFilter.hxx @@ -0,0 +1,40 @@ +/* -*- 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/. + */ + +#pragma once + +#include + +#include +#include + +/* 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 +{ +public: + explicit NumbersImportFilter(const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence 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; +}; + +/* 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 0000000000..de7e30e44d --- /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 + +#include + +#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 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&) +{ + 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 0000000000..0b11e5166f --- /dev/null +++ b/writerperfect/source/calc/StarOfficeCalcImportFilter.hxx @@ -0,0 +1,41 @@ +/* -*- 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/. + */ + +#pragma once + +#include + +#include +#include + +/* 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 +{ +public: + explicit StarOfficeCalcImportFilter( + const css::uno::Reference& rxContext) + : writerperfect::ImportFilter(rxContext) + { + } + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; + virtual css::uno::Sequence 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; +}; + +/* 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 0000000000..7054f76995 --- /dev/null +++ b/writerperfect/source/calc/wpftcalc.component @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/writerperfect/source/calc/wpftcalc.component.extended b/writerperfect/source/calc/wpftcalc.component.extended new file mode 100644 index 0000000000..81bdc103cc --- /dev/null +++ b/writerperfect/source/calc/wpftcalc.component.extended @@ -0,0 +1,7 @@ +# 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/. + +org.libreoffice.comp.Calc.NumbersImportFilter -- cgit v1.2.3