1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/text/XTextDocument.hpp>
21 #include <com/sun/star/container/XEnumerationAccess.hpp>
23 #include <tools/urlobj.hxx>
24 #include <rtl/ref.hxx>
26 #include "vbadocument.hxx"
27 #include "vbadocuments.hxx"
29 #include <osl/file.hxx>
31 #include <unotxdoc.hxx>
33 using namespace ::ooo::vba
;
34 using namespace ::com::sun::star
;
37 getDocument( uno::Reference
< uno::XComponentContext
> const & xContext
, const rtl::Reference
< SwXTextDocument
> &xDoc
, const uno::Any
& aApplication
)
39 // FIXME: fine as long as SwVbaDocument is stateless ...
43 rtl::Reference
<SwVbaDocument
> pWb
= new SwVbaDocument( uno::Reference
< XHelperInterface
>( aApplication
, uno::UNO_QUERY_THROW
), xContext
, xDoc
);
44 return uno::Any( uno::Reference
< word::XDocument
> (pWb
) );
49 class DocumentEnumImpl
: public EnumerationHelperImpl
51 uno::Any m_aApplication
;
53 /// @throws uno::RuntimeException
54 DocumentEnumImpl( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
>& xContext
, const uno::Reference
< container::XEnumeration
>& xEnumeration
, uno::Any aApplication
) : EnumerationHelperImpl( xParent
, xContext
, xEnumeration
), m_aApplication(std::move( aApplication
)) {}
56 virtual uno::Any SAL_CALL
nextElement( ) override
58 uno::Reference
< text::XTextDocument
> xDoc( m_xEnumeration
->nextElement(), uno::UNO_QUERY_THROW
);
59 return getDocument( m_xContext
, dynamic_cast<SwXTextDocument
*>(xDoc
.get()), m_aApplication
);
65 SwVbaDocuments::SwVbaDocuments( const uno::Reference
< XHelperInterface
>& xParent
, const uno::Reference
< uno::XComponentContext
>& xContext
) : SwVbaDocuments_BASE( xParent
, xContext
, VbaDocumentsBase::WORD_DOCUMENT
)
70 SwVbaDocuments::getElementType()
72 return cppu::UnoType
<word::XDocument
>::get();
74 uno::Reference
< container::XEnumeration
>
75 SwVbaDocuments::createEnumeration()
77 // #FIXME it's possible the DocumentEnumImpl here doesn't reflect
78 // the state of this object (although it should) would be
79 // safer to create an enumeration based on this objects state
80 // rather than one effectively based of the desktop component
81 uno::Reference
< container::XEnumerationAccess
> xEnumerationAccess( m_xIndexAccess
, uno::UNO_QUERY_THROW
);
82 return new DocumentEnumImpl( mxParent
, mxContext
, xEnumerationAccess
->createEnumeration(), Application() );
86 SwVbaDocuments::createCollectionObject( const uno::Any
& aSource
)
88 uno::Reference
< text::XTextDocument
> xDoc( aSource
, uno::UNO_QUERY_THROW
);
89 return getDocument( mxContext
, dynamic_cast<SwXTextDocument
*>(xDoc
.get()), Application() );
93 SwVbaDocuments::Add( const uno::Any
& Template
, const uno::Any
& /*NewTemplate*/, const uno::Any
& /*DocumentType*/, const uno::Any
& /*Visible*/ )
96 if( Template
.hasValue() && ( Template
>>= sFileName
) )
98 return Open( sFileName
, uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any());
100 uno::Reference
<text::XTextDocument
> xTextDoc( createDocument() , uno::UNO_QUERY_THROW
);
101 return getDocument( mxContext
, dynamic_cast<SwXTextDocument
*>(xTextDoc
.get()), Application() );
104 // #TODO# #FIXME# can any of the unused params below be used?
105 // #TODO# #FIXME# surely we should actually close the document here
107 SwVbaDocuments::Close( const uno::Any
& /*SaveChanges*/, const uno::Any
& /*OriginalFormat*/, const uno::Any
& /*RouteDocument*/ )
111 // #TODO# #FIXME# can any of the unused params below be used?
113 SwVbaDocuments::Open( const OUString
& Filename
, const uno::Any
& /*ConfirmConversions*/, const uno::Any
& ReadOnly
, const uno::Any
& /*AddToRecentFiles*/, const uno::Any
& /*PasswordDocument*/, const uno::Any
& /*PasswordTemplate*/, const uno::Any
& /*Revert*/, const uno::Any
& /*WritePasswordDocument*/, const uno::Any
& /*WritePasswordTemplate*/, const uno::Any
& /*Format*/, const uno::Any
& /*Encoding*/, const uno::Any
& /*Visible*/, const uno::Any
& /*OpenAndRepair*/, const uno::Any
& /*DocumentDirection*/, const uno::Any
& /*NoEncodingDialog*/, const uno::Any
& /*XMLTransform*/ )
115 SAL_INFO("sw.vba", "Documents.Open(Filename:=" << Filename
<< ",ReadOnly:=" << ReadOnly
<< ")");
117 // we need to detect if this is a URL, if not then assume it's a file path
120 aObj
.SetURL( Filename
);
121 bool bIsURL
= aObj
.GetProtocol() != INetProtocol::NotValid
;
125 osl::FileBase::getFileURLFromSystemPath( Filename
, aURL
);
127 uno::Reference
<text::XTextDocument
> xSpreadDoc( openDocument( Filename
, ReadOnly
, {}), uno::UNO_QUERY_THROW
);
128 uno::Any aRet
= getDocument( mxContext
, dynamic_cast<SwXTextDocument
*>(xSpreadDoc
.get()), Application() );
129 uno::Reference
< word::XDocument
> xDocument( aRet
, uno::UNO_QUERY
);
130 if ( xDocument
.is() )
131 xDocument
->Activate();
136 SwVbaDocuments::OpenNoRepairDialog( const OUString
& Filename
, const uno::Any
& ConfirmConversions
, const uno::Any
& ReadOnly
, const uno::Any
& AddToRecentFiles
, const uno::Any
& PasswordDocument
, const uno::Any
& PasswordTemplate
, const uno::Any
& Revert
, const uno::Any
& WritePasswordDocument
, const uno::Any
& WritePasswordTemplate
, const uno::Any
& Format
, const uno::Any
& Encoding
, const uno::Any
& Visible
, const uno::Any
& OpenAndRepair
, const uno::Any
& DocumentDirection
, const uno::Any
& NoEncodingDialog
, const uno::Any
& XMLTransform
)
138 return Open( Filename
, ConfirmConversions
, ReadOnly
, AddToRecentFiles
, PasswordDocument
, PasswordTemplate
, Revert
, WritePasswordDocument
, WritePasswordTemplate
, Format
, Encoding
, Visible
, OpenAndRepair
, DocumentDirection
, NoEncodingDialog
, XMLTransform
);
142 SwVbaDocuments::OpenOld( const OUString
& FileName
, const uno::Any
& ConfirmConversions
, const uno::Any
& ReadOnly
, const uno::Any
& AddToRecentFiles
, const uno::Any
& PasswordDocument
, const uno::Any
& PasswordTemplate
, const uno::Any
& Revert
, const uno::Any
& WritePasswordDocument
, const uno::Any
& WritePasswordTemplate
, const uno::Any
& Format
)
144 return Open( FileName
, ConfirmConversions
, ReadOnly
, AddToRecentFiles
, PasswordDocument
, PasswordTemplate
, Revert
, WritePasswordDocument
, WritePasswordTemplate
, Format
, uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any() );
148 SwVbaDocuments::getServiceImplName()
150 return u
"SwVbaDocuments"_ustr
;
153 uno::Sequence
<OUString
>
154 SwVbaDocuments::getServiceNames()
156 static uno::Sequence
< OUString
> const sNames
158 u
"ooo.vba.word.Documents"_ustr
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */