LCOV - code coverage report
Current view: top level - sw/source/ui/vba - vbafield.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 236 0.0 %
Date: 2012-08-25 Functions: 0 37 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 470 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : #include "vbafield.hxx"
      29                 :            : #include "vbarange.hxx"
      30                 :            : #include <com/sun/star/frame/XModel.hpp>
      31                 :            : #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
      32                 :            : #include <com/sun/star/view/XSelectionSupplier.hpp>
      33                 :            : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
      34                 :            : #include <com/sun/star/text/FilenameDisplayFormat.hpp>
      35                 :            : #include <com/sun/star/util/XRefreshable.hpp>
      36                 :            : #include <com/sun/star/util/XUpdatable.hpp>
      37                 :            : #include <comphelper/string.hxx>
      38                 :            : #include <ooo/vba/word/WdFieldType.hpp>
      39                 :            : #include <swtypes.hxx>
      40                 :            : 
      41                 :            : using namespace ::ooo::vba;
      42                 :            : using namespace ::com::sun::star;
      43                 :            : 
      44                 :            : // *** SwVbaField ***********************************************
      45                 :            : 
      46                 :          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 )
      47                 :            : {
      48         [ #  # ]:          0 :     mxTextField.set( xTextField, uno::UNO_QUERY_THROW );
      49                 :          0 : }
      50                 :            : 
      51                 :          0 : sal_Bool SAL_CALL SwVbaField::Update() throw (uno::RuntimeException)
      52                 :            : {
      53         [ #  # ]:          0 :     uno::Reference< util::XUpdatable > xUpdatable( mxTextField, uno::UNO_QUERY );
      54         [ #  # ]:          0 :     if( xUpdatable.is() )
      55                 :            :     {
      56 [ #  # ][ #  # ]:          0 :         xUpdatable->update();
      57                 :          0 :         return sal_True;
      58                 :            :     }
      59                 :          0 :     return sal_False;
      60                 :            : }
      61                 :            : 
      62                 :            : // XHelperInterface
      63                 :            : rtl::OUString
      64                 :          0 : SwVbaField::getServiceImplName()
      65                 :            : {
      66                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaField"));
      67                 :            : }
      68                 :            : 
      69                 :            : uno::Sequence<rtl::OUString>
      70                 :          0 : SwVbaField::getServiceNames()
      71                 :            : {
      72 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
      73         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
      74                 :            :     {
      75                 :          0 :         aServiceNames.realloc( 1 );
      76         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Field" ) );
      77                 :            :     }
      78                 :          0 :     return aServiceNames;
      79                 :            : }
      80                 :            : 
      81                 :            : // *** _ReadFieldParams ***********************************************
      82                 :            : // the codes are copied from ww8par5.cxx
      83                 :            : class _ReadFieldParams
      84                 :            : {
      85                 :            : private:
      86                 :            :     String aData;
      87                 :            :     xub_StrLen nLen, nFnd, nNext, nSavPtr;
      88                 :            :     String aFieldName;
      89                 :            : public:
      90                 :            :     _ReadFieldParams( const String& rData );
      91                 :            :     ~_ReadFieldParams();
      92                 :            : 
      93                 :            :     xub_StrLen GoToTokenParam();
      94                 :            :     long SkipToNextToken();
      95                 :          0 :     xub_StrLen GetTokenSttPtr() const   { return nFnd;  }
      96                 :            : 
      97                 :            :     xub_StrLen FindNextStringPiece( xub_StrLen _nStart = STRING_NOTFOUND );
      98                 :            :     bool GetTokenSttFromTo(xub_StrLen* _pFrom, xub_StrLen* _pTo,
      99                 :            :         xub_StrLen _nMax);
     100                 :            : 
     101                 :            :     String GetResult() const;
     102                 :          0 :     String GetFieldName()const { return aFieldName; }
     103                 :            : };
     104                 :            : 
     105                 :            : 
     106                 :          0 : _ReadFieldParams::_ReadFieldParams( const String& _rData )
     107         [ #  # ]:          0 :     : aData( _rData ), nLen( _rData.Len() ), nNext( 0 )
     108                 :            : {
     109                 :            :     /*
     110                 :            :         erstmal nach einer oeffnenden Klammer oder einer Leerstelle oder einem
     111                 :            :         Anfuehrungszeichen oder einem Backslash suchen, damit der Feldbefehl
     112                 :            :         (also INCLUDEPICTURE bzw EINFUeGENGRAFIK bzw ...) ueberlesen wird
     113                 :            :     */
     114 [ #  # ][ #  # ]:          0 :     while( (nLen > nNext) && (aData.GetChar( nNext ) == ' ') )
                 [ #  # ]
     115                 :          0 :         ++nNext;
     116                 :            : 
     117                 :            :     sal_Unicode c;
     118 [ #  # ][ #  # ]:          0 :     while(     nLen > nNext
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     119                 :          0 :             && (c = aData.GetChar( nNext )) != ' '
     120                 :            :             && c != '"'
     121                 :            :             && c != '\\'
     122                 :            :             && c != 132
     123                 :            :             && c != 0x201c )
     124                 :          0 :         ++nNext;
     125                 :            : 
     126                 :          0 :     nFnd      = nNext;
     127                 :          0 :     nSavPtr   = nNext;
     128 [ #  # ][ #  # ]:          0 :     aFieldName = aData.Copy( 0, nFnd );
                 [ #  # ]
     129                 :          0 : }
     130                 :            : 
     131                 :            : 
     132         [ #  # ]:          0 : _ReadFieldParams::~_ReadFieldParams()
     133                 :            : {
     134                 :          0 : }
     135                 :            : 
     136                 :            : 
     137                 :          0 : String _ReadFieldParams::GetResult() const
     138                 :            : {
     139                 :            :     return    (STRING_NOTFOUND == nFnd)
     140                 :            :             ? aEmptyStr
     141         [ #  # ]:          0 :             : aData.Copy( nFnd, (nSavPtr - nFnd) );
     142                 :            : }
     143                 :            : 
     144                 :            : 
     145                 :          0 : xub_StrLen _ReadFieldParams::GoToTokenParam()
     146                 :            : {
     147                 :          0 :     xub_StrLen nOld = nNext;
     148         [ #  # ]:          0 :     if( -2 == SkipToNextToken() )
     149                 :          0 :         return GetTokenSttPtr();
     150                 :          0 :     nNext = nOld;
     151                 :          0 :     return STRING_NOTFOUND;
     152                 :            : }
     153                 :            : 
     154                 :            : // ret: -2: NOT a '\' parameter but normal Text
     155                 :          0 : long _ReadFieldParams::SkipToNextToken()
     156                 :            : {
     157                 :          0 :     long nRet = -1;     // Ende
     158         [ #  # ]:          0 :     if (
           [ #  #  #  # ]
                 [ #  # ]
     159                 :            :          (STRING_NOTFOUND != nNext) && (nLen > nNext) &&
     160                 :          0 :          STRING_NOTFOUND != (nFnd = FindNextStringPiece(nNext))
     161                 :            :        )
     162                 :            :     {
     163                 :          0 :         nSavPtr = nNext;
     164                 :            : 
     165 [ #  # ][ #  # ]:          0 :         if ('\\' == aData.GetChar(nFnd) && '\\' != aData.GetChar(nFnd + 1))
                 [ #  # ]
     166                 :            :         {
     167                 :          0 :             nRet = aData.GetChar(++nFnd);
     168                 :          0 :             nNext = ++nFnd;             // und dahinter setzen
     169                 :            :         }
     170                 :            :         else
     171                 :            :         {
     172                 :          0 :             nRet = -2;
     173   [ #  #  #  #  :          0 :             if (
           #  # ][ #  # ]
     174                 :            :                  (STRING_NOTFOUND != nSavPtr ) &&
     175                 :            :                  (
     176                 :          0 :                    ('"' == aData.GetChar(nSavPtr - 1)) ||
     177                 :          0 :                    (0x201d == aData.GetChar(nSavPtr - 1))
     178                 :            :                  )
     179                 :            :                )
     180                 :            :             {
     181                 :          0 :                 --nSavPtr;
     182                 :            :             }
     183                 :            :         }
     184                 :            :     }
     185                 :          0 :     return nRet;
     186                 :            : }
     187                 :            : 
     188                 :            : // FindNextPara sucht naechsten Backslash-Parameter oder naechste Zeichenkette
     189                 :            : // bis zum Blank oder naechsten "\" oder zum schliessenden Anfuehrungszeichen
     190                 :            : // oder zum String-Ende von pStr.
     191                 :            : //
     192                 :            : // Ausgabe ppNext (falls ppNext != 0) Suchbeginn fuer naechsten Parameter bzw. 0
     193                 :            : //
     194                 :            : // Returnwert: 0 falls String-Ende erreicht,
     195                 :            : //             ansonsten Anfang des Paramters bzw. der Zeichenkette
     196                 :            : //
     197                 :          0 : xub_StrLen _ReadFieldParams::FindNextStringPiece(const xub_StrLen nStart)
     198                 :            : {
     199         [ #  # ]:          0 :     xub_StrLen  n = ( STRING_NOTFOUND == nStart ) ? nFnd : nStart;  // Anfang
     200                 :            :     xub_StrLen n2;          // Ende
     201                 :            : 
     202                 :          0 :     nNext = STRING_NOTFOUND;        // Default fuer nicht gefunden
     203                 :            : 
     204 [ #  # ][ #  # ]:          0 :     while( (nLen > n) && (aData.GetChar( n ) == ' ') )
                 [ #  # ]
     205                 :          0 :         ++n;
     206                 :            : 
     207         [ #  # ]:          0 :     if( nLen == n )
     208                 :          0 :         return STRING_NOTFOUND;     // String End reached!
     209                 :            : 
     210   [ #  #  #  #  :          0 :     if(     (aData.GetChar( n ) == '"')     // Anfuehrungszeichen vor Para?
           #  # ][ #  # ]
     211                 :          0 :         ||  (aData.GetChar( n ) == 0x201c)
     212                 :          0 :         ||  (aData.GetChar( n ) == 132) )
     213                 :            :     {
     214                 :          0 :         n++;                        // Anfuehrungszeichen ueberlesen
     215                 :          0 :         n2 = n;                     // ab hier nach Ende suchen
     216   [ #  #  #  #  :          0 :         while(     (nLen > n2)
             #  #  #  # ]
                 [ #  # ]
     217                 :          0 :                 && (aData.GetChar( n2 ) != '"')
     218                 :          0 :                 && (aData.GetChar( n2 ) != 0x201d)
     219                 :          0 :                 && (aData.GetChar( n2 ) != 147) )
     220                 :          0 :             n2++;                   // Ende d. Paras suchen
     221                 :            :     }
     222                 :            :     else                        // keine Anfuehrungszeichen
     223                 :            :     {
     224                 :          0 :         n2 = n;                     // ab hier nach Ende suchen
     225 [ #  # ][ #  # ]:          0 :         while( (nLen > n2) && (aData.GetChar( n2 ) != ' ') ) // Ende d. Paras suchen
                 [ #  # ]
     226                 :            :         {
     227         [ #  # ]:          0 :             if( aData.GetChar( n2 ) == '\\' )
     228                 :            :             {
     229         [ #  # ]:          0 :                 if( aData.GetChar( n2+1 ) == '\\' )
     230                 :          0 :                     n2 += 2;        // Doppel-Backslash -> OK
     231                 :            :                 else
     232                 :            :                 {
     233         [ #  # ]:          0 :                     if( n2 > n )
     234                 :          0 :                         n2--;
     235                 :          0 :                     break;          // einfach-Backslash -> Ende
     236                 :            :                 }
     237                 :            :             }
     238                 :            :             else
     239                 :          0 :                 n2++;               // kein Backslash -> OK
     240                 :            :         }
     241                 :            :     }
     242         [ #  # ]:          0 :     if( nLen > n2 )
     243                 :            :     {
     244         [ #  # ]:          0 :         if(aData.GetChar( n2 ) != ' ') n2++;
     245                 :          0 :         nNext = n2;
     246                 :            :     }
     247                 :          0 :     return n;
     248                 :            : }
     249                 :            : 
     250                 :            : 
     251                 :            : 
     252                 :            : // read parameters "1-3" or 1-3 with both values between 1 and nMax
     253                 :          0 : bool _ReadFieldParams::GetTokenSttFromTo(sal_uInt16* pFrom, sal_uInt16* pTo, sal_uInt16 nMax)
     254                 :            : {
     255                 :          0 :     sal_uInt16 nStart = 0;
     256                 :          0 :     sal_uInt16 nEnd   = 0;
     257                 :          0 :     xub_StrLen n = GoToTokenParam();
     258         [ #  # ]:          0 :     if( STRING_NOTFOUND != n )
     259                 :            :     {
     260                 :            : 
     261         [ #  # ]:          0 :         String sParams( GetResult() );
     262                 :            : 
     263                 :          0 :         xub_StrLen nIndex = 0;
     264         [ #  # ]:          0 :         String sStart( sParams.GetToken(0, '-', nIndex) );
     265         [ #  # ]:          0 :         if( STRING_NOTFOUND != nIndex )
     266                 :            :         {
     267         [ #  # ]:          0 :             nStart = static_cast<sal_uInt16>(sStart.ToInt32());
     268 [ #  # ][ #  # ]:          0 :             nEnd   = static_cast<sal_uInt16>(sParams.Copy(nIndex).ToInt32());
                 [ #  # ]
     269 [ #  # ][ #  # ]:          0 :         }
     270                 :            :     }
     271         [ #  # ]:          0 :     if( pFrom ) *pFrom = nStart;
     272         [ #  # ]:          0 :     if( pTo )   *pTo   = nEnd;
     273                 :            : 
     274 [ #  # ][ #  # ]:          0 :     return nStart && nEnd && (nMax >= nStart) && (nMax >= nEnd);
         [ #  # ][ #  # ]
     275                 :            : }
     276                 :            : 
     277                 :            : // *** SwVbaFields ***********************************************
     278                 :            : 
     279                 :          0 : 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 )
     280                 :            : {
     281         [ #  # ]:          0 :     uno::Reference< text::XTextField > xTextField( aSource, uno::UNO_QUERY_THROW );
     282         [ #  # ]:          0 :     uno::Reference< text::XTextDocument > xTextDocument( xModel, uno::UNO_QUERY_THROW );
     283 [ #  # ][ #  # ]:          0 :     uno::Reference< word::XField > xField( new SwVbaField( xParent, xContext, xTextDocument, xTextField ) );
                 [ #  # ]
     284         [ #  # ]:          0 :     return uno::makeAny( xField );
     285                 :            : }
     286                 :            : 
     287                 :            : typedef ::cppu::WeakImplHelper1< css::container::XEnumeration > FieldEnumeration_BASE;
     288                 :            : typedef ::cppu::WeakImplHelper2< container::XIndexAccess, container::XEnumerationAccess > FieldCollectionHelper_BASE;
     289                 :            : 
     290         [ #  # ]:          0 : class FieldEnumeration : public FieldEnumeration_BASE
     291                 :            : {
     292                 :            :     uno::Reference< XHelperInterface > mxParent;
     293                 :            :     uno::Reference< uno::XComponentContext > mxContext;
     294                 :            :     uno::Reference< frame::XModel > mxModel;
     295                 :            :     uno::Reference< container::XEnumeration > mxEnumeration;
     296                 :            : public:
     297                 :          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 )
     298                 :            :     {
     299                 :          0 :     }
     300                 :          0 :     virtual ::sal_Bool SAL_CALL hasMoreElements(  ) throw (uno::RuntimeException)
     301                 :            :     {
     302                 :          0 :         return mxEnumeration->hasMoreElements();
     303                 :            :     }
     304                 :          0 :     virtual uno::Any SAL_CALL nextElement(  ) throw (container::NoSuchElementException, lang::WrappedTargetException, uno::RuntimeException)
     305                 :            :     {
     306         [ #  # ]:          0 :         if ( !hasMoreElements() )
     307         [ #  # ]:          0 :             throw container::NoSuchElementException();
     308         [ #  # ]:          0 :         return lcl_createField( mxParent, mxContext, mxModel, mxEnumeration->nextElement() );
     309                 :            :     }
     310                 :            : };
     311                 :            : 
     312         [ #  # ]:          0 : class FieldCollectionHelper : public FieldCollectionHelper_BASE
     313                 :            : {
     314                 :            :     uno::Reference< XHelperInterface > mxParent;
     315                 :            :     uno::Reference< uno::XComponentContext > mxContext;
     316                 :            :     uno::Reference< frame::XModel > mxModel;
     317                 :            :     uno::Reference< container::XEnumerationAccess > mxEnumerationAccess;
     318                 :            : public:
     319                 :          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 )
     320                 :            :     {
     321         [ #  # ]:          0 :         uno::Reference< text::XTextFieldsSupplier > xSupp( xModel, uno::UNO_QUERY_THROW );
     322 [ #  # ][ #  # ]:          0 :         mxEnumerationAccess.set( xSupp->getTextFields(), uno::UNO_QUERY_THROW );
                 [ #  # ]
     323                 :          0 :     }
     324                 :            :     // XElementAccess
     325                 :          0 :     virtual uno::Type SAL_CALL getElementType(  ) throw (uno::RuntimeException) { return  mxEnumerationAccess->getElementType(); }
     326                 :          0 :     virtual ::sal_Bool SAL_CALL hasElements(  ) throw (uno::RuntimeException) { return mxEnumerationAccess->hasElements(); }
     327                 :            :     // XIndexAccess
     328                 :          0 :     virtual ::sal_Int32 SAL_CALL getCount(  ) throw (uno::RuntimeException)
     329                 :            :     {
     330 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     331                 :          0 :         sal_Int32 nCount = 0;
     332 [ #  # ][ #  # ]:          0 :         while( xEnumeration->hasMoreElements() )
                 [ #  # ]
     333                 :            :         {
     334                 :          0 :             ++nCount;
     335 [ #  # ][ #  # ]:          0 :             xEnumeration->nextElement();
     336                 :            :         }
     337                 :          0 :         return nCount;
     338                 :            :     }
     339                 :          0 :     virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException )
     340                 :            :     {
     341 [ #  # ][ #  # ]:          0 :         if( Index < 0 || Index >= getCount() )
         [ #  # ][ #  # ]
     342         [ #  # ]:          0 :             throw lang::IndexOutOfBoundsException();
     343                 :            : 
     344 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     345                 :          0 :         sal_Int32 nCount = 0;
     346 [ #  # ][ #  # ]:          0 :         while( xEnumeration->hasMoreElements() )
                 [ #  # ]
     347                 :            :         {
     348         [ #  # ]:          0 :             if( nCount == Index )
     349                 :            :             {
     350 [ #  # ][ #  # ]:          0 :                 return xEnumeration->nextElement();
     351                 :            :             }
     352                 :          0 :             ++nCount;
     353                 :            :         }
     354         [ #  # ]:          0 :         throw lang::IndexOutOfBoundsException();
     355                 :            :     }
     356                 :            :     // XEnumerationAccess
     357                 :          0 :     virtual uno::Reference< container::XEnumeration > SAL_CALL createEnumeration(  ) throw (uno::RuntimeException)
     358                 :            :     {
     359 [ #  # ][ #  # ]:          0 :         uno::Reference< container::XEnumeration > xEnumeration =  mxEnumerationAccess->createEnumeration();
     360 [ #  # ][ #  # ]:          0 :         return uno::Reference< container::XEnumeration >( new FieldEnumeration( mxParent, mxContext, mxModel, xEnumeration ) );
                 [ #  # ]
     361                 :            :     }
     362                 :            : };
     363                 :            : 
     364 [ #  # ][ #  # ]:          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 )
                 [ #  # ]
     365                 :            : {
     366         [ #  # ]:          0 :     mxMSF.set( mxModel, uno::UNO_QUERY_THROW );
     367                 :          0 : }
     368                 :            : 
     369                 :            : uno::Reference< word::XField > SAL_CALL
     370                 :          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)
     371                 :            : {
     372                 :          0 :     sal_Int32 nType = word::WdFieldType::wdFieldEmpty;
     373                 :          0 :     Type >>= nType;
     374                 :          0 :     rtl::OUString sText;
     375                 :          0 :     Text >>= sText;
     376                 :            : 
     377         [ #  # ]:          0 :     String sFieldName;
     378 [ #  # ][ #  # ]:          0 :     if( ( nType == word::WdFieldType::wdFieldEmpty ) && !sText.isEmpty() )
                 [ #  # ]
     379                 :            :     {
     380 [ #  # ][ #  # ]:          0 :         _ReadFieldParams aReadParam(sText);
                 [ #  # ]
     381 [ #  # ][ #  # ]:          0 :         sFieldName = aReadParam.GetFieldName();
                 [ #  # ]
     382         [ #  # ]:          0 :         OSL_TRACE("SwVbaFields::Add, the field name is %s ",rtl::OUStringToOString( sFieldName, RTL_TEXTENCODING_UTF8 ).getStr() );
     383                 :            :     }
     384                 :            : 
     385                 :          0 :     uno::Reference< text::XTextContent > xTextField;
     386 [ #  # ][ #  # ]:          0 :     if( nType == word::WdFieldType::wdFieldFileName || sFieldName.EqualsIgnoreCaseAscii("FILENAME") )
         [ #  # ][ #  # ]
     387                 :            :     {
     388 [ #  # ][ #  # ]:          0 :         xTextField.set( Create_Field_FileName( sText ), uno::UNO_QUERY_THROW );
     389                 :            :     }
     390 [ #  # ][ #  # ]:          0 :     else if( nType == word::WdFieldType::wdFieldDocProperty || sFieldName.EqualsIgnoreCaseAscii("DOCPROPERTY") )
         [ #  # ][ #  # ]
     391                 :            :     {
     392 [ #  # ][ #  # ]:          0 :         xTextField.set( Create_Field_DocProperty( sText ), uno::UNO_QUERY_THROW );
     393                 :            :     }
     394                 :            :     else
     395                 :            :     {
     396 [ #  # ][ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
     397                 :            :     }
     398                 :            : 
     399 [ #  # ][ #  # ]:          0 :     SwVbaRange* pVbaRange = dynamic_cast< SwVbaRange* >( Range.get() );
     400         [ #  # ]:          0 :     uno::Reference< text::XTextRange > xTextRange = pVbaRange->getXTextRange();
     401 [ #  # ][ #  # ]:          0 :     uno::Reference< text::XText > xText = xTextRange->getText();
     402 [ #  # ][ #  # ]:          0 :     xText->insertTextContent( xTextRange, xTextField, true );
     403 [ #  # ][ #  # ]:          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 ) ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     404                 :            : }
     405                 :            : 
     406                 :          0 : uno::Reference< text::XTextField > SwVbaFields::Create_Field_FileName( const rtl::OUString _text ) throw (uno::RuntimeException)
     407                 :            : {
     408 [ #  # ][ #  # ]:          0 :     uno::Reference< text::XTextField > xTextField( mxMSF->createInstance( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.FileName")) ), uno::UNO_QUERY_THROW );
         [ #  # ][ #  # ]
     409                 :          0 :     sal_Int16 nFileFormat = text::FilenameDisplayFormat::NAME_AND_EXT;
     410         [ #  # ]:          0 :     if( !_text.isEmpty() )
     411                 :            :     {
     412                 :            :         long nRet;
     413 [ #  # ][ #  # ]:          0 :         _ReadFieldParams aReadParam( _text );
                 [ #  # ]
     414 [ #  # ][ #  # ]:          0 :         while (-1 != (nRet = aReadParam.SkipToNextToken()))
     415                 :            :         {
     416      [ #  #  # ]:          0 :             switch (nRet)
     417                 :            :             {
     418                 :            :                 case 'p':
     419                 :          0 :                     nFileFormat = text::FilenameDisplayFormat::FULL;
     420                 :          0 :                     break;
     421                 :            :                 case '*':
     422                 :            :                     //Skip over MERGEFORMAT
     423         [ #  # ]:          0 :                     aReadParam.SkipToNextToken();
     424                 :          0 :                     break;
     425                 :            :                 default:
     426         [ #  # ]:          0 :                     DebugHelper::exception(SbERR_BAD_ARGUMENT, rtl::OUString());
     427                 :          0 :                     break;
     428                 :            :             }
     429         [ #  # ]:          0 :         }
     430                 :            :     }
     431                 :            : 
     432         [ #  # ]:          0 :     uno::Reference< beans::XPropertySet > xProps( xTextField, uno::UNO_QUERY_THROW );
     433 [ #  # ][ #  # ]:          0 :     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FileFormat") ), uno::makeAny( nFileFormat ) );
         [ #  # ][ #  # ]
     434                 :            : 
     435                 :          0 :     return xTextField;
     436                 :            : }
     437                 :            : 
     438                 :            : struct DocPropertyTable
     439                 :            : {
     440                 :            :     const char* sDocPropertyName;
     441                 :            :     const char* sFieldService;
     442                 :            : };
     443                 :            : 
     444                 :            : static const DocPropertyTable aDocPropertyTables[] =
     445                 :            : {
     446                 :            :     { "Author", "com.sun.star.text.textfield.docinfo.CreateAuthor" },
     447                 :            :     { "Bytes", NULL },
     448                 :            :     { "Category", NULL },
     449                 :            :     { "Characters",NULL },
     450                 :            :     { "CharactersWithSpaces", NULL },
     451                 :            :     { "Comments", "com.sun.star.text.textfield.docinfo.Description" },
     452                 :            :     { "Company", NULL },
     453                 :            :     { "CreateTime", "com.sun.star.text.textfield.docinfo.CreateDateTime" },
     454                 :            :     { "HyperlinkBase", NULL },
     455                 :            :     { "Keywords", "com.sun.star.text.textfield.docinfo.Keywords" },
     456                 :            :     { "LastPrinted", "com.sun.star.text.textfield.docinfo.PrintDateTime" },
     457                 :            :     { "LastSavedBy", "com.sun.star.text.textfield.docinfo.ChangeAuthor" },
     458                 :            :     { "LastSavedTime", "com.sun.star.text.textfield.docinfo.ChangeDateTime" },
     459                 :            :     { "Lines", NULL },
     460                 :            :     { "Manager", NULL },
     461                 :            :     { "NameofApplication", NULL },
     462                 :            :     { "ODMADocID", NULL },
     463                 :            :     { "Pages", "com.sun.star.text.textfield.PageCount" },
     464                 :            :     { "Paragraphs", "com.sun.star.text.textfield.ParagraphCount" },
     465                 :            :     { "RevisionNumber", "com.sun.star.text.textfield.docinfo.Revision" },
     466                 :            :     { "Security", NULL },
     467                 :            :     { "Subject", "com.sun.star.text.textfield.docinfo.Subject" },
     468                 :            :     { "Template", "com.sun.star.text.textfield.TemplateName" },
     469                 :            :     { "Title", "com.sun.star.text.textfield.docinfo.Title" },
     470                 :            :     { "TotalEditingTime", "com.sun.star.text.textfield.docinfo.EditTime" },
     471                 :            :     { "Words", "com.sun.star.text.textfield.WordCount" },
     472                 :            :     { NULL, NULL }
     473                 :            : };
     474                 :            : 
     475                 :          0 : uno::Reference< text::XTextField > SwVbaFields::Create_Field_DocProperty( const rtl::OUString _text ) throw (uno::RuntimeException)
     476                 :            : {
     477         [ #  # ]:          0 :     String aDocProperty;
     478 [ #  # ][ #  # ]:          0 :     _ReadFieldParams aReadParam( _text );
                 [ #  # ]
     479                 :            :     long nRet;
     480 [ #  # ][ #  # ]:          0 :     while( -1 != ( nRet = aReadParam.SkipToNextToken() ))
     481                 :            :     {
     482      [ #  #  # ]:          0 :         switch( nRet )
     483                 :            :         {
     484                 :            :             case -2:
     485         [ #  # ]:          0 :                 if( !aDocProperty.Len() )
     486 [ #  # ][ #  # ]:          0 :                     aDocProperty = aReadParam.GetResult();
                 [ #  # ]
     487                 :          0 :                 break;
     488                 :            :             case '*':
     489                 :            :                 //Skip over MERGEFORMAT
     490         [ #  # ]:          0 :                 aReadParam.SkipToNextToken();
     491                 :          0 :                 break;
     492                 :            :         }
     493                 :            :     }
     494 [ #  # ][ #  # ]:          0 :     aDocProperty = comphelper::string::remove(aDocProperty, '"');
     495                 :            :     OSL_TRACE("SwVbaFields::Create_Field_DocProperty, the document property name is %s ",rtl::OUStringToOString( aDocProperty, RTL_TEXTENCODING_UTF8 ).getStr() );
     496         [ #  # ]:          0 :     if( aDocProperty.Len() == 0 )
     497                 :            :     {
     498         [ #  # ]:          0 :         throw uno::RuntimeException();
     499                 :            :     }
     500                 :            : 
     501                 :          0 :     sal_Bool bCustom = sal_True;
     502                 :          0 :     rtl::OUString sFieldService;
     503                 :            :     // find the build in document properties
     504         [ #  # ]:          0 :     for( const DocPropertyTable* pTable = aDocPropertyTables; pTable->sDocPropertyName != NULL; pTable++ )
     505                 :            :     {
     506 [ #  # ][ #  # ]:          0 :         if( aDocProperty.EqualsIgnoreCaseAscii( pTable->sDocPropertyName ) )
     507                 :            :         {
     508         [ #  # ]:          0 :             if( pTable->sFieldService != NULL )
     509                 :          0 :                 sFieldService = rtl::OUString::createFromAscii(pTable->sFieldService);
     510                 :          0 :             bCustom = sal_False;
     511                 :          0 :             break;
     512                 :            :         }
     513                 :            :     }
     514                 :            : 
     515         [ #  # ]:          0 :     if( bCustom )
     516                 :            :     {
     517         [ #  # ]:          0 :         sFieldService = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.textfield.docinfo.Custom" ) );
     518                 :            :     }
     519         [ #  # ]:          0 :     else if( sFieldService.isEmpty() )
     520                 :            :     {
     521 [ #  # ][ #  # ]:          0 :         throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
     522                 :            :     }
     523                 :            : 
     524 [ #  # ][ #  # ]:          0 :     uno::Reference< text::XTextField > xTextField( mxMSF->createInstance( sFieldService ), uno::UNO_QUERY_THROW );
                 [ #  # ]
     525                 :            : 
     526         [ #  # ]:          0 :     if( bCustom )
     527                 :            :     {
     528         [ #  # ]:          0 :         uno::Reference< beans::XPropertySet > xProps( xTextField, uno::UNO_QUERY_THROW );
     529         [ #  # ]:          0 :         rtl::OUString sDocPropertyName( aDocProperty );
     530 [ #  # ][ #  # ]:          0 :         xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Name") ), uno::makeAny( sDocPropertyName ) );
         [ #  # ][ #  # ]
     531                 :            :     }
     532                 :            : 
     533 [ #  # ][ #  # ]:          0 :     return xTextField;
     534                 :            : }
     535                 :            : 
     536                 :            : uno::Reference< container::XEnumeration > SAL_CALL
     537                 :          0 : SwVbaFields::createEnumeration() throw (uno::RuntimeException)
     538                 :            : {
     539         [ #  # ]:          0 :     uno::Reference< container::XEnumerationAccess > xEnumerationAccess( m_xIndexAccess, uno::UNO_QUERY_THROW );
     540 [ #  # ][ #  # ]:          0 :     return xEnumerationAccess->createEnumeration();
     541                 :            : }
     542                 :            : 
     543                 :            : // ScVbaCollectionBaseImpl
     544                 :            : uno::Any
     545                 :          0 : SwVbaFields::createCollectionObject( const uno::Any& aSource )
     546                 :            : {
     547         [ #  # ]:          0 :     return lcl_createField( mxParent, mxContext, mxModel, aSource );
     548                 :            : }
     549                 :            : 
     550                 :          0 : sal_Int32 SAL_CALL SwVbaFields::Update() throw (uno::RuntimeException)
     551                 :            : {
     552                 :          0 :     sal_Int32 nUpdate = 1;
     553                 :            :     try
     554                 :            :     {
     555         [ #  # ]:          0 :         uno::Reference< text::XTextFieldsSupplier > xSupp( mxModel, uno::UNO_QUERY_THROW );
     556 [ #  # ][ #  # ]:          0 :         uno::Reference< util::XRefreshable > xRef( xSupp->getTextFields(), uno::UNO_QUERY_THROW );
                 [ #  # ]
     557 [ #  # ][ #  # ]:          0 :         xRef->refresh();
     558         [ #  # ]:          0 :         nUpdate = 0;
     559                 :            :     }
     560                 :          0 :     catch(const uno::Exception&)
     561                 :            :     {
     562                 :          0 :         nUpdate = 1;
     563                 :            :     }
     564                 :          0 :     return nUpdate;
     565                 :            : }
     566                 :            : 
     567                 :            : // XHelperInterface
     568                 :            : rtl::OUString
     569                 :          0 : SwVbaFields::getServiceImplName()
     570                 :            : {
     571                 :          0 :     return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaFields"));
     572                 :            : }
     573                 :            : 
     574                 :            : // XEnumerationAccess
     575                 :            : uno::Type SAL_CALL
     576                 :          0 : SwVbaFields::getElementType() throw (uno::RuntimeException)
     577                 :            : {
     578                 :          0 :     return  word::XField::static_type(0);
     579                 :            : }
     580                 :            : 
     581                 :            : uno::Sequence<rtl::OUString>
     582                 :          0 : SwVbaFields::getServiceNames()
     583                 :            : {
     584 [ #  # ][ #  # ]:          0 :     static uno::Sequence< rtl::OUString > aServiceNames;
         [ #  # ][ #  # ]
     585         [ #  # ]:          0 :     if ( aServiceNames.getLength() == 0 )
     586                 :            :     {
     587                 :          0 :         aServiceNames.realloc( 1 );
     588         [ #  # ]:          0 :         aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.Fields" ) );
     589                 :            :     }
     590                 :          0 :     return aServiceNames;
     591                 :            : }
     592                 :            : 
     593                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10