LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbadocuments.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 54 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          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             : #include <comphelper/processfactory.hxx>
      20             : 
      21             : #include <cppuhelper/implbase1.hxx>
      22             : #include <cppuhelper/implbase3.hxx>
      23             : 
      24             : #include <com/sun/star/frame/XDesktop.hpp>
      25             : #include <com/sun/star/text/XTextDocument.hpp>
      26             : #include <com/sun/star/container/XEnumerationAccess.hpp>
      27             : #include <com/sun/star/frame/XComponentLoader.hpp>
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/frame/XModel.hpp>
      30             : #include <com/sun/star/frame/XFrame.hpp>
      31             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      32             : #include <com/sun/star/util/XModifiable.hpp>
      33             : #include <com/sun/star/frame/XStorable.hpp>
      34             : #include <com/sun/star/lang/DisposedException.hpp>
      35             : #include <com/sun/star/beans/PropertyVetoException.hpp>
      36             : #include <com/sun/star/util/XCloseable.hpp>
      37             : #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
      38             : #include <com/sun/star/document/XTypeDetection.hpp>
      39             : #include <com/sun/star/uri/XUriReference.hpp>
      40             : #include <com/sun/star/uri/XUriReferenceFactory.hpp>
      41             : 
      42             : #include <sfx2/objsh.hxx>
      43             : #include <tools/urlobj.hxx>
      44             : 
      45             : #include "vbaglobals.hxx"
      46             : #include "vbadocument.hxx"
      47             : #include "vbadocuments.hxx"
      48             : #include <vbahelper/vbahelper.hxx>
      49             : 
      50             : #include <osl/file.hxx>
      51             : using namespace ::ooo::vba;
      52             : using namespace ::com::sun::star;
      53             : 
      54             : static uno::Any
      55           0 : getDocument( uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< text::XTextDocument > &xDoc, const uno::Any& aApplication )
      56             : {
      57             :     // FIXME: fine as long as SwVbaDocument is stateless ...
      58           0 :     uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY );
      59           0 :     if( !xModel.is() )
      60           0 :         return uno::Any();
      61             : 
      62           0 :     SwVbaDocument *pWb = new SwVbaDocument(  uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xModel );
      63           0 :     return uno::Any( uno::Reference< word::XDocument > (pWb) );
      64             : }
      65             : 
      66           0 : class DocumentEnumImpl : public EnumerationHelperImpl
      67             : {
      68             :     uno::Any m_aApplication;
      69             : public:
      70           0 :     DocumentEnumImpl( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< container::XEnumeration >& xEnumeration, const uno::Any& aApplication ) throw ( uno::RuntimeException ) : EnumerationHelperImpl( xParent, xContext, xEnumeration ), m_aApplication( aApplication ) {}
      71             : 
      72           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      73             :     {
      74           0 :         uno::Reference< text::XTextDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
      75           0 :         return getDocument( m_xContext, xDoc, m_aApplication );
      76             :     }
      77             : };
      78             : 
      79           0 : SwVbaDocuments::SwVbaDocuments( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : SwVbaDocuments_BASE( xParent, xContext, VbaDocumentsBase::WORD_DOCUMENT )
      80             : {
      81           0 : }
      82             : // XEnumerationAccess
      83             : uno::Type
      84           0 : SwVbaDocuments::getElementType() throw (uno::RuntimeException)
      85             : {
      86           0 :     return cppu::UnoType<word::XDocument>::get();
      87             : }
      88             : uno::Reference< container::XEnumeration >
      89           0 : SwVbaDocuments::createEnumeration() throw (uno::RuntimeException)
      90             : {
      91             :     // #FIXME its possible the DocumentEnumImpl here doesn't reflect
      92             :     // the state of this object ( although it should ) would be
      93             :     // safer to create an enumeration based on this objects state
      94             :     // rather than one effectively based of the desktop component
      95           0 :     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
      96           0 :     return new DocumentEnumImpl( mxParent, mxContext, xEnumerationAccess->createEnumeration(), Application() );
      97             : }
      98             : 
      99             : uno::Any
     100           0 : SwVbaDocuments::createCollectionObject( const uno::Any& aSource )
     101             : {
     102           0 :     uno::Reference< text::XTextDocument > xDoc( aSource, uno::UNO_QUERY_THROW );
     103           0 :     return getDocument( mxContext, xDoc, Application() );
     104             : }
     105             : 
     106             : uno::Any SAL_CALL
     107           0 : SwVbaDocuments::Add( const uno::Any& Template, const uno::Any& /*NewTemplate*/, const uno::Any& /*DocumentType*/, const uno::Any& /*Visible*/ ) throw (uno::RuntimeException, std::exception)
     108             : {
     109           0 :     OUString sFileName;
     110           0 :     if( Template.hasValue() && ( Template >>= sFileName ) )
     111             :     {
     112           0 :         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());
     113             :     }
     114           0 :     uno::Reference <text::XTextDocument> xTextDoc( createDocument() , uno::UNO_QUERY_THROW );
     115             : 
     116           0 :     if( xTextDoc.is() )
     117           0 :         return getDocument( mxContext, xTextDoc, Application() );
     118           0 :     return uno::Any();
     119             : }
     120             : 
     121             : // #TODO# #FIXME# can any of the unused params below be used?
     122             : void SAL_CALL
     123           0 : SwVbaDocuments::Close( const uno::Any& /*SaveChanges*/, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ ) throw (uno::RuntimeException, std::exception)
     124             : {
     125           0 : }
     126             : 
     127             : // #TODO# #FIXME# can any of the unused params below be used?
     128             : uno::Any SAL_CALL
     129           0 : 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*/ ) throw (uno::RuntimeException, std::exception)
     130             : {
     131             :     // we need to detect if this is a URL, if not then assume it's a file path
     132           0 :     OUString aURL;
     133           0 :     INetURLObject aObj;
     134           0 :     aObj.SetURL( Filename );
     135           0 :     bool bIsURL = aObj.GetProtocol() != INetProtocol::NotValid;
     136           0 :     if ( bIsURL )
     137           0 :         aURL = Filename;
     138             :     else
     139           0 :         osl::FileBase::getFileURLFromSystemPath( Filename, aURL );
     140             : 
     141           0 :     uno::Sequence< beans::PropertyValue > sProps(0);
     142             : 
     143           0 :     uno::Reference <text::XTextDocument> xSpreadDoc( openDocument( Filename, ReadOnly, sProps ), uno::UNO_QUERY_THROW );
     144           0 :     uno::Any aRet = getDocument( mxContext, xSpreadDoc, Application() );
     145           0 :     uno::Reference< word::XDocument > xDocument( aRet, uno::UNO_QUERY );
     146           0 :     if ( xDocument.is() )
     147           0 :         xDocument->Activate();
     148           0 :     return aRet;
     149             : }
     150             : 
     151             : OUString
     152           0 : SwVbaDocuments::getServiceImplName()
     153             : {
     154           0 :     return OUString("SwVbaDocuments");
     155             : }
     156             : 
     157             : uno::Sequence<OUString>
     158           0 : SwVbaDocuments::getServiceNames()
     159             : {
     160           0 :     static uno::Sequence< OUString > sNames;
     161           0 :     if ( sNames.getLength() == 0 )
     162             :     {
     163           0 :         sNames.realloc( 1 );
     164           0 :         sNames[0] = "ooo.vba.word.Documents";
     165             :     }
     166           0 :     return sNames;
     167             : }
     168             : 
     169             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11