From bd94c29f549507cc4079888927213c4e7b9a1092 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 1 Aug 2011 23:41:37 +0200 Subject: ImportRTF: use the new uno filter in experimental mode --- sw/source/filter/rtf/swparrtf.cxx | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx index 15dbfa86c4..23a9f658b6 100644 --- a/sw/source/filter/rtf/swparrtf.cxx +++ b/sw/source/filter/rtf/swparrtf.cxx @@ -103,6 +103,9 @@ #include #include #include +#include +#include +#include #include #include @@ -112,6 +115,9 @@ #include // FRound #include +#include +#include +#include using namespace ::com::sun::star; @@ -125,8 +131,41 @@ inline const SvxLRSpaceItem& GetLRSpace(const SfxItemSet& rSet,sal_Bool bInP=sal { return (const SvxLRSpaceItem&)rSet.Get( RES_LR_SPACE,bInP); } +/// Glue class to call RtfImport as an internal filter, needed by copy&paste support. +class SwRTFReader : public Reader +{ + virtual sal_uLong Read( SwDoc &, const String& rBaseURL, SwPaM &,const String &); +}; + +sal_uLong SwRTFReader::Read( SwDoc &rDoc, const String& /*rBaseURL*/, SwPaM& /*rPam*/, const String &) +{ + if (!pStrm) + return ERR_SWG_READ_ERROR; + + SwDocShell *pDocShell(rDoc.GetDocShell()); + uno::Reference xMultiServiceFactory(comphelper::getProcessServiceFactory()); + uno::Reference xInterface(xMultiServiceFactory->createInstance( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.RtfFilter"))), uno::UNO_QUERY_THROW); + + uno::Reference xImporter(xInterface, uno::UNO_QUERY_THROW); + uno::Reference xDstDoc(pDocShell->GetModel(), uno::UNO_QUERY_THROW); + xImporter->setTargetDocument(xDstDoc); + + uno::Reference xFilter(xInterface, uno::UNO_QUERY_THROW); + uno::Sequence aDescriptor(1); + aDescriptor[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream")); + uno::Reference xStream(new utl::OStreamWrapper(*pStrm)); + aDescriptor[0].Value <<= xStream; + xFilter->filter(aDescriptor); + + return 0; +} + extern "C" SAL_DLLPUBLIC_EXPORT Reader* SAL_CALL ImportRTF() { + SvtMiscOptions aMiscOptions; + if (aMiscOptions.IsExperimentalMode()) + return new SwRTFReader(); return new RtfReader(); } -- cgit v1.2.3