LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbadocuments.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 55 0.0 %
Date: 2014-04-14 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 <boost/unordered_map.hpp>
      51             : #include <osl/file.hxx>
      52             : using namespace ::ooo::vba;
      53             : using namespace ::com::sun::star;
      54             : 
      55             : static uno::Any
      56           0 : getDocument( uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< text::XTextDocument > &xDoc, const uno::Any& aApplication )
      57             : {
      58             :     // FIXME: fine as long as SwVbaDocument is stateless ...
      59           0 :     uno::Reference< frame::XModel > xModel( xDoc, uno::UNO_QUERY );
      60           0 :     if( !xModel.is() )
      61           0 :         return uno::Any();
      62             : 
      63           0 :     SwVbaDocument *pWb = new SwVbaDocument(  uno::Reference< XHelperInterface >( aApplication, uno::UNO_QUERY_THROW ), xContext, xModel );
      64           0 :     return uno::Any( uno::Reference< word::XDocument > (pWb) );
      65             : }
      66             : 
      67           0 : class DocumentEnumImpl : public EnumerationHelperImpl
      68             : {
      69             :     uno::Any m_aApplication;
      70             : public:
      71           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 ) {}
      72             : 
      73           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
      74             :     {
      75           0 :         uno::Reference< text::XTextDocument > xDoc( m_xEnumeration->nextElement(), uno::UNO_QUERY_THROW );
      76           0 :         return getDocument( m_xContext, xDoc, m_aApplication );
      77             :     }
      78             : };
      79             : 
      80           0 : SwVbaDocuments::SwVbaDocuments( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext ) : SwVbaDocuments_BASE( xParent, xContext, VbaDocumentsBase::WORD_DOCUMENT )
      81             : {
      82           0 : }
      83             : // XEnumerationAccess
      84             : uno::Type
      85           0 : SwVbaDocuments::getElementType() throw (uno::RuntimeException)
      86             : {
      87           0 :     return cppu::UnoType<word::XDocument>::get();
      88             : }
      89             : uno::Reference< container::XEnumeration >
      90           0 : SwVbaDocuments::createEnumeration() throw (uno::RuntimeException)
      91             : {
      92             :     // #FIXME its possible the DocumentEnumImpl here doens't reflect
      93             :     // the state of this object ( although it should ) would be
      94             :     // safer to create an enumeration based on this objects state
      95             :     // rather than one effectively based of the desktop component
      96           0 :     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
      97           0 :     return new DocumentEnumImpl( mxParent, mxContext, xEnumerationAccess->createEnumeration(), Application() );
      98             : }
      99             : 
     100             : uno::Any
     101           0 : SwVbaDocuments::createCollectionObject( const uno::Any& aSource )
     102             : {
     103           0 :     uno::Reference< text::XTextDocument > xDoc( aSource, uno::UNO_QUERY_THROW );
     104           0 :     return getDocument( mxContext, xDoc, Application() );
     105             : }
     106             : 
     107             : uno::Any SAL_CALL
     108           0 : SwVbaDocuments::Add( const uno::Any& Template, const uno::Any& /*NewTemplate*/, const uno::Any& /*DocumentType*/, const uno::Any& /*Visible*/ ) throw (uno::RuntimeException, std::exception)
     109             : {
     110           0 :     OUString sFileName;
     111           0 :     if( Template.hasValue() && ( Template >>= sFileName ) )
     112             :     {
     113           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());
     114             :     }
     115           0 :     uno::Reference <text::XTextDocument> xTextDoc( createDocument() , uno::UNO_QUERY_THROW );
     116             : 
     117           0 :     if( xTextDoc.is() )
     118           0 :         return getDocument( mxContext, xTextDoc, Application() );
     119           0 :     return uno::Any();
     120             : }
     121             : 
     122             : // #TODO# #FIXME# can any of the unused params below be used?
     123             : void SAL_CALL
     124           0 : SwVbaDocuments::Close( const uno::Any& /*SaveChanges*/, const uno::Any& /*OriginalFormat*/, const uno::Any& /*RouteDocument*/ ) throw (uno::RuntimeException, std::exception)
     125             : {
     126           0 :     closeDocuments();
     127           0 : }
     128             : 
     129             : // #TODO# #FIXME# can any of the unused params below be used?
     130             : uno::Any SAL_CALL
     131           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)
     132             : {
     133             :     // we need to detect if this is a URL, if not then assume it's a file path
     134           0 :     OUString aURL;
     135           0 :     INetURLObject aObj;
     136           0 :     aObj.SetURL( Filename );
     137           0 :     bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
     138           0 :     if ( bIsURL )
     139           0 :         aURL = Filename;
     140             :     else
     141           0 :         osl::FileBase::getFileURLFromSystemPath( Filename, aURL );
     142             : 
     143           0 :     uno::Sequence< beans::PropertyValue > sProps(0);
     144             : 
     145           0 :     uno::Reference <text::XTextDocument> xSpreadDoc( openDocument( Filename, ReadOnly, sProps ), uno::UNO_QUERY_THROW );
     146           0 :     uno::Any aRet = getDocument( mxContext, xSpreadDoc, Application() );
     147           0 :     uno::Reference< word::XDocument > xDocument( aRet, uno::UNO_QUERY );
     148           0 :     if ( xDocument.is() )
     149           0 :         xDocument->Activate();
     150           0 :     return aRet;
     151             : }
     152             : 
     153             : OUString
     154           0 : SwVbaDocuments::getServiceImplName()
     155             : {
     156           0 :     return OUString("SwVbaDocuments");
     157             : }
     158             : 
     159             : uno::Sequence<OUString>
     160           0 : SwVbaDocuments::getServiceNames()
     161             : {
     162           0 :     static uno::Sequence< OUString > sNames;
     163           0 :     if ( sNames.getLength() == 0 )
     164             :     {
     165           0 :         sNames.realloc( 1 );
     166           0 :         sNames[0] = "ooo.vba.word.Documents";
     167             :     }
     168           0 :     return sNames;
     169             : }
     170             : 
     171             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10