LibreOffice Module sw (master) 1
vbadocuments.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 <com/sun/star/text/XTextDocument.hpp>
21#include <com/sun/star/container/XEnumerationAccess.hpp>
22
23#include <tools/urlobj.hxx>
24#include <rtl/ref.hxx>
25
26#include "vbadocument.hxx"
27#include "vbadocuments.hxx"
28
29#include <osl/file.hxx>
30#include <utility>
31using namespace ::ooo::vba;
32using namespace ::com::sun::star;
33
34static uno::Any
35getDocument( uno::Reference< uno::XComponentContext > const & xContext, const uno::Reference< text::XTextDocument > &xDoc, const uno::Any& aApplication )
36{
37 // FIXME: fine as long as SwVbaDocument is stateless ...
38 if( !xDoc.is() )
39 return uno::Any();
40
41 rtl::Reference<SwVbaDocument> pWb = new SwVbaDocument( uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xDoc );
42 return uno::Any( uno::Reference< word::XDocument > (pWb) );
43}
44
45namespace {
46
47class DocumentEnumImpl : public EnumerationHelperImpl
48{
49 uno::Any m_aApplication;
50public:
52 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 )) {}
53
54 virtual uno::Any SAL_CALL nextElement( ) override
55 {
56 uno::Reference< text::XTextDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
57 return getDocument( m_xContext, xDoc, m_aApplication );
58 }
59};
60
61}
62
63SwVbaDocuments::SwVbaDocuments( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : SwVbaDocuments_BASE( xParent, xContext, VbaDocumentsBase::WORD_DOCUMENT )
64{
65}
66// XEnumerationAccess
69{
71}
72uno::Reference< container::XEnumeration >
74{
75 // #FIXME it's possible the DocumentEnumImpl here doesn't reflect
76 // the state of this object (although it should) would be
77 // safer to create an enumeration based on this objects state
78 // rather than one effectively based of the desktop component
79 uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
80 return new DocumentEnumImpl( mxParent, mxContext, xEnumerationAccess->createEnumeration(), Application() );
81}
82
85{
86 uno::Reference< text::XTextDocument > xDoc( aSource, uno::UNO_QUERY_THROW );
87 return getDocument( mxContext, xDoc, Application() );
88}
89
90uno::Any SAL_CALL
91SwVbaDocuments::Add( const uno::Any& Template, const uno::Any& /*NewTemplate*/, const uno::Any& /*DocumentType*/, const uno::Any& /*Visible*/ )
92{
93 OUString sFileName;
94 if( Template.hasValue() && ( Template >>= sFileName ) )
95 {
96 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());
97 }
98 uno::Reference <text::XTextDocument> xTextDoc( createDocument() , uno::UNO_QUERY_THROW );
99 return getDocument( mxContext, xTextDoc, Application() );
100}
101
102// #TODO# #FIXME# can any of the unused params below be used?
103// #TODO# #FIXME# surely we should actually close the document here
104void SAL_CALL
105SwVbaDocuments::Close( const uno::Any& /*SaveChanges*/, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ )
106{
107}
108
109// #TODO# #FIXME# can any of the unused params below be used?
110uno::Any SAL_CALL
111SwVbaDocuments::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*/ )
112{
113 SAL_INFO("sw.vba", "Documents.Open(Filename:=" << Filename << ",ReadOnly:=" << ReadOnly << ")");
114
115 // we need to detect if this is a URL, if not then assume it's a file path
116 OUString aURL;
117 INetURLObject aObj;
118 aObj.SetURL( Filename );
119 bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
120 if ( bIsURL )
121 aURL = Filename;
122 else
123 osl::FileBase::getFileURLFromSystemPath( Filename, aURL );
124
125 uno::Reference <text::XTextDocument> xSpreadDoc( openDocument( Filename, ReadOnly, {}), uno::UNO_QUERY_THROW );
126 uno::Any aRet = getDocument( mxContext, xSpreadDoc, Application() );
127 uno::Reference< word::XDocument > xDocument( aRet, uno::UNO_QUERY );
128 if ( xDocument.is() )
129 xDocument->Activate();
130 return aRet;
131}
132
133uno::Any SAL_CALL
134SwVbaDocuments::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 )
135{
136 return Open( Filename, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, Encoding, Visible, OpenAndRepair, DocumentDirection, NoEncodingDialog, XMLTransform );
137}
138
139uno::Any SAL_CALL
140SwVbaDocuments::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 )
141{
142 return Open( FileName, ConfirmConversions, ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate, Revert, WritePasswordDocument, WritePasswordTemplate, Format, uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any(), uno::Any() );
143}
144
145OUString
147{
148 return "SwVbaDocuments";
149}
150
151uno::Sequence<OUString>
153{
154 static uno::Sequence< OUString > const sNames
155 {
156 "ooo.vba.word.Documents"
157 };
158 return sNames;
159}
160
161/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
WeakReference< XInterface > mxParent
INetProtocol GetProtocol() const
bool SetURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual css::uno::Type SAL_CALL getElementType() override
virtual OUString getServiceImplName() override
virtual css::uno::Any SAL_CALL OpenNoRepairDialog(const OUString &Filename, const css::uno::Any &ConfirmConversions, const css::uno::Any &ReadOnly, const css::uno::Any &AddToRecentFiles, const css::uno::Any &PasswordDocument, const css::uno::Any &PasswordTemplate, const css::uno::Any &Revert, const css::uno::Any &WritePasswordDocument, const css::uno::Any &WritePasswordTemplate, const css::uno::Any &Format, const css::uno::Any &Encoding, const css::uno::Any &Visible, const css::uno::Any &OpenAndRepair, const css::uno::Any &DocumentDirection, const css::uno::Any &NoEncodingDialog, const css::uno::Any &XMLTransform) override
virtual css::uno::Any SAL_CALL Open(const OUString &Filename, const css::uno::Any &ConfirmConversions, const css::uno::Any &ReadOnly, const css::uno::Any &AddToRecentFiles, const css::uno::Any &PasswordDocument, const css::uno::Any &PasswordTemplate, const css::uno::Any &Revert, const css::uno::Any &WritePasswordDocument, const css::uno::Any &WritePasswordTemplate, const css::uno::Any &Format, const css::uno::Any &Encoding, const css::uno::Any &Visible, const css::uno::Any &OpenAndRepair, const css::uno::Any &DocumentDirection, const css::uno::Any &NoEncodingDialog, const css::uno::Any &XMLTransform) override
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual css::uno::Any createCollectionObject(const css::uno::Any &aSource) override
virtual css::uno::Any SAL_CALL OpenOld(const OUString &FileName, const css::uno::Any &ConfirmConversions, const css::uno::Any &ReadOnly, const css::uno::Any &AddToRecentFiles, const css::uno::Any &PasswordDocument, const css::uno::Any &PasswordTemplate, const css::uno::Any &Revert, const css::uno::Any &WritePasswordDocument, const css::uno::Any &WritePasswordTemplate, const css::uno::Any &Format) override
virtual css::uno::Any SAL_CALL Add(const css::uno::Any &Template, const css::uno::Any &NewTemplate, const css::uno::Any &DocumentType, const css::uno::Any &Visible) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
SwVbaDocuments(const css::uno::Reference< ov::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext)
virtual void SAL_CALL Close(const css::uno::Any &SaveChanges, const css::uno::Any &OriginalFormat, const css::uno::Any &RouteDocument) override
css::uno::Type const & get()
URL aURL
uno::Reference< uno::XComponentContext > mxContext
#define SAL_INFO(area, stream)
Visible
static uno::Any getDocument(uno::Reference< uno::XComponentContext > const &xContext, const uno::Reference< text::XTextDocument > &xDoc, const uno::Any &aApplication)
cppu::ImplInheritanceHelper< VbaDocumentsBase, ov::word::XDocuments > SwVbaDocuments_BASE