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::shared_ptr<SwUnoCursor> pCurPam(pDoc->CreateUnoCursor(*aPam.End(), false));
77  pCurPam->SetMark();
78  *pCurPam->GetPoint() = *aPam.Start();
79 
80  OUString aFilterName;
82  bool bDocm = aFilterName.endsWith("VBA");
83 
84  // export the document
85  // (in a separate block so that it's destructed before the commit)
86  {
87  DocxExport aExport(this, pDoc, pCurPam, &aPam, bDocm, isExportTemplate());
88  aExport.ExportDocument( true ); // FIXME support exporting selection only
89  }
90 
91  commitStorage();
92 
93  // delete the pCurPam
94  while ( pCurPam->GetNext() != pCurPam.get() )
95  delete pCurPam->GetNext();
96 
97  return true;
98 }
99 
100 // UNO stuff so that the filter is registered
101 
103 {
104  return "com.sun.star.comp.Writer.DocxExport";
105 }
106 
107 extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
109  uno::Sequence<uno::Any> const& /*rSeq*/)
110 {
111  return cppu::acquire(new DocxExportFilter(pCtx));
112 }
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< SwUnoCursor > CreateUnoCursor(const SwPosition &rPos, bool bTableCursor=false)
Definition: doc.cxx:1797
virtual void CalcLayout()
Definition: viewsh.cxx:984
static const OUString & PROP_FILTERNAME()
Definition: doc.hxx:185
The class that does all the actual DOCX export-related work.
Definition: docxexport.hxx:65
utl::MediaDescriptor & getMediaDescriptor() const
bool isExportTemplate() const
virtual OUString SAL_CALL getImplementationName() override
SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin()
Definition: PostItMgr.cxx:2342
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:463
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:884
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
const css::uno::Reference< css::frame::XModel > & getModel() const
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2323
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:402
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:459
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:3223