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

Generated by: LCOV version 1.10