LibreOffice Module sw (master) 1
rtfexportfilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "rtfexportfilter.hxx"
21#include "rtfexport.hxx"
22
23#include <docsh.hxx>
25#include <unotxdoc.hxx>
26#include <viewsh.hxx>
27
30
31using namespace ::com::sun::star;
32
33RtfExportFilter::RtfExportFilter(uno::Reference<uno::XComponentContext> xCtx)
34 : m_xCtx(std::move(xCtx))
35{
36}
37
39
40sal_Bool RtfExportFilter::filter(const uno::Sequence<beans::PropertyValue>& aDescriptor)
41{
42 utl::MediaDescriptor aMediaDesc = aDescriptor;
43 uno::Reference<io::XStream> xStream = aMediaDesc.getUnpackedValueOrDefault(
44 utl::MediaDescriptor::PROP_STREAMFOROUTPUT, uno::Reference<io::XStream>());
45 std::unique_ptr<SvStream> pStream = utl::UcbStreamHelper::CreateStream(xStream, true);
46 m_aWriter.SetStream(pStream.get());
47
48 // get SwDoc*
49 uno::Reference<uno::XInterface> xIfc(m_xSrcDoc, uno::UNO_QUERY);
50 auto pTextDoc = dynamic_cast<SwXTextDocument*>(xIfc.get());
51 if (!pTextDoc)
52 {
53 return false;
54 }
55
56 SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
57 if (!pDoc)
58 {
59 return false;
60 }
61
62 // fdo#37161 - update layout (if present), for SwWriteTable
64 if (pViewShell != nullptr)
65 pViewShell->CalcLayout();
66
67 // get SwPaM*
68 // we get SwPaM for the entire document; copy&paste is handled internally, not via UNO
69 SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
70 aPam.SetMark();
72
73 std::shared_ptr<SwUnoCursor> pCurPam(pDoc->CreateUnoCursor(*aPam.End(), false));
74 pCurPam->SetMark();
75 *pCurPam->GetPoint() = *aPam.Start();
76
77 // export the document
78 // (in a separate block so that it's destructed before the commit)
79 {
80 RtfExport aExport(this, *pDoc, pCurPam, aPam, nullptr);
81 aExport.ExportDocument(true);
82 }
83
84 // delete the pCurPam
85 while (pCurPam->GetNext() != pCurPam.get())
86 delete pCurPam->GetNext();
87
88 return true;
89}
90
92
93void RtfExportFilter::setSourceDocument(const uno::Reference<lang::XComponent>& xDoc)
94{
95 m_xSrcDoc = xDoc;
96}
97
98// UNO helpers
99
100extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
102 uno::Sequence<uno::Any> const& /*rSeq*/)
103{
104 return cppu::acquire(new RtfExportFilter(pCtx));
105}
106
107/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XComponentContext > m_xCtx
Reference< XInputStream > xStream
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
ErrCode ExportDocument(bool bWriteAll)
The main function to export the document.
Definition: wrtww8.cxx:3320
The physical access to the RTF document (for writing).
RtfExportFilter(css::uno::Reference< css::uno::XComponentContext > xCtx)
void SAL_CALL setSourceDocument(const css::uno::Reference< css::lang::XComponent > &xDoc) override
~RtfExportFilter() override
sal_Bool SAL_CALL filter(const css::uno::Sequence< css::beans::PropertyValue > &aDescriptor) override
void SAL_CALL cancel() override
css::uno::Reference< css::lang::XComponent > m_xSrcDoc
The class that does all the actual RTF export-related work.
Definition: rtfexport.hxx:37
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
Definition: doc.hxx:192
SwNodes & GetNodes()
Definition: doc.hxx:413
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:406
std::shared_ptr< SwUnoCursor > CreateUnoCursor(const SwPosition &rPos, bool bTableCursor=false)
Definition: doc.cxx:1774
SwDocShell * GetDocShell()
Definition: doc.hxx:1355
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:165
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:612
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:638
const SwPosition * End() const
Definition: pam.hxx:271
const SwPosition * Start() const
Definition: pam.hxx:266
virtual void CalcLayout()
Definition: viewsh.cxx:1082
void SetStream(SvStream *const pStream)
Definition: writer.cxx:220
static constexpr OUStringLiteral PROP_STREAMFOROUTPUT
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:1121
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_RtfExport_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
unsigned char sal_Bool