From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- writerperfect/inc/DirectoryStream.hxx | 57 +++++++++ writerperfect/inc/DocumentHandler.hxx | 51 ++++++++ writerperfect/inc/DocumentHandlerFor.hxx | 22 ++++ writerperfect/inc/DocumentHandlerForOdg.hxx | 24 ++++ writerperfect/inc/DocumentHandlerForOdp.hxx | 24 ++++ writerperfect/inc/DocumentHandlerForOds.hxx | 24 ++++ writerperfect/inc/DocumentHandlerForOdt.hxx | 24 ++++ writerperfect/inc/ImportFilter.hxx | 183 ++++++++++++++++++++++++++++ writerperfect/inc/WPFTEncodingDialog.hxx | 45 +++++++ writerperfect/inc/WPFTResMgr.hxx | 9 ++ writerperfect/inc/WPXSvInputStream.hxx | 54 ++++++++ writerperfect/inc/strings.hrc | 23 ++++ writerperfect/inc/writerperfectdllapi.h | 20 +++ 13 files changed, 560 insertions(+) create mode 100644 writerperfect/inc/DirectoryStream.hxx create mode 100644 writerperfect/inc/DocumentHandler.hxx create mode 100644 writerperfect/inc/DocumentHandlerFor.hxx create mode 100644 writerperfect/inc/DocumentHandlerForOdg.hxx create mode 100644 writerperfect/inc/DocumentHandlerForOdp.hxx create mode 100644 writerperfect/inc/DocumentHandlerForOds.hxx create mode 100644 writerperfect/inc/DocumentHandlerForOdt.hxx create mode 100644 writerperfect/inc/ImportFilter.hxx create mode 100644 writerperfect/inc/WPFTEncodingDialog.hxx create mode 100644 writerperfect/inc/WPFTResMgr.hxx create mode 100644 writerperfect/inc/WPXSvInputStream.hxx create mode 100644 writerperfect/inc/strings.hrc create mode 100644 writerperfect/inc/writerperfectdllapi.h (limited to 'writerperfect/inc') diff --git a/writerperfect/inc/DirectoryStream.hxx b/writerperfect/inc/DirectoryStream.hxx new file mode 100644 index 000000000..c45209333 --- /dev/null +++ b/writerperfect/inc/DirectoryStream.hxx @@ -0,0 +1,57 @@ +/* -*- 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 "writerperfectdllapi.h" +#include +#include + +namespace com::sun::star::ucb +{ +class XContent; +} + +namespace writerperfect +{ +class WRITERPERFECT_DLLPUBLIC DirectoryStream final : public librevenge::RVNGInputStream +{ + struct Impl; + +public: + explicit DirectoryStream(const css::uno::Reference& xContent); + virtual ~DirectoryStream() override; + + static bool isDirectory(const css::uno::Reference& xContent); + static std::unique_ptr + createForParent(const css::uno::Reference& xContent); + + css::uno::Reference getContent() const; + + virtual bool isStructured() override; + SAL_DLLPRIVATE virtual unsigned subStreamCount() override; + SAL_DLLPRIVATE virtual const char* subStreamName(unsigned id) override; + SAL_DLLPRIVATE virtual bool existsSubStream(const char* name) override; + SAL_DLLPRIVATE virtual librevenge::RVNGInputStream* + getSubStreamByName(const char* name) override; + SAL_DLLPRIVATE virtual librevenge::RVNGInputStream* getSubStreamById(unsigned id) override; + + virtual const unsigned char* read(unsigned long numBytes, unsigned long& numBytesRead) override; + virtual int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType) override; + virtual long tell() override; + virtual bool isEnd() override; + +private: + std::unique_ptr m_pImpl; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/DocumentHandler.hxx b/writerperfect/inc/DocumentHandler.hxx new file mode 100644 index 000000000..a79b114f3 --- /dev/null +++ b/writerperfect/inc/DocumentHandler.hxx @@ -0,0 +1,51 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include + +#include + +#include "writerperfectdllapi.h" + +namespace com::sun::star::xml::sax +{ +class XDocumentHandler; +} + +namespace writerperfect +{ +class WRITERPERFECT_DLLPUBLIC DocumentHandler final : public OdfDocumentHandler +{ +public: + DocumentHandler(css::uno::Reference const& xHandler); + SAL_DLLPRIVATE void startDocument() override; + SAL_DLLPRIVATE void endDocument() override; + SAL_DLLPRIVATE void startElement(const char* psName, + const librevenge::RVNGPropertyList& xPropList) override; + SAL_DLLPRIVATE void endElement(const char* psName) override; + SAL_DLLPRIVATE void characters(const librevenge::RVNGString& sCharacters) override; + +private: + css::uno::Reference mxHandler; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/DocumentHandlerFor.hxx b/writerperfect/inc/DocumentHandlerFor.hxx new file mode 100644 index 000000000..a7c7459fd --- /dev/null +++ b/writerperfect/inc/DocumentHandlerFor.hxx @@ -0,0 +1,22 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 + +namespace writerperfect +{ +/** Definition of XML import service used with a Generator. + + This template must be specialized for every libodfgen generator. + */ +template struct DocumentHandlerFor +{ + // static OUString name(); +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/DocumentHandlerForOdg.hxx b/writerperfect/inc/DocumentHandlerForOdg.hxx new file mode 100644 index 000000000..7784dddca --- /dev/null +++ b/writerperfect/inc/DocumentHandlerForOdg.hxx @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 "DocumentHandlerFor.hxx" + +#include + +namespace writerperfect +{ +template <> struct DocumentHandlerFor +{ + static OUString name() { return "com.sun.star.comp.Draw.XMLOasisImporter"; } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/DocumentHandlerForOdp.hxx b/writerperfect/inc/DocumentHandlerForOdp.hxx new file mode 100644 index 000000000..970f129e6 --- /dev/null +++ b/writerperfect/inc/DocumentHandlerForOdp.hxx @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 "DocumentHandlerFor.hxx" + +#include + +namespace writerperfect +{ +template <> struct DocumentHandlerFor +{ + static OUString name() { return "com.sun.star.comp.Impress.XMLOasisImporter"; } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/DocumentHandlerForOds.hxx b/writerperfect/inc/DocumentHandlerForOds.hxx new file mode 100644 index 000000000..226252f09 --- /dev/null +++ b/writerperfect/inc/DocumentHandlerForOds.hxx @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 "DocumentHandlerFor.hxx" + +#include + +namespace writerperfect +{ +template <> struct DocumentHandlerFor +{ + static OUString name() { return "com.sun.star.comp.Calc.XMLOasisImporter"; } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/DocumentHandlerForOdt.hxx b/writerperfect/inc/DocumentHandlerForOdt.hxx new file mode 100644 index 000000000..49af6f9d5 --- /dev/null +++ b/writerperfect/inc/DocumentHandlerForOdt.hxx @@ -0,0 +1,24 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 "DocumentHandlerFor.hxx" + +#include + +namespace writerperfect +{ +template <> struct DocumentHandlerFor +{ + static OUString name() { return "com.sun.star.comp.Writer.XMLOasisImporter"; } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/ImportFilter.hxx b/writerperfect/inc/ImportFilter.hxx new file mode 100644 index 000000000..f2cfb614d --- /dev/null +++ b/writerperfect/inc/ImportFilter.hxx @@ -0,0 +1,183 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "DocumentHandler.hxx" +#include "WPXSvInputStream.hxx" + +#include "DocumentHandlerFor.hxx" + +namespace writerperfect +{ +namespace detail +{ +template +class ImportFilterImpl + : public cppu::WeakImplHelper +{ +public: + ImportFilterImpl(const css::uno::Reference& rxContext) + : mxContext(rxContext) + { + } + + const css::uno::Reference& getXContext() const + { + return mxContext; + } + + // XFilter + virtual sal_Bool SAL_CALL + filter(const css::uno::Sequence& rDescriptor) override + { + utl::MediaDescriptor aDescriptor(rDescriptor); + css::uno::Reference xInputStream; + aDescriptor[utl::MediaDescriptor::PROP_INPUTSTREAM] >>= xInputStream; + if (!xInputStream.is()) + { + OSL_ASSERT(false); + return false; + } + + css::uno::Reference xDialogParent; + aDescriptor["ParentWindow"] >>= xDialogParent; + + // An XML import service: what we push sax messages to... + css::uno::Reference xInternalFilter + = mxContext->getServiceManager()->createInstanceWithContext( + DocumentHandlerFor::name(), mxContext); + 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(mxDoc); + + // OO Graphics Handler: abstract class to handle document SAX messages, concrete implementation here + // writes to in-memory target doc + DocumentHandler aHandler( + new SvXMLLegacyToFastDocHandler(static_cast(xInternalHandler.get()))); + + WPXSvInputStream input(xInputStream); + + Generator exporter; + exporter.addDocumentHandler(&aHandler, ODF_FLAT_XML); + + doRegisterHandlers(exporter); + + return doImportDocument(Application::GetFrameWeld(xDialogParent), input, exporter, + aDescriptor); + } + + virtual void SAL_CALL cancel() override {} + + // XImporter + const css::uno::Reference& getTargetDocument() const { return mxDoc; } + virtual void SAL_CALL + setTargetDocument(const css::uno::Reference& xDoc) override + { + mxDoc = xDoc; + } + + //XExtendedFilterDetection + virtual OUString SAL_CALL + detect(css::uno::Sequence& Descriptor) override + { + OUString sTypeName; + sal_Int32 nLength = Descriptor.getLength(); + sal_Int32 location = nLength; + const css::beans::PropertyValue* pValue = Descriptor.getConstArray(); + css::uno::Reference xInputStream; + for (sal_Int32 i = 0; i < nLength; i++) + { + if (pValue[i].Name == "TypeName") + location = i; + else if (pValue[i].Name == "InputStream") + pValue[i].Value >>= xInputStream; + } + + if (!xInputStream.is()) + return OUString(); + + WPXSvInputStream input(xInputStream); + + if (doDetectFormat(input, sTypeName)) + { + assert(!sTypeName.isEmpty()); + + if (location == nLength) + { + Descriptor.realloc(nLength + 1); + Descriptor.getArray()[location].Name = "TypeName"; + } + + Descriptor.getArray()[location].Value <<= sTypeName; + } + + return sTypeName; + } + + // XInitialization + virtual void SAL_CALL + initialize(const css::uno::Sequence& /*aArguments*/) override + { + } + +private: + virtual bool doDetectFormat(librevenge::RVNGInputStream& rInput, OUString& rTypeName) = 0; + virtual bool doImportDocument(weld::Window* pParent, librevenge::RVNGInputStream& rInput, + Generator& rGenerator, utl::MediaDescriptor& rDescriptor) + = 0; + virtual void doRegisterHandlers(Generator&){}; + + css::uno::Reference mxContext; + css::uno::Reference mxDoc; +}; +} + +/** A base class for import filters. + */ +template +struct ImportFilter : public cppu::ImplInheritanceHelper, + css::lang::XServiceInfo> +{ + ImportFilter(const css::uno::Reference& rxContext) + : cppu::ImplInheritanceHelper, css::lang::XServiceInfo>( + rxContext) + { + } +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/WPFTEncodingDialog.hxx b/writerperfect/inc/WPFTEncodingDialog.hxx new file mode 100644 index 000000000..31df95826 --- /dev/null +++ b/writerperfect/inc/WPFTEncodingDialog.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* MSWorksImportFilter: 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/. + */ + +#pragma once + +#include + +#include "writerperfectdllapi.h" + +namespace writerperfect +{ +class WRITERPERFECT_DLLPUBLIC WPFTEncodingDialog final : public weld::GenericDialogController +{ +public: + WPFTEncodingDialog(weld::Window* pParent, const OUString& title, const OUString& defEncoding); + + virtual ~WPFTEncodingDialog() override; + + OUString GetEncoding() const; + bool hasUserCalledCancel() const { return m_userHasCancelled; } + +private: + bool m_userHasCancelled; + + std::unique_ptr m_xLbCharset; + std::unique_ptr m_xBtnOk; + std::unique_ptr m_xBtnCancel; + +private: + DECL_DLLPRIVATE_LINK(CancelHdl, weld::Button&, void); + + WPFTEncodingDialog(WPFTEncodingDialog const&) = delete; + WPFTEncodingDialog& operator=(WPFTEncodingDialog const&) = delete; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/WPFTResMgr.hxx b/writerperfect/inc/WPFTResMgr.hxx new file mode 100644 index 000000000..5780dd30f --- /dev/null +++ b/writerperfect/inc/WPFTResMgr.hxx @@ -0,0 +1,9 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ + +#pragma once + +#include + +inline OUString WpResId(TranslateId aId) { return Translate::get(aId, Translate::Create("wpt")); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/WPXSvInputStream.hxx b/writerperfect/inc/WPXSvInputStream.hxx new file mode 100644 index 000000000..8cf41d777 --- /dev/null +++ b/writerperfect/inc/WPXSvInputStream.hxx @@ -0,0 +1,54 @@ +/* -*- 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 +#include "writerperfectdllapi.h" +#include + +namespace com::sun::star::io +{ +class XInputStream; +class XSeekable; +} + +namespace writerperfect +{ +class WPXSvInputStreamImpl; + +class SAL_DLLPUBLIC_RTTI WPXSvInputStream final : public librevenge::RVNGInputStream +{ +public: + WRITERPERFECT_DLLPUBLIC + WPXSvInputStream(css::uno::Reference const& xStream); + WRITERPERFECT_DLLPUBLIC virtual ~WPXSvInputStream() override; + + virtual bool isStructured() override; + virtual unsigned subStreamCount() override; + virtual const char* subStreamName(unsigned id) override; + virtual bool existsSubStream(const char* name) override; + virtual librevenge::RVNGInputStream* getSubStreamByName(const char* name) override; + virtual librevenge::RVNGInputStream* getSubStreamById(unsigned id) override; + + WRITERPERFECT_DLLPUBLIC virtual const unsigned char* read(unsigned long numBytes, + unsigned long& numBytesRead) override; + WRITERPERFECT_DLLPUBLIC virtual int seek(long offset, + librevenge::RVNG_SEEK_TYPE seekType) override; + virtual long tell() override; + virtual bool isEnd() override; + +private: + std::unique_ptr mpImpl; +}; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/strings.hrc b/writerperfect/inc/strings.hrc new file mode 100644 index 000000000..a9373d237 --- /dev/null +++ b/writerperfect/inc/strings.hrc @@ -0,0 +1,23 @@ +/* -*- 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 + +#define NC_(Context, String) TranslateId(Context, reinterpret_cast(u8##String)) + +#define STR_ENCODING_DIALOG_TITLE NC_("STR_ENCODING_DIALOG_TITLE", "Import file") +#define STR_ENCODING_DIALOG_TITLE_MSMULTIPLAN NC_("STR_ENCODING_DIALOG_TITLE_MSMULTIPLAN", "Import MS Multiplan for DOS file") +#define STR_ENCODING_DIALOG_TITLE_MSWORKS NC_("STR_ENCODING_DIALOG_TITLE_MSWORKS", "Import MS Works file") +#define STR_ENCODING_DIALOG_TITLE_MSWRITE NC_("STR_ENCODING_DIALOG_TITLE_MSWRITE", "Import MS Write file") +#define STR_ENCODING_DIALOG_TITLE_DOSWORD NC_("STR_ENCODING_DIALOG_TITLE_DOSWORD", "Import MS Word for DOS file") +#define STR_ENCODING_DIALOG_TITLE_LOTUS NC_("STR_ENCODING_DIALOG_TITLE_LOTUS", "Import Lotus file") +#define STR_ENCODING_DIALOG_TITLE_SYMPHONY NC_("STR_ENCODING_DIALOG_TITLE_SYMPHONY", "Import Symphony file") +#define STR_ENCODING_DIALOG_TITLE_QUATTROPRO NC_("STR_ENCODING_DIALOG_TITLE_QUATTROPRO", "Import Quattro Pro file") + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerperfect/inc/writerperfectdllapi.h b/writerperfect/inc/writerperfectdllapi.h new file mode 100644 index 000000000..29f708ffc --- /dev/null +++ b/writerperfect/inc/writerperfectdllapi.h @@ -0,0 +1,20 @@ +/* -*- 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 + +#if defined WRITERPERFECT_DLLIMPLEMENTATION + +#define WRITERPERFECT_DLLPUBLIC SAL_DLLPUBLIC_EXPORT +#else +#define WRITERPERFECT_DLLPUBLIC SAL_DLLPUBLIC_IMPORT +#endif +#define WRITERPERFECT_DLLPRIVATE SAL_DLLPRIVATE + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3