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 OUString aFilterName;
67 auto& rMediaDescriptor = getMediaDescriptor();
68 rMediaDescriptor[utl::MediaDescriptor::PROP_FILTERNAME] >>= aFilterName;
69 bool bDocm = aFilterName.endsWith("VBA");
70
71 if (!bDocm)
72 {
73 // Check whether application is in headless mode
75 {
76 uno::Reference<document::XStorageBasedDocument> xStorageBasedDocument(
77 pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY);
78 if (xStorageBasedDocument.is())
79 {
80 uno::Reference<embed::XStorage> xDocumentStorage =
81 xStorageBasedDocument->getDocumentStorage();
82 if (xDocumentStorage.is() && xDocumentStorage->hasByName(u"_MS_VBA_Macros"))
83 {
84 // Let user know that macros won't be saved in this format
85 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(
86 nullptr,
87 VclMessageType::Warning, VclButtonsType::OkCancel,
88 SwResId(STR_CANT_SAVE_MACROS))
89 );
90 if (xBox->run() == RET_CANCEL)
91 return false;
92 }
93 }
94 }
95 }
96
97 // get SwPaM*
98 // FIXME so far we get SwPaM for the entire document; probably we should
99 // be able to output just the selection as well - though no idea how to
100 // get the correct SwPaM* then...
101 SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
102 aPam.SetMark();
103 aPam.Move( fnMoveBackward, GoInDoc );
104
105 std::shared_ptr<SwUnoCursor> pCurPam(pDoc->CreateUnoCursor(*aPam.End(), false));
106 pCurPam->SetMark();
107 *pCurPam->GetPoint() = *aPam.Start();
108
109 // export the document
110 // (in a separate block so that it's destructed before the commit)
111 {
112 DocxExport aExport(*this, *pDoc, pCurPam, aPam, bDocm, isExportTemplate());
113 aExport.ExportDocument( true ); // FIXME support exporting selection only
114 }
115
117
118 // delete the pCurPam
119 while ( pCurPam->GetNext() != pCurPam.get() )
120 delete pCurPam->GetNext();
121
122 return true;
123}
124
125// UNO stuff so that the filter is registered
126
128{
129 return "com.sun.star.comp.Writer.DocxExport";
130}
131
132extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
134 uno::Sequence<uno::Any> const& /*rSeq*/)
135{
136 return cppu::acquire(new DocxExportFilter(pCtx));
137}
138
139/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static bool IsHeadlessModeEnabled()
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:3401
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:204
Definition: doc.hxx:197
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
std::shared_ptr< SwUnoCursor > CreateUnoCursor(const SwPosition &rPos, bool bTableCursor=false)
Definition: doc.cxx:1810
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
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:188
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
const SwPosition * End() const
Definition: pam.hxx:263
const SwPosition * Start() const
Definition: pam.hxx:258
SW_DLLPUBLIC void UpdateDataOnActiveSidebarWin()
Definition: PostItMgr.cxx:2391
SW_DLLPUBLIC bool HasActiveSidebarWin() const
Definition: PostItMgr.cxx:2372
virtual void CalcLayout()
Definition: viewsh.cxx:1075
const SwPostItMgr * GetPostItMgr() const
Definition: viewsh.hxx:583
SwDocShell * GetDocShell()
Definition: unotxdoc.hxx:484
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 &)
float u
bool GoInDoc(SwPaM &rPam, SwMoveFnCollection const &fnMove)
Definition: pam.cxx:1182
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
RET_CANCEL