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 "rtfexportfilter.hxx"
23 #include "docxexport.hxx"
24 
25 #include <docsh.hxx>
26 #include <editsh.hxx>
27 #include <pam.hxx>
28 #include <PostItMgr.hxx>
29 #include <unotxdoc.hxx>
31 
34 
35 using namespace ::comphelper;
36 using namespace ::com::sun::star;
37 
38 DocxExportFilter::DocxExportFilter( const uno::Reference< uno::XComponentContext >& xContext )
39  : oox::core::XmlFilterBase( xContext )
40 {
41 }
42 
44 {
45  // get SwDoc*
46  uno::Reference< uno::XInterface > xIfc( getModel(), uno::UNO_QUERY );
47  SwXTextDocument *pTextDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
48  if ( !pTextDoc )
49  return false;
50 
51  SwDoc *pDoc = pTextDoc->GetDocShell()->GetDoc();
52  if ( !pDoc )
53  return false;
54 
55  // update layout (if present), for SwWriteTable
57  if (pViewShell != nullptr)
58  pViewShell->CalcLayout();
59 
60  // if we have an active postit window, update the document model
61  if (pViewShell &&
62  pViewShell->GetPostItMgr() &&
63  pViewShell->GetPostItMgr()->HasActiveSidebarWin())
64  {
66  }
67 
68  // get SwPaM*
69  // FIXME so far we get SwPaM for the entire document; probably we should
70  // be able to output just the selection as well - though no idea how to
71  // get the correct SwPaM* then...
72  SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
73  aPam.SetMark();
74  aPam.Move( fnMoveBackward, GoInDoc );
75 
76  std::unique_ptr<SwPaM> pCurPam( new SwPaM( *aPam.End(), *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.get(), &aPam, bDocm, isExportTemplate());
86  aExport.ExportDocument( true ); // FIXME support exporting selection only
87  }
88 
89  commitStorage();
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 OUString("com.sun.star.comp.Writer.DocxExport");
103 }
104 
105 extern "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: */
virtual void CalcLayout()
Definition: viewsh.cxx:983
static const OUString & PROP_FILTERNAME()
Definition: doc.hxx:185
The class that does all the actual DOCX export-related work.
Definition: docxexport.hxx:68
utl::MediaDescriptor & getMediaDescriptor() const
bool isExportTemplate() const
virtual OUString SAL_CALL getImplementationName() override
SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin()
Definition: PostItMgr.cxx:2304
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:164
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:203
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
SwDocShell * GetDocShell()
Definition: unotxdoc.hxx:464
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:882
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:437
const css::uno::Reference< css::frame::XModel > & getModel() const
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2285
DocxExportFilter(const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
SwNodes & GetNodes()
Definition: doc.hxx:403
The physical access to the DOCX document (for writing).
virtual bool exportDocument() override
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
const SwPostItMgr * GetPostItMgr() const
Definition: viewsh.hxx:559
void commitStorage() const
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:457
SAL_DLLPUBLIC_EXPORT uno::XInterface * com_sun_star_comp_Writer_DocxExport_get_implementation(uno::XComponentContext *pCtx, uno::Sequence< uno::Any > const &)
ErrCode ExportDocument(bool bWriteAll)
The main function to export the document.
Definition: wrtww8.cxx:3154