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

Generated by: LCOV version 1.10