Line data Source code
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 "docxexportfilter.hxx"
21 : #include "rtfexportfilter.hxx"
22 : #include "docxexport.hxx"
23 :
24 : #include <docsh.hxx>
25 : #include <editsh.hxx>
26 : #include <pam.hxx>
27 : #include <unotxdoc.hxx>
28 :
29 : #include <cppuhelper/implementationentry.hxx>
30 :
31 : using namespace ::comphelper;
32 : using namespace ::com::sun::star;
33 :
34 48 : DocxExportFilter::DocxExportFilter( const uno::Reference< uno::XComponentContext >& xContext )
35 48 : : oox::core::XmlFilterBase( xContext )
36 : {
37 48 : }
38 :
39 48 : bool DocxExportFilter::exportDocument()
40 : {
41 : OSL_TRACE( "DocxExportFilter::exportDocument()\n" ); // DEBUG remove me
42 :
43 : // get SwDoc*
44 48 : uno::Reference< uno::XInterface > xIfc( getModel(), uno::UNO_QUERY );
45 48 : SwXTextDocument *pTxtDoc = dynamic_cast< SwXTextDocument * >( xIfc.get() );
46 48 : if ( !pTxtDoc )
47 0 : return false;
48 :
49 48 : SwDoc *pDoc = pTxtDoc->GetDocShell()->GetDoc();
50 48 : if ( !pDoc )
51 0 : return false;
52 :
53 : // update layout (if present), for SwWriteTable
54 48 : ViewShell* pViewShell = NULL;
55 48 : pDoc->GetEditShell(&pViewShell);
56 48 : if (pViewShell != NULL)
57 48 : pViewShell->CalcLayout();
58 :
59 : // get SwPaM*
60 : // FIXME so far we get SwPaM for the entire document; probably we should
61 : // be able to output just the selection as well - though no idea how to
62 : // get the correct SwPaM* then...
63 48 : SwPaM aPam( pDoc->GetNodes().GetEndOfContent() );
64 48 : aPam.SetMark();
65 48 : aPam.Move( fnMoveBackward, fnGoDoc );
66 :
67 48 : SwPaM *pCurPam = new SwPaM( *aPam.End(), *aPam.Start() );
68 :
69 : // export the document
70 : // (in a separate block so that it's destructed before the commit)
71 : {
72 48 : DocxExport aExport( this, pDoc, pCurPam, &aPam );
73 48 : aExport.ExportDocument( true ); // FIXME support exporting selection only
74 : }
75 :
76 48 : commitStorage();
77 :
78 : // delete the pCurPam
79 48 : if ( pCurPam )
80 : {
81 96 : while ( pCurPam->GetNext() != pCurPam )
82 0 : delete pCurPam->GetNext();
83 48 : delete pCurPam;
84 : }
85 :
86 48 : return true;
87 : }
88 :
89 : //////////////////////////////////////////////////////////////////////////
90 : // UNO stuff so that the filter is registered
91 : //////////////////////////////////////////////////////////////////////////
92 :
93 : #define IMPL_NAME "com.sun.star.comp.Writer.DocxExport"
94 :
95 4 : OUString DocxExport_getImplementationName()
96 : {
97 4 : return OUString( IMPL_NAME );
98 : }
99 :
100 0 : OUString DocxExportFilter::implGetImplementationName() const
101 : {
102 0 : return DocxExport_getImplementationName();
103 : }
104 :
105 2 : uno::Sequence< OUString > SAL_CALL DocxExport_getSupportedServiceNames() throw()
106 : {
107 2 : const OUString aServiceName( "com.sun.star.document.ExportFilter" );
108 2 : const uno::Sequence< OUString > aSeq( &aServiceName, 1 );
109 2 : return aSeq;
110 : }
111 :
112 48 : uno::Reference< uno::XInterface > SAL_CALL DocxExport_createInstance(const uno::Reference< uno::XComponentContext > & xCtx ) throw( uno::Exception )
113 : {
114 48 : return (cppu::OWeakObject*) new DocxExportFilter( xCtx );
115 : }
116 :
117 : extern "C"
118 : {
119 :
120 : ::cppu::ImplementationEntry entries [] =
121 : {
122 : {
123 : DocxExport_createInstance, DocxExport_getImplementationName,
124 : DocxExport_getSupportedServiceNames, ::cppu::createSingleComponentFactory,
125 : 0, 0
126 : },
127 : {
128 : RtfExport_createInstance, RtfExport_getImplementationName,
129 : RtfExport_getSupportedServiceNames, ::cppu::createSingleComponentFactory,
130 : 0, 0
131 : },
132 : { 0, 0, 0, 0, 0, 0 }
133 : };
134 :
135 4 : SAL_DLLPUBLIC_EXPORT void* SAL_CALL msword_component_getFactory( const sal_Char* pImplName, void* pServiceManager, void* pRegistryKey )
136 : {
137 4 : return ::cppu::component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey, entries );
138 : }
139 :
140 36 : } // extern "C"
141 :
142 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|