LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/vba - vbafield.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 222 0.5 %
Date: 2013-07-09 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)
      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 ] = OUString("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             :     String aData;
      77             :     xub_StrLen nLen, nFnd, nNext, nSavPtr;
      78             :     String aFieldName;
      79             : public:
      80             :     SwVbaReadFieldParams( const String& rData );
      81             :     ~SwVbaReadFieldParams();
      82             : 
      83             :     long SkipToNextToken();
      84             :     xub_StrLen GetTokenSttPtr() const   { return nFnd;  }
      85             : 
      86             :     xub_StrLen FindNextStringPiece( xub_StrLen _nStart = STRING_NOTFOUND );
      87             : 
      88             :     String GetResult() const;
      89           0 :     String GetFieldName()const { return aFieldName; }
      90             : };
      91             : 
      92           0 : SwVbaReadFieldParams::SwVbaReadFieldParams( const String& _rData )
      93           0 :     : aData( _rData ), nLen( _rData.Len() ), 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.GetChar( nNext ) == ' ') )
      99           0 :         ++nNext;
     100             : 
     101             :     sal_Unicode c;
     102           0 :     while(     nLen > nNext
     103           0 :             && (c = aData.GetChar( 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             : 
     120           0 : String SwVbaReadFieldParams::GetResult() const
     121             : {
     122           0 :     return    (STRING_NOTFOUND == nFnd)
     123             :             ? aEmptyStr
     124           0 :             : aData.Copy( nFnd, (nSavPtr - nFnd) );
     125             : }
     126             : 
     127             : // ret: -2: NOT a '\' parameter but normal Text
     128           0 : long SwVbaReadFieldParams::SkipToNextToken()
     129             : {
     130           0 :     long nRet = -1;     // end
     131           0 :     if (
     132           0 :          (STRING_NOTFOUND != nNext) && (nLen > nNext) &&
     133           0 :          STRING_NOTFOUND != (nFnd = FindNextStringPiece(nNext))
     134             :        )
     135             :     {
     136           0 :         nSavPtr = nNext;
     137             : 
     138           0 :         if ('\\' == aData.GetChar(nFnd) && '\\' != aData.GetChar(nFnd + 1))
     139             :         {
     140           0 :             nRet = aData.GetChar(++nFnd);
     141           0 :             nNext = ++nFnd;             // and set behind
     142             :         }
     143             :         else
     144             :         {
     145           0 :             nRet = -2;
     146           0 :             if (
     147           0 :                  (STRING_NOTFOUND != nSavPtr ) &&
     148             :                  (
     149           0 :                    ('"' == aData.GetChar(nSavPtr - 1)) ||
     150           0 :                    (0x201d == aData.GetChar(nSavPtr - 1))
     151             :                  )
     152             :                )
     153             :             {
     154           0 :                 --nSavPtr;
     155             :             }
     156             :         }
     157             :     }
     158           0 :     return nRet;
     159             : }
     160             : 
     161             : // FindNextPara is searching for the next Backslash-Parameter or the next string
     162             : // until blank or the next "\" or until the closing quotation mark
     163             : // or until the string end of pStr.
     164             : //
     165             : // Output ppNext (if ppNext != 0) beginning of the search for the next parameter or 0
     166             : //
     167             : // Return value: 0 if String-End reached, otherwise begin of the paramater or the string
     168             : 
     169           0 : xub_StrLen SwVbaReadFieldParams::FindNextStringPiece(const xub_StrLen nStart)
     170             : {
     171           0 :     xub_StrLen  n = ( STRING_NOTFOUND == nStart ) ? nFnd : nStart;  // Start
     172             :     xub_StrLen n2;          // End
     173             : 
     174           0 :     nNext = STRING_NOTFOUND;        // Default for not found
     175             : 
     176           0 :     while( (nLen > n) && (aData.GetChar( n ) == ' ') )
     177           0 :         ++n;
     178             : 
     179           0 :     if( nLen == n )
     180           0 :         return STRING_NOTFOUND;     // String End reached!
     181             : 
     182           0 :     if(     (aData.GetChar( n ) == '"')     // quotation marks are in front of parenthesis?
     183           0 :         ||  (aData.GetChar( n ) == 0x201c)
     184           0 :         ||  (aData.GetChar( n ) == 132) )
     185             :     {
     186           0 :         n++;                        // ignore quotation marks
     187           0 :         n2 = n;                     // From here search for the end
     188           0 :         while(     (nLen > n2)
     189           0 :                 && (aData.GetChar( n2 ) != '"')
     190           0 :                 && (aData.GetChar( n2 ) != 0x201d)
     191           0 :                 && (aData.GetChar( n2 ) != 147) )
     192           0 :             n2++;                   // Search for the end of the parenthesis
     193             :     }
     194             :     else                        // no quotation marks
     195             :     {
     196           0 :         n2 = n;                     // from here search for the end
     197           0 :         while( (nLen > n2) && (aData.GetChar( n2 ) != ' ') ) // Search for the end of the parenthesis
     198             :         {
     199           0 :             if( aData.GetChar( n2 ) == '\\' )
     200             :             {
     201           0 :                 if( aData.GetChar( n2+1 ) == '\\' )
     202           0 :                     n2 += 2;        // double-backslash -> OK
     203             :                 else
     204             :                 {
     205           0 :                     if( n2 > n )
     206           0 :                         n2--;
     207           0 :                     break;          // single-backslash -> End
     208             :                 }
     209             :             }
     210             :             else
     211           0 :                 n2++;               // no backslash -> OK
     212             :         }
     213             :     }
     214           0 :     if( nLen > n2 )
     215             :     {
     216           0 :         if(aData.GetChar( n2 ) != ' ') n2++;
     217           0 :         nNext = n2;
     218             :     }
     219           0 :     return n;
     220             : }
     221             : 
     222             : // SwVbaFields
     223             : 
     224           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 )
     225             : {
     226           0 :     uno::Reference< text::XTextField > xTextField( aSource, uno::UNO_QUERY_THROW );
     227           0 :     uno::Reference< text::XTextDocument > xTextDocument( xModel, uno::UNO_QUERY_THROW );
     228           0 :     uno::Reference< word::XField > xField( new SwVbaField( xParent, xContext, xTextDocument, xTextField ) );
     229           0 :     return uno::makeAny( xField );
     230             : }
     231             : 
     232             : typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > FieldEnumeration_BASE;
     233             : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > FieldCollectionHelper_BASE;
     234             : 
     235           0 : class FieldEnumeration : public FieldEnumeration_BASE
     236             : {
     237             :     uno::Reference< XHelperInterface > mxParent;
     238             :     uno::Reference< uno::XComponentContext > mxContext;
     239             :     uno::Reference< frame::XModel > mxModel;
     240             :     uno::Reference< container::XEnumeration > mxEnumeration;
     241             : public:
     242           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 )
     243             :     {
     244           0 :     }
     245           0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
     246             :     {
     247           0 :         return mxEnumeration->hasMoreElements();
     248             :     }
     249           0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     250             :     {
     251           0 :         if ( !hasMoreElements() )
     252           0 :             throw container::NoSuchElementException();
     253           0 :         return lcl_createField( mxParent, mxContext, mxModel, mxEnumeration->nextElement() );
     254             :     }
     255             : };
     256             : 
     257           0 : class FieldCollectionHelper : public FieldCollectionHelper_BASE
     258             : {
     259             :     uno::Reference< XHelperInterface > mxParent;
     260             :     uno::Reference< uno::XComponentContext > mxContext;
     261             :     uno::Reference< frame::XModel > mxModel;
     262             :     uno::Reference< container::XEnumerationAccess > mxEnumerationAccess;
     263             : public:
     264           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 )
     265             :     {
     266           0 :         uno::Reference< text::XTextFieldsSupplier > xSupp( xModel, uno::UNO_QUERY_THROW );
     267           0 :         mxEnumerationAccess.set( xSupp->getTextFields(), uno::UNO_QUERY_THROW );
     268           0 :     }
     269             :     // XElementAccess
     270           0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException) { return  mxEnumerationAccess->getElementType(); }
     271           0 :     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException) { return mxEnumerationAccess->hasElements(); }
     272             :     // XIndexAccess
     273           0 :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
     274             :     {
     275           0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     276           0 :         sal_Int32 nCount = 0;
     277           0 :         while( xEnumeration->hasMoreElements() )
     278             :         {
     279           0 :             ++nCount;
     280           0 :             xEnumeration->nextElement();
     281             :         }
     282           0 :         return nCount;
     283             :     }
     284           0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
     285             :     {
     286           0 :         if( Index < 0 || Index >= getCount() )
     287           0 :             throw lang::IndexOutOfBoundsException();
     288             : 
     289           0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     290           0 :         sal_Int32 nCount = 0;
     291           0 :         while( xEnumeration->hasMoreElements() )
     292             :         {
     293           0 :             if( nCount == Index )
     294             :             {
     295           0 :                 return xEnumeration->nextElement();
     296             :             }
     297           0 :             ++nCount;
     298             :         }
     299           0 :         throw lang::IndexOutOfBoundsException();
     300             :     }
     301             :     // XEnumerationAccess
     302           0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException)
     303             :     {
     304           0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     305           0 :         return uno::Reference< container::XEnumeration >( new FieldEnumeration( mxParent, mxContext, mxModel, xEnumeration ) );
     306             :     }
     307             : };
     308             : 
     309           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 )
     310             : {
     311           0 :     mxMSF.set( mxModel, uno::UNO_QUERY_THROW );
     312           0 : }
     313             : 
     314             : uno::Reference< word::XField > SAL_CALL
     315           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)
     316             : {
     317           0 :     sal_Int32 nType = word::WdFieldType::wdFieldEmpty;
     318           0 :     Type >>= nType;
     319           0 :     OUString sText;
     320           0 :     Text >>= sText;
     321             : 
     322           0 :     String sFieldName;
     323           0 :     if( ( nType == word::WdFieldType::wdFieldEmpty ) && !sText.isEmpty() )
     324             :     {
     325           0 :         SwVbaReadFieldParams aReadParam(sText);
     326           0 :         sFieldName = aReadParam.GetFieldName();
     327           0 :         OSL_TRACE("SwVbaFields::Add, the field name is %s ",OUStringToOString( sFieldName, RTL_TEXTENCODING_UTF8 ).getStr() );
     328             :     }
     329             : 
     330           0 :     uno::Reference< text::XTextContent > xTextField;
     331           0 :     if( nType == word::WdFieldType::wdFieldFileName || sFieldName.EqualsIgnoreCaseAscii("FILENAME") )
     332             :     {
     333           0 :         xTextField.set( Create_Field_FileName( sText ), uno::UNO_QUERY_THROW );
     334             :     }
     335           0 :     else if( nType == word::WdFieldType::wdFieldDocProperty || sFieldName.EqualsIgnoreCaseAscii("DOCPROPERTY") )
     336             :     {
     337           0 :         xTextField.set( Create_Field_DocProperty( sText ), uno::UNO_QUERY_THROW );
     338             :     }
     339             :     else
     340             :     {
     341           0 :         throw uno::RuntimeException("Not implemented", uno::Reference< uno::XInterface >() );
     342             :     }
     343             : 
     344           0 :     SwVbaRange* pVbaRange = dynamic_cast< SwVbaRange* >( Range.get() );
     345           0 :     uno::Reference< text::XTextRange > xTextRange = pVbaRange->getXTextRange();
     346           0 :     uno::Reference< text::XText > xText = xTextRange->getText();
     347           0 :     xText->insertTextContent( xTextRange, xTextField, true );
     348           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 ) ) );
     349             : }
     350             : 
     351           0 : uno::Reference< text::XTextField > SwVbaFields::Create_Field_FileName( const OUString _text ) throw (uno::RuntimeException)
     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 :     String 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.Len() )
     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.Len() == 0 )
     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.EqualsIgnoreCaseAscii( 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 = OUString( "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)
     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  word::XField::static_type(0);
     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 ] = OUString("ooo.vba.word.Fields" );
     534             :     }
     535           0 :     return aServiceNames;
     536           3 : }
     537             : 
     538             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10