LibreOffice Module sw (master) 1
docxexportfilter.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 <memory>
21#include "docxexportfilter.hxx"
22#include "docxexport.hxx"
23
24#include <docsh.hxx>
25#include <pam.hxx>
26#include <PostItMgr.hxx>
27#include <unotxdoc.hxx>
29#include <viewsh.hxx>
30
32
33using namespace ::comphelper;
34using namespace ::com::sun::star;
35
36DocxExportFilter::DocxExportFilter( const uno::Reference< uno::XComponentContext >& xContext )
37 : oox::core::XmlFilterBase( xContext )
38{
39}
40
42{
43 // get SwDoc*
44 uno::Reference< uno::XInterface > xIfc( getModel(), uno::UNO_QUERY );
45 SwXTextDocument *pTextDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
46 if ( !pTextDoc )
47 return false;
48
49 SwDoc *pDoc = pTextDoc->GetDocShell()->GetDoc();
50 if ( !pDoc )
51 return false;
52
53 // update layout (if present), for SwWriteTable
55 if (pViewShell != nullptr)
56 pViewShell->CalcLayout();
57
58 // if we have an active postit window, update the document model
59 if (pViewShell &&
60 pViewShell->GetPostItMgr() &&
61 pViewShell->GetPostItMgr()->HasActiveSidebarWin())
62 {
64 }
65
66 // get SwPaM*
67 // FIXME so far we get SwPaM for the entire document; probably we should
68 // be able to output just the selection as well - though no idea how to
69 // get the correct SwPaM* then...
70 SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
71 aPam.SetMark();
73
74 std::shared_ptr<SwUnoCursor> pCurPam(pDoc->CreateUnoCursor(*aPam.End(), false));
75 pCurPam->SetMark();
76 *pCurPam->GetPoint() = *aPam.Start();
77
78 OUString aFilterName;
80 bool bDocm = aFilterName.endsWith("VBA");
81
82 // export the document
83 // (in a separate block so that it's destructed before the commit)
84 {
85 DocxExport aExport(*this, *pDoc, pCurPam, aPam, bDocm, isExportTemplate());
86 aExport.ExportDocument( true ); // FIXME support exporting selection only
87 }
88
90
91 // delete the pCurPam
92 while ( pCurPam->GetNext() != pCurPam.get() )
93 delete pCurPam->GetNext();
94
95 return true;
96}
97
98// UNO stuff so that the filter is registered
99
101{
102 return "com.sun.star.comp.Writer.DocxExport";
103}
104
105extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
107 uno::Sequence<uno::Any> const& /*rSeq*/)
108{
109 return cppu::acquire(new DocxExportFilter(pCtx));
110}
111
112/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The physical access to the DOCX document (for writing).
virtual OUString SAL_CALL getImplementationName() override
virtual bool exportDocument() override
DocxExportFilter(const css::uno::Reference< css::uno::XComponentContext > &xContext)
The class that does all the actual DOCX export-related work.
Definition: docxexport.hxx:75
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
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
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
SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin()
Definition: PostItMgr.cxx:2397
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2378
virtual void CalcLayout()
Definition: viewsh.cxx:1082
const SwPostItMgr * GetPostItMgr() const
Definition: viewsh.hxx:569
SwDocShell * GetDocShell()
Definition: unotxdoc.hxx:469
utl::MediaDescriptor & getMediaDescriptor() const
const css::uno::Reference< css::frame::XModel > & getModel() const
void commitStorage() const
bool isExportTemplate() const
static constexpr OUStringLiteral PROP_FILTERNAME
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_DocxExport_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:1121
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58