LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/vba - vbadocument.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 244 1.2 %
Date: 2012-12-27 Functions: 2 51 3.9 %
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 "vbadocument.hxx"
      20             : #include "vbarange.hxx"
      21             : #include "vbarangehelper.hxx"
      22             : #include "vbadocumentproperties.hxx"
      23             : #include "vbabookmarks.hxx"
      24             : #include "vbavariables.hxx"
      25             : #include <com/sun/star/text/XBookmarksSupplier.hpp>
      26             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      27             : #include <com/sun/star/document/XDocumentProperties.hpp>
      28             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      29             : #include <com/sun/star/drawing/XControlShape.hpp>
      30             : #include <com/sun/star/form/XFormsSupplier.hpp>
      31             : #include <com/sun/star/document/XRedlinesSupplier.hpp>
      32             : #include <ooo/vba/XControlProvider.hpp>
      33             : #include <ooo/vba/word/WdProtectionType.hpp>
      34             : 
      35             : #include <vbahelper/helperdecl.hxx>
      36             : #include <wordvbahelper.hxx>
      37             : #include <docsh.hxx>
      38             : #include "vbatemplate.hxx"
      39             : #include "vbaparagraph.hxx"
      40             : #include "vbastyles.hxx"
      41             : #include "vbatables.hxx"
      42             : #include "vbafield.hxx"
      43             : #include "vbapagesetup.hxx"
      44             : #include "vbasections.hxx"
      45             : #include "vbatablesofcontents.hxx"
      46             : #include <vbahelper/vbashapes.hxx>
      47             : #include <vbahelper/vbahelper.hxx>
      48             : #include "vbarevisions.hxx"
      49             : #include "vbaframes.hxx"
      50             : #include "vbaformfields.hxx"
      51             : #include <osl/file.hxx>
      52             : #include <tools/urlobj.hxx>
      53             : 
      54             : using namespace ::ooo::vba;
      55             : using namespace ::com::sun::star;
      56             : 
      57           0 : SwVbaDocument::SwVbaDocument( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, uno::Reference< frame::XModel > xModel ): SwVbaDocument_BASE( xParent, xContext, xModel )
      58             : {
      59           0 :     Initialize();
      60           0 : }
      61           0 : SwVbaDocument::SwVbaDocument( uno::Sequence< uno::Any > const& aArgs, uno::Reference< uno::XComponentContext >const& xContext ) : SwVbaDocument_BASE( aArgs, xContext )
      62             : {
      63           0 :     Initialize();
      64           0 : }
      65             : 
      66           0 : SwVbaDocument::~SwVbaDocument()
      67             : {
      68           0 : }
      69             : 
      70           0 : void SwVbaDocument::Initialize()
      71             : {
      72           0 :     mxTextDocument.set( getModel(), uno::UNO_QUERY_THROW );
      73           0 : }
      74             : 
      75             : uno::Reference< word::XRange > SAL_CALL
      76           0 : SwVbaDocument::getContent() throw ( uno::RuntimeException )
      77             : {
      78           0 :     uno::Reference< text::XTextRange > xStart = mxTextDocument->getText()->getStart();
      79           0 :     uno::Reference< text::XTextRange > xEnd;
      80           0 :     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd, sal_True ) );
      81             : }
      82             : 
      83             : uno::Reference< word::XRange > SAL_CALL
      84           0 : SwVbaDocument::Range( const uno::Any& rStart, const uno::Any& rEnd ) throw ( uno::RuntimeException )
      85             : {
      86           0 :     if( !rStart.hasValue() && !rEnd.hasValue() )
      87           0 :         return getContent();
      88             : 
      89           0 :     sal_Int32 nStart = 0;
      90           0 :     sal_Int32 nEnd = 0;
      91           0 :     rStart >>= nStart;
      92           0 :     rEnd >>= nEnd;
      93           0 :     nStart--;
      94           0 :     nEnd--;
      95             : 
      96           0 :     uno::Reference< text::XTextRange > xStart;
      97           0 :     uno::Reference< text::XTextRange > xEnd;
      98           0 :     if( nStart != -1 || nEnd != -1 )
      99             :     {
     100           0 :         if( nStart == -1 )
     101           0 :             xStart = mxTextDocument->getText()->getStart();
     102             :         else
     103           0 :             xStart = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nStart );
     104             : 
     105           0 :         if( nEnd == -1 )
     106           0 :             xEnd = mxTextDocument->getText()->getEnd();
     107             :         else
     108           0 :             xEnd = SwVbaRangeHelper::getRangeByPosition( mxTextDocument->getText(), nEnd );
     109             :     }
     110             : 
     111           0 :     if( !xStart.is() && !xEnd.is() )
     112             :     {
     113             :         try
     114             :         {
     115             :             // FIXME
     116           0 :             xStart = mxTextDocument->getText()->getStart();
     117           0 :             xEnd = mxTextDocument->getText()->getEnd();
     118             :         }
     119           0 :         catch(const uno::Exception&)
     120             :         {
     121           0 :             DebugHelper::exception(SbERR_METHOD_FAILED, rtl::OUString());
     122             :         }
     123             :     }
     124           0 :     return uno::Reference< word::XRange >( new SwVbaRange( this, mxContext, mxTextDocument, xStart, xEnd ) );
     125             : }
     126             : 
     127             : uno::Any SAL_CALL
     128           0 : SwVbaDocument::BuiltInDocumentProperties( const uno::Any& index ) throw (uno::RuntimeException)
     129             : {
     130           0 :     uno::Reference< XCollection > xCol( new SwVbaBuiltinDocumentProperties( mxParent, mxContext, getModel() ) );
     131           0 :     if ( index.hasValue() )
     132           0 :         return xCol->Item( index, uno::Any() );
     133           0 :     return uno::makeAny( xCol );
     134             : }
     135             : 
     136             : uno::Any SAL_CALL
     137           0 : SwVbaDocument::CustomDocumentProperties( const uno::Any& index ) throw (uno::RuntimeException)
     138             : {
     139           0 :     uno::Reference< XCollection > xCol( new SwVbaCustomDocumentProperties( mxParent, mxContext, getModel() ) );
     140           0 :     if ( index.hasValue() )
     141           0 :         return xCol->Item( index, uno::Any() );
     142           0 :     return uno::makeAny( xCol );
     143             : }
     144             : 
     145             : uno::Any SAL_CALL
     146           0 : SwVbaDocument::Bookmarks( const uno::Any& rIndex ) throw ( uno::RuntimeException )
     147             : {
     148           0 :     uno::Reference< text::XBookmarksSupplier > xBookmarksSupplier( getModel(),uno::UNO_QUERY_THROW );
     149           0 :     uno::Reference<container::XIndexAccess > xBookmarks( xBookmarksSupplier->getBookmarks(), uno::UNO_QUERY_THROW );
     150           0 :     uno::Reference< XCollection > xBookmarksVba( new SwVbaBookmarks( this, mxContext, xBookmarks, getModel() ) );
     151           0 :     if (  rIndex.getValueTypeClass() == uno::TypeClass_VOID )
     152           0 :         return uno::makeAny( xBookmarksVba );
     153             : 
     154           0 :     return uno::Any( xBookmarksVba->Item( rIndex, uno::Any() ) );
     155             : }
     156             : 
     157             : uno::Any SAL_CALL
     158           0 : SwVbaDocument::Variables( const uno::Any& rIndex ) throw ( uno::RuntimeException )
     159             : {
     160           0 :     uno::Reference< document::XDocumentPropertiesSupplier > xDocumentPropertiesSupplier( getModel(),uno::UNO_QUERY_THROW );
     161           0 :     uno::Reference< document::XDocumentProperties > xDocumentProperties =  xDocumentPropertiesSupplier->getDocumentProperties();
     162           0 :     uno::Reference< beans::XPropertyAccess > xUserDefined( xDocumentProperties->getUserDefinedProperties(), uno::UNO_QUERY_THROW );
     163             : 
     164           0 :     uno::Reference< XCollection > xVariables( new SwVbaVariables( this, mxContext, xUserDefined ) );
     165           0 :     if (  rIndex.getValueTypeClass() == uno::TypeClass_VOID )
     166           0 :         return uno::makeAny( xVariables );
     167             : 
     168           0 :     return uno::Any( xVariables->Item( rIndex, uno::Any() ) );
     169             : }
     170             : 
     171             : uno::Any SAL_CALL
     172           0 : SwVbaDocument::Paragraphs( const uno::Any& index ) throw (uno::RuntimeException)
     173             : {
     174           0 :     uno::Reference< XCollection > xCol( new SwVbaParagraphs( mxParent, mxContext, mxTextDocument ) );
     175           0 :     if ( index.hasValue() )
     176           0 :         return xCol->Item( index, uno::Any() );
     177           0 :     return uno::makeAny( xCol );
     178             : }
     179             : 
     180             : uno::Any SAL_CALL
     181           0 : SwVbaDocument::Styles( const uno::Any& index ) throw (uno::RuntimeException)
     182             : {
     183           0 :     uno::Reference< XCollection > xCol( new SwVbaStyles( mxParent, mxContext, getModel() ) );
     184           0 :     if ( index.hasValue() )
     185           0 :         return xCol->Item( index, uno::Any() );
     186           0 :     return uno::makeAny( xCol );
     187             : }
     188             : 
     189             : uno::Any SAL_CALL
     190           0 : SwVbaDocument::Fields( const uno::Any& index ) throw (uno::RuntimeException)
     191             : {
     192           0 :     uno::Reference< XCollection > xCol( new SwVbaFields( mxParent, mxContext, getModel() ) );
     193           0 :     if ( index.hasValue() )
     194           0 :         return xCol->Item( index, uno::Any() );
     195           0 :     return uno::makeAny( xCol );
     196             : }
     197             : 
     198             : uno::Any SAL_CALL
     199           0 : SwVbaDocument::Shapes( const uno::Any& index ) throw (uno::RuntimeException)
     200             : {
     201           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( getModel(), uno::UNO_QUERY_THROW );
     202           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
     203           0 :     uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
     204           0 :     uno::Reference< XCollection > xCol( new ScVbaShapes( this, mxContext, xIndexAccess, xModel ) );
     205             : 
     206           0 :     if ( index.hasValue() )
     207           0 :         return xCol->Item( index, uno::Any() );
     208           0 :     return uno::makeAny( xCol );
     209             : }
     210             : 
     211             : uno::Any SAL_CALL
     212           0 : SwVbaDocument::Sections( const uno::Any& index ) throw (uno::RuntimeException)
     213             : {
     214           0 :     uno::Reference< XCollection > xCol( new SwVbaSections( mxParent, mxContext, getModel() ) );
     215           0 :     if ( index.hasValue() )
     216           0 :         return xCol->Item( index, uno::Any() );
     217           0 :     return uno::makeAny( xCol );
     218             : }
     219             : 
     220             : uno::Any SAL_CALL
     221           0 : SwVbaDocument::TablesOfContents( const uno::Any& index ) throw (uno::RuntimeException)
     222             : {
     223           0 :     uno::Reference< XCollection > xCol( new SwVbaTablesOfContents( this, mxContext, mxTextDocument ) );
     224           0 :     if ( index.hasValue() )
     225           0 :         return xCol->Item( index, uno::Any() );
     226           0 :     return uno::makeAny( xCol );
     227             : }
     228             : 
     229             : uno::Any SAL_CALL
     230           0 : SwVbaDocument::FormFields( const uno::Any& /*index*/ ) throw (uno::RuntimeException)
     231             : {
     232           0 :     uno::Reference< XCollection > xCol;
     233           0 :     return uno::makeAny( xCol );
     234             : }
     235             : 
     236             : uno::Any SAL_CALL
     237           0 : SwVbaDocument::PageSetup( ) throw (uno::RuntimeException)
     238             : {
     239           0 :     uno::Reference< beans::XPropertySet > xPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
     240           0 :     return uno::makeAny( uno::Reference< word::XPageSetup >( new SwVbaPageSetup( this, mxContext, mxModel, xPageProps ) ) );
     241             : }
     242             : 
     243             : rtl::OUString
     244           0 : SwVbaDocument::getServiceImplName()
     245             : {
     246           0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaDocument"));
     247             : }
     248             : 
     249             : uno::Any SAL_CALL
     250           0 : SwVbaDocument::getAttachedTemplate() throw (uno::RuntimeException)
     251             : {
     252           0 :     uno::Reference< word::XTemplate > xTemplate;
     253             :     uno::Reference<document::XDocumentPropertiesSupplier> const xDocPropSupp(
     254           0 :             getModel(), uno::UNO_QUERY_THROW);
     255           0 :     uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
     256           0 :     rtl::OUString sTemplateUrl = xDocProps->getTemplateURL();
     257             : 
     258           0 :     xTemplate = new SwVbaTemplate( this, mxContext, getModel(), sTemplateUrl );
     259           0 :     return uno::makeAny( xTemplate );
     260             : }
     261             : 
     262             : void SAL_CALL
     263           0 : SwVbaDocument::setAttachedTemplate( const css::uno::Any& _attachedtemplate ) throw (uno::RuntimeException)
     264             : {
     265           0 :     rtl::OUString sTemplate;
     266           0 :     if( !( _attachedtemplate >>= sTemplate ) )
     267             :     {
     268           0 :         throw uno::RuntimeException();
     269             :     }
     270           0 :     rtl::OUString aURL;
     271           0 :     INetURLObject aObj;
     272           0 :     aObj.SetURL( sTemplate );
     273           0 :     bool bIsURL = aObj.GetProtocol() != INET_PROT_NOT_VALID;
     274           0 :     if ( bIsURL )
     275           0 :         aURL = sTemplate;
     276             :     else
     277           0 :         osl::FileBase::getFileURLFromSystemPath( sTemplate, aURL );
     278             : 
     279           0 :     uno::Reference< word::XTemplate > xTemplate;
     280             :     uno::Reference<document::XDocumentPropertiesSupplier> const xDocPropSupp(
     281           0 :             getModel(), uno::UNO_QUERY_THROW );
     282           0 :     uno::Reference< document::XDocumentProperties > xDocProps( xDocPropSupp->getDocumentProperties(), uno::UNO_QUERY_THROW );
     283           0 :     xDocProps->setTemplateURL( aURL );
     284           0 : }
     285             : 
     286             : uno::Any SAL_CALL
     287           0 : SwVbaDocument::Tables( const css::uno::Any& aIndex ) throw (uno::RuntimeException)
     288             : {
     289           0 :     uno::Reference< frame::XModel > xModel( mxTextDocument, uno::UNO_QUERY_THROW );
     290           0 :     uno::Reference< XCollection > xColl( new SwVbaTables( mxParent, mxContext, xModel ) );
     291             : 
     292           0 :     if ( aIndex.hasValue() )
     293           0 :         return xColl->Item( aIndex, uno::Any() );
     294           0 :     return uno::makeAny( xColl );
     295             : }
     296             : 
     297           0 : void SAL_CALL SwVbaDocument::Activate() throw (uno::RuntimeException)
     298             : {
     299           0 :     VbaDocumentBase::Activate();
     300           0 : }
     301             : 
     302           0 : ::sal_Int32 SAL_CALL SwVbaDocument::getProtectionType() throw (css::uno::RuntimeException)
     303             : {
     304             :     //TODO
     305           0 :     return word::WdProtectionType::wdNoProtection;
     306             : }
     307             : 
     308           0 : void SAL_CALL SwVbaDocument::setProtectionType( ::sal_Int32 /*_protectiontype*/ ) throw (css::uno::RuntimeException)
     309             : {
     310             :     //TODO
     311           0 : }
     312             : 
     313           0 : ::sal_Bool SAL_CALL SwVbaDocument::getUpdateStylesOnOpen() throw (css::uno::RuntimeException)
     314             : {
     315             :     //TODO
     316           0 :     return sal_False;
     317             : }
     318             : 
     319           0 : void SAL_CALL SwVbaDocument::setUpdateStylesOnOpen( ::sal_Bool /*_updatestylesonopen*/ ) throw (uno::RuntimeException)
     320             : {
     321             :     //TODO
     322           0 : }
     323             : 
     324           0 : ::sal_Bool SAL_CALL SwVbaDocument::getAutoHyphenation() throw (uno::RuntimeException)
     325             : {
     326             :     // check this property only in default paragraph style
     327           0 :     sal_Bool IsAutoHyphenation = sal_False;
     328           0 :     uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
     329           0 :     xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsHyphenation")) ) >>= IsAutoHyphenation;
     330           0 :     return IsAutoHyphenation;
     331             : }
     332             : 
     333           0 : void SAL_CALL SwVbaDocument::setAutoHyphenation( ::sal_Bool _autohyphenation ) throw (uno::RuntimeException)
     334             : {
     335             :     //TODO
     336           0 :     uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
     337           0 :     xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsHyphenation")), uno::makeAny( _autohyphenation ) );
     338           0 : }
     339             : 
     340           0 : ::sal_Int32 SAL_CALL SwVbaDocument::getHyphenationZone() throw (uno::RuntimeException)
     341             : {
     342             :     //TODO
     343           0 :     return 0;
     344             : }
     345             : 
     346           0 : void SAL_CALL SwVbaDocument::setHyphenationZone( ::sal_Int32 /*_hyphenationzone*/ ) throw (uno::RuntimeException)
     347             : {
     348             :     //TODO
     349           0 : }
     350             : 
     351           0 : ::sal_Int32 SAL_CALL SwVbaDocument::getConsecutiveHyphensLimit() throw (uno::RuntimeException)
     352             : {
     353             :     //TODO
     354           0 :     sal_Int16 nHyphensLimit = 0;
     355           0 :     uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
     356           0 :     xParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaHyphenationMaxHyphens")) ) >>= nHyphensLimit;
     357           0 :     return nHyphensLimit;
     358             : }
     359             : 
     360           0 : void SAL_CALL SwVbaDocument::setConsecutiveHyphensLimit( ::sal_Int32 _consecutivehyphenslimit ) throw (uno::RuntimeException)
     361             : {
     362           0 :     sal_Int16 nHyphensLimit = static_cast< sal_Int16 >( _consecutivehyphenslimit );
     363           0 :     uno::Reference< beans::XPropertySet > xParaProps( word::getDefaultParagraphStyle( getModel() ), uno::UNO_QUERY_THROW );
     364           0 :     xParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaHyphenationMaxHyphens")), uno::makeAny( nHyphensLimit ) );
     365           0 : }
     366             : 
     367           0 : void SAL_CALL SwVbaDocument::Protect( ::sal_Int32 /*Type*/, const uno::Any& /*NOReset*/, const uno::Any& /*Password*/, const uno::Any& /*UseIRM*/, const uno::Any& /*EnforceStyleLock*/ ) throw (uno::RuntimeException)
     368             : {
     369             :     // Seems not support in Writer
     370             :     // VbaDocumentBase::Protect( Password );
     371           0 : }
     372             : 
     373           0 : void SAL_CALL SwVbaDocument::PrintOut( const uno::Any& /*Background*/, const uno::Any& /*Append*/, const uno::Any& /*Range*/, const uno::Any& /*OutputFileName*/, const uno::Any& /*From*/, const uno::Any& /*To*/, const uno::Any& /*Item*/, const uno::Any& /*Copies*/, const uno::Any& /*Pages*/, const uno::Any& /*PageType*/, const uno::Any& /*PrintToFile*/, const uno::Any& /*Collate*/, const uno::Any& /*FileName*/, const uno::Any& /*ActivePrinterMacGX*/, const uno::Any& /*ManualDuplexPrint*/, const uno::Any& /*PrintZoomColumn*/, const uno::Any& /*PrintZoomRow*/, const uno::Any& /*PrintZoomPaperWidth*/, const uno::Any& /*PrintZoomPaperHeight*/ ) throw (uno::RuntimeException)
     374             : {
     375             :     //TODO
     376           0 : }
     377             : 
     378           0 : void SAL_CALL SwVbaDocument::PrintPreview(  ) throw (uno::RuntimeException)
     379             : {
     380           0 :     rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:PrintPreview"));
     381           0 :     dispatchRequests( mxModel,url );
     382           0 : }
     383             : 
     384           0 : void SAL_CALL SwVbaDocument::ClosePrintPreview(  ) throw (uno::RuntimeException)
     385             : {
     386           0 :     rtl::OUString url = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( ".uno:ClosePreview"));
     387           0 :     dispatchRequests( mxModel,url );
     388           0 : }
     389             : 
     390             : uno::Any SAL_CALL
     391           0 : SwVbaDocument::Revisions( const uno::Any& index ) throw (uno::RuntimeException)
     392             : {
     393           0 :     uno::Reference< document::XRedlinesSupplier > xRedlinesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
     394           0 :     uno::Reference< container::XIndexAccess > xRedlines( xRedlinesSupp->getRedlines(), uno::UNO_QUERY_THROW );
     395           0 :     uno::Reference< XCollection > xCol( new SwVbaRevisions( this, mxContext, getModel(), xRedlines ) );
     396           0 :     if ( index.hasValue() )
     397           0 :         return xCol->Item( index, uno::Any() );
     398           0 :     return uno::makeAny( xCol );
     399             : }
     400             : 
     401             : uno::Any SAL_CALL
     402           0 : SwVbaDocument::Frames( const uno::Any& index ) throw (uno::RuntimeException)
     403             : {
     404           0 :     uno::Reference< text::XTextFramesSupplier > xTextFramesSupp( mxTextDocument, uno::UNO_QUERY_THROW );
     405           0 :     uno::Reference< container::XIndexAccess > xFrames( xTextFramesSupp->getTextFrames(), uno::UNO_QUERY_THROW );
     406           0 :     uno::Reference< XCollection > xCol( new SwVbaFrames( this, mxContext, xFrames, getModel() ) );
     407           0 :     if ( index.hasValue() )
     408           0 :         return xCol->Item( index, uno::Any() );
     409           0 :     return uno::makeAny( xCol );
     410             : }
     411             : 
     412             : uno::Any
     413           0 : SwVbaDocument::getControlShape( const ::rtl::OUString& sName )
     414             : {
     415           0 :     uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
     416           0 :     uno::Reference< container::XIndexAccess > xIndexAccess( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
     417             : 
     418           0 :     sal_Int32 nCount = xIndexAccess->getCount();
     419           0 :     for( int index = 0; index < nCount; index++ )
     420             :     {
     421           0 :         uno::Any aUnoObj =  xIndexAccess->getByIndex( index );
     422             :         // It seems there are some drawing objects that can not query into Control shapes?
     423           0 :         uno::Reference< drawing::XControlShape > xControlShape( aUnoObj, uno::UNO_QUERY );
     424           0 :         if( xControlShape.is() )
     425             :         {
     426           0 :              uno::Reference< container::XNamed > xNamed( xControlShape->getControl(), uno::UNO_QUERY_THROW );
     427           0 :             if( sName.equals( xNamed->getName() ))
     428             :             {
     429           0 :                 return aUnoObj;
     430           0 :             }
     431             :         }
     432           0 :     }
     433           0 :     return uno::Any();
     434             : }
     435             : 
     436             : uno::Reference< beans::XIntrospectionAccess > SAL_CALL
     437           0 : SwVbaDocument::getIntrospection(  ) throw (uno::RuntimeException)
     438             : {
     439           0 :     return uno::Reference< beans::XIntrospectionAccess >();
     440             : }
     441             : 
     442             : uno::Any SAL_CALL
     443           0 : SwVbaDocument::invoke( const ::rtl::OUString& aFunctionName, const uno::Sequence< uno::Any >& /*aParams*/, uno::Sequence< ::sal_Int16 >& /*aOutParamIndex*/, uno::Sequence< uno::Any >& /*aOutParam*/ ) throw (lang::IllegalArgumentException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
     444             : {
     445             :     OSL_TRACE("** SwVbaDocument::invoke( %s ), will barf",
     446             :         rtl::OUStringToOString( aFunctionName, RTL_TEXTENCODING_UTF8 ).getStr() );
     447             : 
     448           0 :     throw uno::RuntimeException(); // unsupported operation
     449             : }
     450             : 
     451             : void SAL_CALL
     452           0 : SwVbaDocument::setValue( const ::rtl::OUString& /*aPropertyName*/, const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, script::CannotConvertException, reflection::InvocationTargetException, uno::RuntimeException)
     453             : {
     454           0 :     throw uno::RuntimeException(); // unsupported operation
     455             : }
     456             : uno::Any SAL_CALL
     457           0 : SwVbaDocument::getValue( const ::rtl::OUString& aPropertyName ) throw (beans::UnknownPropertyException, uno::RuntimeException)
     458             : {
     459           0 :     uno::Reference< drawing::XControlShape > xControlShape( getControlShape( aPropertyName ), uno::UNO_QUERY_THROW );
     460             : 
     461           0 :     uno::Reference<lang::XMultiComponentFactory > xServiceManager( mxContext->getServiceManager(), uno::UNO_QUERY_THROW );
     462           0 :     uno::Reference< XControlProvider > xControlProvider( xServiceManager->createInstanceWithContext( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.ControlProvider" ) ), mxContext ), uno::UNO_QUERY_THROW );
     463           0 :     uno::Reference< msforms::XControl > xControl( xControlProvider->createControl(  xControlShape, getModel() ) );
     464           0 :     return uno::makeAny( xControl );
     465             : }
     466             : 
     467             : ::sal_Bool SAL_CALL
     468           0 : SwVbaDocument::hasMethod( const ::rtl::OUString& /*aName*/ ) throw (uno::RuntimeException)
     469             : {
     470           0 :     return sal_False;
     471             : }
     472             : 
     473             : ::sal_Bool SAL_CALL
     474           0 : SwVbaDocument::hasProperty( const ::rtl::OUString& aName ) throw (uno::RuntimeException)
     475             : {
     476           0 :     uno::Reference< container::XNameAccess > xFormControls( getFormControls() );
     477           0 :     if ( xFormControls.is() )
     478           0 :         return xFormControls->hasByName( aName );
     479           0 :     return sal_False;
     480             : }
     481             : 
     482             : uno::Reference< container::XNameAccess >
     483           0 : SwVbaDocument::getFormControls()
     484             : {
     485           0 :     uno::Reference< container::XNameAccess > xFormControls;
     486             :     try
     487             :     {
     488           0 :         uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( mxTextDocument, uno::UNO_QUERY_THROW );
     489           0 :         uno::Reference< form::XFormsSupplier >  xFormSupplier( xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW );
     490           0 :             uno::Reference< container::XIndexAccess > xIndexAccess( xFormSupplier->getForms(), uno::UNO_QUERY_THROW );
     491             :         // get the www-standard container ( maybe we should access the
     492             :         // 'www-standard' by name rather than index, this seems an
     493             :         // implementation detail
     494           0 :         xFormControls.set( xIndexAccess->getByIndex(0), uno::UNO_QUERY_THROW );
     495             :     }
     496           0 :     catch(const uno::Exception&)
     497             :     {
     498             :     }
     499           0 :     return xFormControls;
     500             : }
     501             : 
     502             : uno::Sequence< rtl::OUString >
     503           0 : SwVbaDocument::getServiceNames()
     504             : {
     505           0 :     static uno::Sequence< rtl::OUString > aServiceNames;
     506           0 :     if ( aServiceNames.getLength() == 0 )
     507             :     {
     508           0 :         aServiceNames.realloc( 1 );
     509           0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Document" ) );
     510             :     }
     511           0 :     return aServiceNames;
     512             : }
     513             : 
     514             : namespace document
     515             : {
     516             : namespace sdecl = comphelper::service_decl;
     517           1 : sdecl::vba_service_class_<SwVbaDocument, sdecl::with_args<true> > serviceImpl;
     518           1 : extern sdecl::ServiceDecl const serviceDecl(
     519             :     serviceImpl,
     520             :     "SwVbaDocument",
     521             :     "ooo.vba.word.Document" );
     522           3 : }
     523             : 
     524             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10