diff options
author | Miklos Vajna <vmiklos@frugalware.org> | 2011-08-01 23:41:37 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@frugalware.org> | 2011-08-02 00:29:19 +0200 |
commit | fc7d3ea9f05aa13184259fafaf7d8555c999dc58 (patch) | |
tree | 3dbf572ef4b2e02e0bea607380b49e47ea233c27 /sw | |
parent | b161497053e9fe69e3d2ff897999c22fdba9d163 (diff) |
ImportRTF: use the new uno filter in experimental mode
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/filter/rtf/swparrtf.cxx | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx index cde37b09add3..60e5d46e4502 100644 --- a/sw/source/filter/rtf/swparrtf.cxx +++ b/sw/source/filter/rtf/swparrtf.cxx @@ -103,6 +103,9 @@ #include <svx/xflclit.hxx> #include <svx/xlnwtit.hxx> #include <svx/svdoutl.hxx> +#include <svtools/miscopt.hxx> +#include <unotools/streamwrap.hxx> +#include <comphelper/processfactory.hxx> #include <editeng/outlobj.hxx> #include <editeng/paperinf.hxx> @@ -112,6 +115,9 @@ #include <vcl/salbtype.hxx> // FRound #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XExporter.hpp> 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<lang::XMultiServiceFactory> xMultiServiceFactory(comphelper::getProcessServiceFactory()); + uno::Reference<uno::XInterface> xInterface(xMultiServiceFactory->createInstance( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Writer.RtfFilter"))), uno::UNO_QUERY_THROW); + + uno::Reference<document::XImporter> xImporter(xInterface, uno::UNO_QUERY_THROW); + uno::Reference<lang::XComponent> xDstDoc(pDocShell->GetModel(), uno::UNO_QUERY_THROW); + xImporter->setTargetDocument(xDstDoc); + + uno::Reference<document::XFilter> xFilter(xInterface, uno::UNO_QUERY_THROW); + uno::Sequence<beans::PropertyValue> aDescriptor(1); + aDescriptor[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InputStream")); + uno::Reference<io::XStream> 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(); } |