LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbafield.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 222 0.5 %
Date: 2014-11-03 Functions: 2 36 5.6 %
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 "vbafield.hxx"
      20             : #include "vbarange.hxx"
      21             : #include <com/sun/star/frame/XModel.hpp>
      22             : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      23             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      24             : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
      25             : #include <com/sun/star/text/FilenameDisplayFormat.hpp>
      26             : #include <com/sun/star/util/XRefreshable.hpp>
      27             : #include <com/sun/star/util/XUpdatable.hpp>
      28             : #include <comphelper/string.hxx>
      29             : #include <ooo/vba/word/WdFieldType.hpp>
      30             : #include <swtypes.hxx>
      31             : 
      32             : using namespace ::ooo::vba;
      33             : using namespace ::com::sun::star;
      34             : 
      35           0 : SwVbaField::SwVbaField(  const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const css::uno::Reference< css::text::XTextDocument >& rDocument, const  uno::Reference< css::text::XTextField >& xTextField) throw ( uno::RuntimeException ) : SwVbaField_BASE( rParent, rContext ), mxTextDocument( rDocument )
      36             : {
      37           0 :     mxTextField.set( xTextField, uno::UNO_QUERY_THROW );
      38           0 : }
      39             : 
      40           0 : sal_Bool SAL_CALL SwVbaField::Update() throw (uno::RuntimeException, std::exception)
      41             : {
      42           0 :     uno::Reference< util::XUpdatable > xUpdatable( mxTextField, uno::UNO_QUERY );
      43           0 :     if( xUpdatable.is() )
      44             :     {
      45           0 :         xUpdatable->update();
      46           0 :         return sal_True;
      47             :     }
      48           0 :     return sal_False;
      49             : }
      50             : 
      51             : // XHelperInterface
      52             : OUString
      53           0 : SwVbaField::getServiceImplName()
      54             : {
      55           0 :     return OUString("SwVbaField");
      56             : }
      57             : 
      58             : uno::Sequence<OUString>
      59           0 : SwVbaField::getServiceNames()
      60             : {
      61           0 :     static uno::Sequence< OUString > aServiceNames;
      62           0 :     if ( aServiceNames.getLength() == 0 )
      63             :     {
      64           0 :         aServiceNames.realloc( 1 );
      65           0 :         aServiceNames[ 0 ] = "ooo.vba.word.Field";
      66             :     }
      67           0 :     return aServiceNames;
      68             : }
      69             : 
      70             : // FIXME? copy and paste code
      71             : // the codes are copied from ww8par5.cxx
      72             : class SwVbaReadFieldParams
      73             : {
      74             : private:
      75             :     OUString aData;
      76             :     sal_Int32 nLen, nFnd, nNext, nSavPtr;
      77             :     OUString aFieldName;
      78             : public:
      79             :     SwVbaReadFieldParams( const OUString& rData );
      80             :     ~SwVbaReadFieldParams();
      81             : 
      82             :     long SkipToNextToken();
      83             : 
      84             :     sal_Int32 FindNextStringPiece( sal_Int32 _nStart = -1 );
      85             : 
      86             :     OUString GetResult() const;
      87           0 :     OUString GetFieldName()const { return aFieldName; }
      88             : };
      89             : 
      90           0 : SwVbaReadFieldParams::SwVbaReadFieldParams( const OUString& _rData )
      91           0 :     : aData( _rData ), nLen( _rData.getLength() ), nNext( 0 )
      92             : {
      93             :     // First search for an opening parenthesis or a space or a quotation mark
      94             :     // or a backslash, so that the field command
      95             :     // (thus INCLUDEPICTURE or ...) is ignored.
      96           0 :     while( (nLen > nNext) && (aData[ nNext ] == ' ') )
      97           0 :         ++nNext;
      98             : 
      99             :     sal_Unicode c;
     100           0 :     while(     nLen > nNext
     101           0 :             && (c = aData[ nNext ]) != ' '
     102           0 :             && c != '"'
     103           0 :             && c != '\\'
     104           0 :             && c != 132
     105           0 :             && c != 0x201c )
     106           0 :         ++nNext;
     107             : 
     108           0 :     nFnd      = nNext;
     109           0 :     nSavPtr   = nNext;
     110           0 :     aFieldName = aData.copy( 0, nFnd );
     111           0 : }
     112             : 
     113           0 : SwVbaReadFieldParams::~SwVbaReadFieldParams()
     114             : {
     115           0 : }
     116             : 
     117           0 : OUString SwVbaReadFieldParams::GetResult() const
     118             : {
     119           0 :     return    (-1 == nFnd)
     120             :             ? OUString()
     121           0 :             : aData.copy( nFnd, (nSavPtr - nFnd) );
     122             : }
     123             : 
     124             : // ret: -2: NOT a '\' parameter but normal Text
     125           0 : long SwVbaReadFieldParams::SkipToNextToken()
     126             : {
     127           0 :     long nRet = -1;     // end
     128           0 :     if (
     129           0 :          (-1 != nNext) && (nLen > nNext) &&
     130           0 :          -1 != (nFnd = FindNextStringPiece(nNext))
     131             :        )
     132             :     {
     133           0 :         nSavPtr = nNext;
     134             : 
     135           0 :         if ('\\' == aData[nFnd] && '\\' != aData[nFnd + 1])
     136             :         {
     137           0 :             nRet = aData[++nFnd];
     138           0 :             nNext = ++nFnd;             // and set behind
     139             :         }
     140             :         else
     141             :         {
     142           0 :             nRet = -2;
     143           0 :             if (
     144           0 :                  (-1 != nSavPtr ) &&
     145             :                  (
     146           0 :                    ('"' == aData[nSavPtr - 1]) ||
     147           0 :                    (0x201d == aData[nSavPtr - 1])
     148             :                  )
     149             :                )
     150             :             {
     151           0 :                 --nSavPtr;
     152             :             }
     153             :         }
     154             :     }
     155           0 :     return nRet;
     156             : }
     157             : 
     158             : // FindNextPara is searching for the next Backslash-Parameter or the next string
     159             : // until blank or the next "\" or until the closing quotation mark
     160             : // or until the string end of pStr.
     161             : 
     162             : // Output ppNext (if ppNext != 0) beginning of the search for the next parameter or 0
     163             : 
     164             : // Return value: 0 if String-End reached, otherwise begin of the paramater or the string
     165             : 
     166           0 : sal_Int32 SwVbaReadFieldParams::FindNextStringPiece(const sal_Int32 nStart)
     167             : {
     168           0 :     sal_Int32  n = ( -1 == nStart ) ? nFnd : nStart;  // Start
     169             :     sal_Int32 n2;          // End
     170             : 
     171           0 :     nNext = -1;        // Default for not found
     172             : 
     173           0 :     while( (nLen > n) && (aData[ n ] == ' ') )
     174           0 :         ++n;
     175             : 
     176           0 :     if( nLen == n )
     177           0 :         return -1;     // String End reached!
     178             : 
     179           0 :     if(     (aData[ n ] == '"')     // quotation marks are in front of parenthesis?
     180           0 :         ||  (aData[ n ] == 0x201c)
     181           0 :         ||  (aData[ n ] == 132) )
     182             :     {
     183           0 :         n++;                        // ignore quotation marks
     184           0 :         n2 = n;                     // From here search for the end
     185           0 :         while(     (nLen > n2)
     186           0 :                 && (aData[ n2 ] != '"')
     187           0 :                 && (aData[ n2 ] != 0x201d)
     188           0 :                 && (aData[ n2 ] != 147) )
     189           0 :             n2++;                   // Search for the end of the parenthesis
     190             :     }
     191             :     else                        // no quotation marks
     192             :     {
     193           0 :         n2 = n;                     // from here search for the end
     194           0 :         while( (nLen > n2) && (aData[ n2 ] != ' ') ) // Search for the end of the parenthesis
     195             :         {
     196           0 :             if( aData[ n2 ] == '\\' )
     197             :             {
     198           0 :                 if( aData[ n2+1 ] == '\\' )
     199           0 :                     n2 += 2;        // double-backslash -> OK
     200             :                 else
     201             :                 {
     202           0 :                     if( n2 > n )
     203           0 :                         n2--;
     204           0 :                     break;          // single-backslash -> End
     205             :                 }
     206             :             }
     207             :             else
     208           0 :                 n2++;               // no backslash -> OK
     209             :         }
     210             :     }
     211           0 :     if( nLen > n2 )
     212             :     {
     213           0 :         if(aData[ n2 ] != ' ') n2++;
     214           0 :         nNext = n2;
     215             :     }
     216           0 :     return n;
     217             : }
     218             : 
     219             : // SwVbaFields
     220             : 
     221           0 : static uno::Any lcl_createField( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel, const uno::Any& aSource )
     222             : {
     223           0 :     uno::Reference< text::XTextField > xTextField( aSource, uno::UNO_QUERY_THROW );
     224           0 :     uno::Reference< text::XTextDocument > xTextDocument( xModel, uno::UNO_QUERY_THROW );
     225           0 :     uno::Reference< word::XField > xField( new SwVbaField( xParent, xContext, xTextDocument, xTextField ) );
     226           0 :     return uno::makeAny( xField );
     227             : }
     228             : 
     229             : typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > FieldEnumeration_BASE;
     230             : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > FieldCollectionHelper_BASE;
     231             : 
     232           0 : class FieldEnumeration : public FieldEnumeration_BASE
     233             : {
     234             :     uno::Reference< XHelperInterface > mxParent;
     235             :     uno::Reference< uno::XComponentContext > mxContext;
     236             :     uno::Reference< frame::XModel > mxModel;
     237             :     uno::Reference< container::XEnumeration > mxEnumeration;
     238             : public:
     239           0 :     FieldEnumeration(  const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel, const uno::Reference< container::XEnumeration >& xEnumeration ) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel ), mxEnumeration( xEnumeration )
     240             :     {
     241           0 :     }
     242           0 :     virtual sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     243             :     {
     244           0 :         return mxEnumeration->hasMoreElements();
     245             :     }
     246           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException, std::exception) SAL_OVERRIDE
     247             :     {
     248           0 :         if ( !hasMoreElements() )
     249           0 :             throw container::NoSuchElementException();
     250           0 :         return lcl_createField( mxParent, mxContext, mxModel, mxEnumeration->nextElement() );
     251             :     }
     252             : };
     253             : 
     254           0 : class FieldCollectionHelper : public FieldCollectionHelper_BASE
     255             : {
     256             :     uno::Reference< XHelperInterface > mxParent;
     257             :     uno::Reference< uno::XComponentContext > mxContext;
     258             :     uno::Reference< frame::XModel > mxModel;
     259             :     uno::Reference< container::XEnumerationAccess > mxEnumerationAccess;
     260             : public:
     261           0 :     FieldCollectionHelper( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< frame::XModel >& xModel ) throw (css::uno::RuntimeException) : mxParent( xParent ), mxContext( xContext ), mxModel( xModel )
     262             :     {
     263           0 :         uno::Reference< text::XTextFieldsSupplier > xSupp( xModel, uno::UNO_QUERY_THROW );
     264           0 :         mxEnumerationAccess.set( xSupp->getTextFields(), uno::UNO_QUERY_THROW );
     265           0 :     }
     266             :     // XElementAccess
     267           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return  mxEnumerationAccess->getElementType(); }
     268           0 :     virtual sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE { return mxEnumerationAccess->hasElements(); }
     269             :     // XIndexAccess
     270           0 :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     271             :     {
     272           0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     273           0 :         sal_Int32 nCount = 0;
     274           0 :         while( xEnumeration->hasMoreElements() )
     275             :         {
     276           0 :             ++nCount;
     277           0 :             xEnumeration->nextElement();
     278             :         }
     279           0 :         return nCount;
     280             :     }
     281           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException, std::exception ) SAL_OVERRIDE
     282             :     {
     283           0 :         if( Index < 0 || Index >= getCount() )
     284           0 :             throw lang::IndexOutOfBoundsException();
     285             : 
     286           0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     287           0 :         sal_Int32 nCount = 0;
     288           0 :         while( xEnumeration->hasMoreElements() )
     289             :         {
     290           0 :             if( nCount == Index )
     291             :             {
     292           0 :                 return xEnumeration->nextElement();
     293             :             }
     294           0 :             ++nCount;
     295             :         }
     296           0 :         throw lang::IndexOutOfBoundsException();
     297             :     }
     298             :     // XEnumerationAccess
     299           0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE
     300             :     {
     301           0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     302           0 :         return uno::Reference< container::XEnumeration >( new FieldEnumeration( mxParent, mxContext, mxModel, xEnumeration ) );
     303             :     }
     304             : };
     305             : 
     306           0 : SwVbaFields::SwVbaFields( const uno::Reference< XHelperInterface >& xParent, const uno::Reference< uno::XComponentContext > & xContext, const uno::Reference< frame::XModel >& xModel ) : SwVbaFields_BASE( xParent, xContext , uno::Reference< container::XIndexAccess >( new FieldCollectionHelper( xParent, xContext, xModel ) ) ), mxModel( xModel )
     307             : {
     308           0 :     mxMSF.set( mxModel, uno::UNO_QUERY_THROW );
     309           0 : }
     310             : 
     311             : uno::Reference< word::XField > SAL_CALL
     312           0 : SwVbaFields::Add( const css::uno::Reference< ::ooo::vba::word::XRange >& Range, const css::uno::Any& Type, const css::uno::Any& Text, const css::uno::Any& /*PreserveFormatting*/ ) throw (css::script::BasicErrorException, css::uno::RuntimeException, std::exception)
     313             : {
     314           0 :     sal_Int32 nType = word::WdFieldType::wdFieldEmpty;
     315           0 :     Type >>= nType;
     316           0 :     OUString sText;
     317           0 :     Text >>= sText;
     318             : 
     319           0 :     OUString sFieldName;
     320           0 :     if( ( nType == word::WdFieldType::wdFieldEmpty ) && !sText.isEmpty() )
     321             :     {
     322           0 :         SwVbaReadFieldParams aReadParam(sText);
     323           0 :         sFieldName = aReadParam.GetFieldName();
     324           0 :         OSL_TRACE("SwVbaFields::Add, the field name is %s ",OUStringToOString( sFieldName, RTL_TEXTENCODING_UTF8 ).getStr() );
     325             :     }
     326             : 
     327           0 :     uno::Reference< text::XTextContent > xTextField;
     328           0 :     if( nType == word::WdFieldType::wdFieldFileName || sFieldName.equalsIgnoreAsciiCase("FILENAME") )
     329             :     {
     330           0 :         xTextField.set( Create_Field_FileName( sText ), uno::UNO_QUERY_THROW );
     331             :     }
     332           0 :     else if( nType == word::WdFieldType::wdFieldDocProperty || sFieldName.equalsIgnoreAsciiCase("DOCPROPERTY") )
     333             :     {
     334           0 :         xTextField.set( Create_Field_DocProperty( sText ), uno::UNO_QUERY_THROW );
     335             :     }
     336             :     else
     337             :     {
     338           0 :         throw uno::RuntimeException("Not implemented" );
     339             :     }
     340             : 
     341           0 :     SwVbaRange& rVbaRange = dynamic_cast<SwVbaRange&>(*Range.get());
     342           0 :     uno::Reference< text::XTextRange > xTextRange = rVbaRange.getXTextRange();
     343           0 :     uno::Reference< text::XText > xText = xTextRange->getText();
     344           0 :     xText->insertTextContent( xTextRange, xTextField, true );
     345           0 :     return uno::Reference< word::XField >( new SwVbaField( mxParent, mxContext, uno::Reference< text::XTextDocument >( mxModel, uno::UNO_QUERY_THROW ), uno::Reference< text::XTextField >( xTextField, uno::UNO_QUERY_THROW ) ) );
     346             : }
     347             : 
     348           0 : uno::Reference< text::XTextField > SwVbaFields::Create_Field_FileName( const OUString& _text )
     349             :     throw (uno::RuntimeException, script::BasicErrorException)
     350             : {
     351           0 :     uno::Reference< text::XTextField > xTextField( mxMSF->createInstance("com.sun.star.text.TextField.FileName"), uno::UNO_QUERY_THROW );
     352           0 :     sal_Int16 nFileFormat = text::FilenameDisplayFormat::NAME_AND_EXT;
     353           0 :     if( !_text.isEmpty() )
     354             :     {
     355             :         long nRet;
     356           0 :         SwVbaReadFieldParams aReadParam( _text );
     357           0 :         while (-1 != (nRet = aReadParam.SkipToNextToken()))
     358             :         {
     359           0 :             switch (nRet)
     360             :             {
     361             :                 case 'p':
     362           0 :                     nFileFormat = text::FilenameDisplayFormat::FULL;
     363           0 :                     break;
     364             :                 case '*':
     365             :                     //Skip over MERGEFORMAT
     366           0 :                     aReadParam.SkipToNextToken();
     367           0 :                     break;
     368             :                 default:
     369           0 :                     DebugHelper::basicexception(SbERR_BAD_ARGUMENT, OUString());
     370           0 :                     break;
     371             :             }
     372           0 :         }
     373             :     }
     374             : 
     375           0 :     uno::Reference< beans::XPropertySet > xProps( xTextField, uno::UNO_QUERY_THROW );
     376           0 :     xProps->setPropertyValue("FileFormat", uno::makeAny( nFileFormat ) );
     377             : 
     378           0 :     return xTextField;
     379             : }
     380             : 
     381             : struct DocPropertyTable
     382             : {
     383             :     const char* sDocPropertyName;
     384             :     const char* sFieldService;
     385             : };
     386             : 
     387             : static const DocPropertyTable aDocPropertyTables[] =
     388             : {
     389             :     { "Author", "com.sun.star.text.textfield.docinfo.CreateAuthor" },
     390             :     { "Bytes", NULL },
     391             :     { "Category", NULL },
     392             :     { "Characters",NULL },
     393             :     { "CharactersWithSpaces", NULL },
     394             :     { "Comments", "com.sun.star.text.textfield.docinfo.Description" },
     395             :     { "Company", NULL },
     396             :     { "CreateTime", "com.sun.star.text.textfield.docinfo.CreateDateTime" },
     397             :     { "HyperlinkBase", NULL },
     398             :     { "Keywords", "com.sun.star.text.textfield.docinfo.Keywords" },
     399             :     { "LastPrinted", "com.sun.star.text.textfield.docinfo.PrintDateTime" },
     400             :     { "LastSavedBy", "com.sun.star.text.textfield.docinfo.ChangeAuthor" },
     401             :     { "LastSavedTime", "com.sun.star.text.textfield.docinfo.ChangeDateTime" },
     402             :     { "Lines", NULL },
     403             :     { "Manager", NULL },
     404             :     { "NameofApplication", NULL },
     405             :     { "ODMADocID", NULL },
     406             :     { "Pages", "com.sun.star.text.textfield.PageCount" },
     407             :     { "Paragraphs", "com.sun.star.text.textfield.ParagraphCount" },
     408             :     { "RevisionNumber", "com.sun.star.text.textfield.docinfo.Revision" },
     409             :     { "Security", NULL },
     410             :     { "Subject", "com.sun.star.text.textfield.docinfo.Subject" },
     411             :     { "Template", "com.sun.star.text.textfield.TemplateName" },
     412             :     { "Title", "com.sun.star.text.textfield.docinfo.Title" },
     413             :     { "TotalEditingTime", "com.sun.star.text.textfield.docinfo.EditTime" },
     414             :     { "Words", "com.sun.star.text.textfield.WordCount" },
     415             :     { NULL, NULL }
     416             : };
     417             : 
     418           0 : uno::Reference< text::XTextField > SwVbaFields::Create_Field_DocProperty( const OUString& _text ) throw (uno::RuntimeException)
     419             : {
     420           0 :     OUString aDocProperty;
     421           0 :     SwVbaReadFieldParams aReadParam( _text );
     422             :     long nRet;
     423           0 :     while( -1 != ( nRet = aReadParam.SkipToNextToken() ))
     424             :     {
     425           0 :         switch( nRet )
     426             :         {
     427             :             case -2:
     428           0 :                 if( aDocProperty.isEmpty() )
     429           0 :                     aDocProperty = aReadParam.GetResult();
     430           0 :                 break;
     431             :             case '*':
     432             :                 //Skip over MERGEFORMAT
     433           0 :                 aReadParam.SkipToNextToken();
     434           0 :                 break;
     435             :         }
     436             :     }
     437           0 :     aDocProperty = comphelper::string::remove(aDocProperty, '"');
     438             :     OSL_TRACE("SwVbaFields::Create_Field_DocProperty, the document property name is %s ",OUStringToOString( aDocProperty, RTL_TEXTENCODING_UTF8 ).getStr() );
     439           0 :     if( aDocProperty.isEmpty() )
     440             :     {
     441           0 :         throw uno::RuntimeException();
     442             :     }
     443             : 
     444           0 :     bool bCustom = true;
     445           0 :     OUString sFieldService;
     446             :     // find the build in document properties
     447           0 :     for( const DocPropertyTable* pTable = aDocPropertyTables; pTable->sDocPropertyName != NULL; pTable++ )
     448             :     {
     449           0 :         if( aDocProperty.equalsIgnoreAsciiCaseAscii( pTable->sDocPropertyName ) )
     450             :         {
     451           0 :             if( pTable->sFieldService != NULL )
     452           0 :                 sFieldService = OUString::createFromAscii(pTable->sFieldService);
     453           0 :             bCustom = false;
     454           0 :             break;
     455             :         }
     456             :     }
     457             : 
     458           0 :     if( bCustom )
     459             :     {
     460           0 :         sFieldService = "com.sun.star.text.textfield.docinfo.Custom";
     461             :     }
     462           0 :     else if( sFieldService.isEmpty() )
     463             :     {
     464           0 :         throw uno::RuntimeException("Not implemented" );
     465             :     }
     466             : 
     467           0 :     uno::Reference< text::XTextField > xTextField( mxMSF->createInstance( sFieldService ), uno::UNO_QUERY_THROW );
     468             : 
     469           0 :     if( bCustom )
     470             :     {
     471           0 :         uno::Reference< beans::XPropertySet > xProps( xTextField, uno::UNO_QUERY_THROW );
     472           0 :         OUString sDocPropertyName( aDocProperty );
     473           0 :         xProps->setPropertyValue("Name", uno::makeAny( sDocPropertyName ) );
     474             :     }
     475             : 
     476           0 :     return xTextField;
     477             : }
     478             : 
     479             : uno::Reference< container::XEnumeration > SAL_CALL
     480           0 : SwVbaFields::createEnumeration() throw (uno::RuntimeException)
     481             : {
     482           0 :     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     483           0 :     return xEnumerationAccess->createEnumeration();
     484             : }
     485             : 
     486             : // ScVbaCollectionBaseImpl
     487             : uno::Any
     488           0 : SwVbaFields::createCollectionObject( const uno::Any& aSource )
     489             : {
     490           0 :     return lcl_createField( mxParent, mxContext, mxModel, aSource );
     491             : }
     492             : 
     493           0 : sal_Int32 SAL_CALL SwVbaFields::Update() throw (uno::RuntimeException, std::exception)
     494             : {
     495           0 :     sal_Int32 nUpdate = 1;
     496             :     try
     497             :     {
     498           0 :         uno::Reference< text::XTextFieldsSupplier > xSupp( mxModel, uno::UNO_QUERY_THROW );
     499           0 :         uno::Reference< util::XRefreshable > xRef( xSupp->getTextFields(), uno::UNO_QUERY_THROW );
     500           0 :         xRef->refresh();
     501           0 :         nUpdate = 0;
     502             :     }
     503           0 :     catch(const uno::Exception&)
     504             :     {
     505           0 :         nUpdate = 1;
     506             :     }
     507           0 :     return nUpdate;
     508             : }
     509             : 
     510             : // XHelperInterface
     511             : OUString
     512           0 : SwVbaFields::getServiceImplName()
     513             : {
     514           0 :     return OUString("SwVbaFields");
     515             : }
     516             : 
     517             : // XEnumerationAccess
     518             : uno::Type SAL_CALL
     519           0 : SwVbaFields::getElementType() throw (uno::RuntimeException)
     520             : {
     521           0 :     return  cppu::UnoType<word::XField>::get();
     522             : }
     523             : 
     524             : uno::Sequence<OUString>
     525           0 : SwVbaFields::getServiceNames()
     526             : {
     527           0 :     static uno::Sequence< OUString > aServiceNames;
     528           0 :     if ( aServiceNames.getLength() == 0 )
     529             :     {
     530           0 :         aServiceNames.realloc( 1 );
     531           0 :         aServiceNames[ 0 ] = "ooo.vba.word.Fields";
     532             :     }
     533           0 :     return aServiceNames;
     534           6 : }
     535             : 
     536             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10