LCOV - code coverage report
Current view: top level - sw/source/core/doc - docfld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 396 1299 30.5 %
Date: 2012-08-25 Functions: 33 68 48.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 431 2490 17.3 %

           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                 :            : 
      29                 :            : #include <hintids.hxx>
      30                 :            : 
      31                 :            : #include <string.h>
      32                 :            : #include <float.h>
      33                 :            : #include <comphelper/string.hxx>
      34                 :            : #include <tools/datetime.hxx>
      35                 :            : #include <vcl/svapp.hxx>
      36                 :            : #include <unotools/charclass.hxx>
      37                 :            : #include <unotools/transliterationwrapper.hxx>
      38                 :            : #include <doc.hxx>
      39                 :            : #include <IDocumentUndoRedo.hxx>
      40                 :            : #include <cntfrm.hxx>
      41                 :            : #include <pam.hxx>
      42                 :            : #include <ndtxt.hxx>
      43                 :            : #include <swtable.hxx>
      44                 :            : #include <calc.hxx>
      45                 :            : #include <txtfld.hxx>
      46                 :            : #include <fmtfld.hxx>
      47                 :            : #include <tox.hxx>
      48                 :            : #include <txttxmrk.hxx>
      49                 :            : #include <docfld.hxx>   // for expression fields
      50                 :            : #include <docufld.hxx>
      51                 :            : #include <ddefld.hxx>
      52                 :            : #include <usrfld.hxx>
      53                 :            : #include <expfld.hxx>
      54                 :            : #include <dbfld.hxx>
      55                 :            : #include <flddat.hxx>
      56                 :            : #include <chpfld.hxx>
      57                 :            : #include <reffld.hxx>
      58                 :            : #include <flddropdown.hxx>
      59                 :            : #include <dbmgr.hxx>
      60                 :            : #include <section.hxx>
      61                 :            : #include <cellatr.hxx>
      62                 :            : #include <docary.hxx>
      63                 :            : #include <authfld.hxx>
      64                 :            : #include <txtinet.hxx>
      65                 :            : #include <fmtcntnt.hxx>
      66                 :            : #include <poolfmt.hrc>      // for InitFldTypes
      67                 :            : 
      68                 :            : #include <SwUndoField.hxx>
      69                 :            : #include "switerator.hxx"
      70                 :            : 
      71                 :            : using namespace ::com::sun::star::uno;
      72                 :            : 
      73                 :            : extern sal_Bool IsFrameBehind( const SwTxtNode& rMyNd, sal_uInt16 nMySttPos,
      74                 :            :                         const SwTxtNode& rBehindNd, sal_uInt16 nSttPos );
      75                 :            : 
      76                 :            : /*--------------------------------------------------------------------
      77                 :            :     Description: Insert field types
      78                 :            :  --------------------------------------------------------------------*/
      79                 :            : /*
      80                 :            :  *  Implementation of field methods at the Doc
      81                 :            :  *  Always returns a pointer to the type, if it's new or already added.
      82                 :            :  */
      83                 :         69 : SwFieldType* SwDoc::InsertFldType(const SwFieldType &rFldTyp)
      84                 :            : {
      85                 :         69 :     sal_uInt16 nSize = pFldTypes->size(),
      86                 :         69 :             nFldWhich = rFldTyp.Which();
      87                 :            : 
      88                 :         69 :     sal_uInt16 i = INIT_FLDTYPES;
      89                 :            : 
      90   [ +  +  +  - ]:         69 :     switch( nFldWhich )
      91                 :            :     {
      92                 :            :     case RES_SETEXPFLD:
      93                 :            :             //JP 29.01.96: SequenceFields start at INIT_FLDTYPES - 3!!
      94                 :            :             //             Or we get doubble number circles!!
      95                 :            :             //MIB 14.03.95: From now on also the SW3-Reader relies on this, when
      96                 :            :             //constructing string pools and when reading SetExp fields
      97         [ -  + ]:          3 :             if( nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType&)rFldTyp).GetType() )
      98                 :          0 :                 i -= INIT_SEQ_FLDTYPES;
      99                 :            :         // no break;
     100                 :            :     case RES_DBFLD:
     101                 :            :     case RES_USERFLD:
     102                 :            :     case RES_DDEFLD:
     103                 :            :         {
     104         [ +  - ]:         65 :             const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
     105 [ +  - ][ +  - ]:         65 :             String sFldNm( rFldTyp.GetName() );
     106         [ +  + ]:        338 :             for( ; i < nSize; ++i )
     107 [ +  - ][ +  - ]:        819 :                 if( nFldWhich == (*pFldTypes)[i]->Which() &&
         [ -  + ][ -  + ]
     108 [ +  - ][ +  - ]:        546 :                     rSCmp.isEqual( sFldNm, (*pFldTypes)[i]->GetName() ))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ #  # ]
     109 [ #  # ][ +  - ]:         65 :                         return (*pFldTypes)[i];
                 [ +  - ]
     110                 :            :         }
     111                 :         65 :         break;
     112                 :            : 
     113                 :            :     case RES_AUTHORITY:
     114         [ -  + ]:          4 :         for( ; i < nSize; ++i )
     115 [ #  # ][ #  # ]:          0 :             if( nFldWhich == (*pFldTypes)[i]->Which() )
     116         [ #  # ]:          0 :                 return (*pFldTypes)[i];
     117                 :          4 :         break;
     118                 :            : 
     119                 :            :     default:
     120         [ #  # ]:          0 :         for( i = 0; i < nSize; ++i )
     121 [ #  # ][ #  # ]:          0 :             if( nFldWhich == (*pFldTypes)[i]->Which() )
     122         [ #  # ]:          0 :                 return (*pFldTypes)[i];
     123                 :            :     }
     124                 :            : 
     125         [ +  - ]:         69 :     SwFieldType* pNew = rFldTyp.Copy();
     126   [ -  +  +  +  :         69 :     switch( nFldWhich )
                      - ]
     127                 :            :     {
     128                 :            :     case RES_DDEFLD:
     129         [ #  # ]:          0 :         ((SwDDEFieldType*)pNew)->SetDoc( this );
     130                 :          0 :         break;
     131                 :            : 
     132                 :            :     case RES_DBFLD:
     133                 :            :     case RES_TABLEFLD:
     134                 :            :     case RES_DATETIMEFLD:
     135                 :            :     case RES_GETEXPFLD:
     136                 :          8 :         ((SwValueFieldType*)pNew)->SetDoc( this );
     137                 :          8 :         break;
     138                 :            : 
     139                 :            :     case RES_USERFLD:
     140                 :            :     case RES_SETEXPFLD:
     141                 :         57 :         ((SwValueFieldType*)pNew)->SetDoc( this );
     142                 :            :         // JP 29.07.96: Optionally prepare FieldList for Calculator:
     143         [ +  - ]:         57 :         pUpdtFlds->InsertFldType( *pNew );
     144                 :         57 :         break;
     145                 :            :     case RES_AUTHORITY :
     146                 :          4 :         ((SwAuthorityFieldType*)pNew)->SetDoc( this );
     147                 :          4 :         break;
     148                 :            :     }
     149                 :            : 
     150 [ +  - ][ +  - ]:         69 :     pFldTypes->insert( pFldTypes->begin() + nSize, pNew );
     151         [ +  - ]:         69 :     SetModified();
     152                 :            : 
     153         [ +  - ]:         69 :     return (*pFldTypes)[ nSize ];
     154                 :            : }
     155                 :            : 
     156                 :          0 : void SwDoc::InsDeletedFldType( SwFieldType& rFldTyp )
     157                 :            : {
     158                 :            :     // The FldType was marked as deleted and removed from the array.
     159                 :            :     // One has to look this up again, now.
     160                 :            :     // - If it's not present, it can be re-inserted.
     161                 :            :     // - If the same type is found, the deleted one has to be renamed.
     162                 :            : 
     163                 :          0 :     sal_uInt16 nSize = pFldTypes->size(), nFldWhich = rFldTyp.Which();
     164                 :          0 :     sal_uInt16 i = INIT_FLDTYPES;
     165                 :            : 
     166                 :            :     OSL_ENSURE( RES_SETEXPFLD == nFldWhich ||
     167                 :            :             RES_USERFLD == nFldWhich ||
     168                 :            :             RES_DDEFLD == nFldWhich, "Wrong FldType" );
     169                 :            : 
     170                 :          0 :     const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
     171                 :          0 :     const String& rFldNm = rFldTyp.GetName();
     172                 :            :     SwFieldType* pFnd;
     173                 :            : 
     174         [ #  # ]:          0 :     for( ; i < nSize; ++i )
     175 [ #  # ][ #  # ]:          0 :         if( nFldWhich == (pFnd = (*pFldTypes)[i])->Which() &&
         [ #  # ][ #  # ]
     176 [ #  # ][ #  # ]:          0 :             rSCmp.isEqual( rFldNm, pFnd->GetName() ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     177                 :            :         {
     178                 :            :             // find new name
     179                 :          0 :             sal_uInt16 nNum = 1;
     180                 :          0 :             do {
     181         [ #  # ]:          0 :                 String sSrch( rFldNm );
     182 [ #  # ][ #  # ]:          0 :                 sSrch.Append( String::CreateFromInt32( nNum ));
                 [ #  # ]
     183         [ #  # ]:          0 :                 for( i = INIT_FLDTYPES; i < nSize; ++i )
     184 [ #  # ][ #  # ]:          0 :                     if( nFldWhich == (pFnd = (*pFldTypes)[i])->Which() &&
         [ #  # ][ #  # ]
     185 [ #  # ][ #  # ]:          0 :                         rSCmp.isEqual( sSrch, pFnd->GetName() ) )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     186                 :          0 :                         break;
     187                 :            : 
     188         [ #  # ]:          0 :                 if( i >= nSize )        // not found
     189                 :            :                 {
     190         [ #  # ]:          0 :                     ((String&)rFldNm) = sSrch;
     191                 :            :                     break;      // exit while loop
     192                 :            :                 }
     193 [ #  # ][ #  # ]:          0 :                 ++nNum;
     194                 :            :             } while( sal_True );
     195                 :          0 :             break;
     196                 :            :         }
     197                 :            : 
     198                 :            :     // not found, so insert and delete flag
     199 [ #  # ][ #  # ]:          0 :     pFldTypes->insert( pFldTypes->begin() + nSize, &rFldTyp );
     200   [ #  #  #  # ]:          0 :     switch( nFldWhich )
     201                 :            :     {
     202                 :            :     case RES_SETEXPFLD:
     203                 :          0 :         ((SwSetExpFieldType&)rFldTyp).SetDeleted( sal_False );
     204                 :          0 :         break;
     205                 :            :     case RES_USERFLD:
     206                 :          0 :         ((SwUserFieldType&)rFldTyp).SetDeleted( sal_False );
     207                 :          0 :         break;
     208                 :            :     case RES_DDEFLD:
     209                 :          0 :         ((SwDDEFieldType&)rFldTyp).SetDeleted( sal_False );
     210                 :          0 :         break;
     211                 :          0 :     }
     212                 :          0 : }
     213                 :            : 
     214                 :            : /*--------------------------------------------------------------------
     215                 :            :     Description: Remove field type
     216                 :            :  --------------------------------------------------------------------*/
     217                 :          6 : void SwDoc::RemoveFldType(sal_uInt16 nFld)
     218                 :            : {
     219                 :            :     OSL_ENSURE( INIT_FLDTYPES <= nFld,  "don't remove InitFlds" );
     220                 :            :     /*
     221                 :            :      * Dependent fields present -> ErrRaise
     222                 :            :      */
     223                 :          6 :     sal_uInt16 nSize = pFldTypes->size();
     224         [ +  - ]:          6 :     if(nFld < nSize)
     225                 :            :     {
     226                 :          6 :         SwFieldType* pTmp = (*pFldTypes)[nFld];
     227                 :            : 
     228                 :            :         // JP 29.07.96: Optionally prepare FldLst for Calculator
     229                 :          6 :         sal_uInt16 nWhich = pTmp->Which();
     230      [ -  -  + ]:          6 :         switch( nWhich )
     231                 :            :         {
     232                 :            :         case RES_SETEXPFLD:
     233                 :            :         case RES_USERFLD:
     234                 :          0 :             pUpdtFlds->RemoveFldType( *pTmp );
     235                 :            :             // no break;
     236                 :            :         case RES_DDEFLD:
     237 [ #  # ][ #  # ]:          0 :             if( pTmp->GetDepends() && !IsUsed( *pTmp ) )
                 [ #  # ]
     238                 :            :             {
     239         [ #  # ]:          0 :                 if( RES_SETEXPFLD == nWhich )
     240                 :          0 :                     ((SwSetExpFieldType*)pTmp)->SetDeleted( sal_True );
     241         [ #  # ]:          0 :                 else if( RES_USERFLD == nWhich )
     242                 :          0 :                     ((SwUserFieldType*)pTmp)->SetDeleted( sal_True );
     243                 :            :                 else
     244                 :          0 :                     ((SwDDEFieldType*)pTmp)->SetDeleted( sal_True );
     245                 :          0 :                 nWhich = 0;
     246                 :            :             }
     247                 :          0 :             break;
     248                 :            :         }
     249                 :            : 
     250         [ -  + ]:          6 :         if( nWhich )
     251                 :            :         {
     252                 :            :             OSL_ENSURE( !pTmp->GetDepends(), "Dependent fields present!" );
     253                 :            :             // delete field type
     254         [ #  # ]:          0 :             delete pTmp;
     255                 :            :         }
     256 [ +  - ][ +  - ]:          6 :         pFldTypes->erase( pFldTypes->begin() + nFld );
     257                 :          6 :         SetModified();
     258                 :            :     }
     259                 :          6 : }
     260                 :            : 
     261                 :        602 : const SwFldTypes* SwDoc::GetFldTypes() const
     262                 :            : {
     263                 :        602 :     return pFldTypes;
     264                 :            : }
     265                 :            : 
     266                 :            : /*--------------------------------------------------------------------
     267                 :            :     Description: Find first type with ResId and name
     268                 :            :  --------------------------------------------------------------------*/
     269                 :       2212 : SwFieldType* SwDoc::GetFldType( sal_uInt16 nResId, const String& rName,
     270                 :            :          bool bDbFieldMatching // used in some UNO calls for RES_DBFLD
     271                 :            :                                    // to use different string matching code
     272                 :            :                                    // #i51815#
     273                 :            :          ) const
     274                 :            : {
     275                 :       2212 :     sal_uInt16 nSize = pFldTypes->size(), i = 0;
     276                 :       2212 :     const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
     277                 :            : 
     278      [ +  +  + ]:       2212 :     switch( nResId )
     279                 :            :     {
     280                 :            :     case RES_SETEXPFLD:
     281                 :            :             //JP 29.01.96: SequenceFields start at INIT_FLDTYPES - 3!!
     282                 :            :             //             Or we get doubble number circles!!
     283                 :            :             //MIB 14.03.95: From now on also the SW3-Reader relies on this, when
     284                 :            :             //constructing string pools and when reading SetExp fields
     285                 :        748 :         i = INIT_FLDTYPES - INIT_SEQ_FLDTYPES;
     286                 :        748 :         break;
     287                 :            : 
     288                 :            :     case RES_DBFLD:
     289                 :            :     case RES_USERFLD:
     290                 :            :     case RES_DDEFLD:
     291                 :            :     case RES_AUTHORITY:
     292                 :        144 :         i = INIT_FLDTYPES;
     293                 :        144 :         break;
     294                 :            :     }
     295                 :            : 
     296                 :       2212 :     SwFieldType* pRet = 0;
     297         [ +  + ]:      18236 :     for( ; i < nSize; ++i )
     298                 :            :     {
     299         [ +  - ]:      16024 :         SwFieldType* pFldType = (*pFldTypes)[i];
     300                 :            : 
     301 [ +  - ][ +  - ]:      16024 :         String aFldName( pFldType->GetName() );
     302 [ +  + ][ -  + ]:      16024 :         if (bDbFieldMatching && nResId == RES_DBFLD)    // #i51815#
     303         [ #  # ]:          0 :             aFldName.SearchAndReplaceAll(DB_DELIM, '.');
     304                 :            : 
     305 [ +  + ][ +  + ]:      19889 :         if( nResId == pFldType->Which() &&
                 [ +  + ]
     306         [ +  - ]:       3865 :             rSCmp.isEqual( rName, aFldName ))
     307                 :            :         {
     308                 :      16024 :             pRet = pFldType;
     309                 :            :             break;
     310                 :            :         }
     311 [ +  - ][ +  + ]:      16024 :     }
     312                 :       2212 :     return pRet;
     313                 :            : }
     314                 :            : 
     315                 :            : /*************************************************************************
     316                 :            : |*    SwDoc::UpdateFlds()
     317                 :            : |*    Description: Update fields
     318                 :            : *************************************************************************/
     319                 :            : /*
     320                 :            :  *    All have to be re-evaluated.
     321                 :            :  */
     322                 :         47 : void SwDoc::UpdateFlds( SfxPoolItem *pNewHt, bool bCloseDB )
     323                 :            : {
     324                 :            :     // Call Modify() for every field type,
     325                 :            :     // dependent SwTxtFld get notified ...
     326                 :            : 
     327         [ +  + ]:       1554 :     for( sal_uInt16 i=0; i < pFldTypes->size(); ++i)
     328                 :            :     {
     329   [ +  -  +  + ]:       1507 :         switch( (*pFldTypes)[i]->Which() )
     330                 :            :         {
     331                 :            :             // Update table fields second to last
     332                 :            :             // Update references last
     333                 :            :         case RES_GETREFFLD:
     334                 :            :         case RES_TABLEFLD:
     335                 :            :         case RES_DBFLD:
     336                 :            :         case RES_JUMPEDITFLD:
     337                 :            :         case RES_REFPAGESETFLD:     // are never expanded!
     338                 :        188 :             break;
     339                 :            : 
     340                 :            :         case RES_DDEFLD:
     341                 :            :         {
     342         [ #  # ]:          0 :             if( !pNewHt )
     343                 :            :             {
     344         [ #  # ]:          0 :                 SwMsgPoolItem aUpdateDDE( RES_UPDATEDDETBL );
     345 [ #  # ][ #  # ]:          0 :                 (*pFldTypes)[i]->ModifyNotification( 0, &aUpdateDDE );
                 [ #  # ]
     346                 :            :             }
     347                 :            :             else
     348                 :          0 :                 (*pFldTypes)[i]->ModifyNotification( 0, pNewHt );
     349                 :          0 :             break;
     350                 :            :         }
     351                 :            :         case RES_GETEXPFLD:
     352                 :            :         case RES_SETEXPFLD:
     353                 :            :         case RES_HIDDENTXTFLD:
     354                 :            :         case RES_HIDDENPARAFLD:
     355                 :            :             // Expression fields are treated seperately
     356         [ +  - ]:        329 :             if( !pNewHt )
     357                 :        329 :                 break;
     358                 :            :         default:
     359                 :        990 :             (*pFldTypes)[i]->ModifyNotification ( 0, pNewHt );
     360                 :            :         }
     361                 :            :     }
     362                 :            : 
     363         [ +  - ]:         47 :     if( !IsExpFldsLocked() )
     364                 :         47 :         UpdateExpFlds( 0, sal_False );      // update expression fields
     365                 :            : 
     366                 :            :     // Tables
     367                 :         47 :     UpdateTblFlds(pNewHt);
     368                 :            : 
     369                 :            :     // References
     370                 :         47 :     UpdateRefFlds(pNewHt);
     371                 :            : 
     372         [ -  + ]:         47 :     if( bCloseDB )
     373                 :          0 :         GetNewDBMgr()->CloseAll();
     374                 :            : 
     375                 :            :     // Only evaluate on full update
     376                 :         47 :     SetModified();
     377                 :         47 : }
     378                 :            : 
     379                 :            : /******************************************************************************
     380                 :            :  *                      void SwDoc::UpdateUsrFlds()
     381                 :            :  ******************************************************************************/
     382                 :          0 : void SwDoc::UpdateUsrFlds()
     383                 :            : {
     384                 :          0 :     SwCalc* pCalc = 0;
     385                 :            :     const SwFieldType* pFldType;
     386         [ #  # ]:          0 :     for( sal_uInt16 i = INIT_FLDTYPES; i < pFldTypes->size(); ++i )
     387         [ #  # ]:          0 :         if( RES_USERFLD == ( pFldType = (*pFldTypes)[i] )->Which() )
     388                 :            :         {
     389         [ #  # ]:          0 :             if( !pCalc )
     390         [ #  # ]:          0 :                 pCalc = new SwCalc( *this );
     391                 :          0 :             ((SwUserFieldType*)pFldType)->GetValue( *pCalc );
     392                 :            :         }
     393                 :            : 
     394         [ #  # ]:          0 :     if( pCalc )
     395                 :            :     {
     396         [ #  # ]:          0 :         delete pCalc;
     397                 :          0 :         SetModified();
     398                 :            :     }
     399                 :          0 : }
     400                 :            : 
     401                 :            : /*--------------------------------------------------------------------
     402                 :            :     Description: Update reference and table fields
     403                 :            :  --------------------------------------------------------------------*/
     404                 :        133 : void SwDoc::UpdateRefFlds( SfxPoolItem* pHt )
     405                 :            : {
     406                 :            :     SwFieldType* pFldType;
     407         [ +  + ]:       4393 :     for( sal_uInt16 i = 0; i < pFldTypes->size(); ++i )
     408         [ +  + ]:       4260 :         if( RES_GETREFFLD == ( pFldType = (*pFldTypes)[i] )->Which() )
     409                 :        133 :             pFldType->ModifyNotification( 0, pHt );
     410                 :        133 : }
     411                 :            : 
     412                 :            : //For simplicity assume that all field types have updatable contents so
     413                 :            : //optimization currently only available when no fields exist.
     414                 :         36 : bool SwDoc::containsUpdatableFields()
     415                 :            : {
     416         [ +  + ]:       1188 :     for (sal_uInt16 i = 0; i < pFldTypes->size(); ++i)
     417                 :            :     {
     418         [ +  - ]:       1152 :         SwFieldType* pFldType = (*pFldTypes)[i];
     419         [ +  - ]:       1152 :         SwIterator<SwFmtFld,SwFieldType> aIter(*pFldType);
     420 [ +  - ][ -  + ]:       1152 :         if (aIter.First())
     421                 :       1152 :             return true;
     422 [ +  - ][ +  - ]:       1152 :     }
     423                 :         36 :     return false;
     424                 :            : }
     425                 :            : 
     426                 :        336 : void SwDoc::UpdateTblFlds( SfxPoolItem* pHt )
     427                 :            : {
     428                 :            :     OSL_ENSURE( !pHt || RES_TABLEFML_UPDATE  == pHt->Which(),
     429                 :            :             "What MessageItem is this?" );
     430                 :            : 
     431                 :        336 :     SwFieldType* pFldType(0);
     432                 :            : 
     433         [ +  - ]:       4704 :     for (sal_uInt16 i = 0; i < pFldTypes->size(); ++i)
     434                 :            :     {
     435         [ +  + ]:       4704 :         if( RES_TABLEFLD == ( pFldType = (*pFldTypes)[i] )->Which() )
     436                 :            :         {
     437                 :        336 :             SwTableFmlUpdate* pUpdtFld = 0;
     438 [ +  + ][ +  - ]:        336 :             if( pHt && RES_TABLEFML_UPDATE == pHt->Which() )
                 [ +  + ]
     439                 :        285 :                 pUpdtFld = (SwTableFmlUpdate*)pHt;
     440                 :            : 
     441         [ +  - ]:        336 :             SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
     442 [ +  - ][ #  # ]:        336 :             for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
                 [ -  + ]
     443                 :            :             {
     444         [ #  # ]:          0 :                 if( pFmtFld->GetTxtFld() )
     445                 :            :                 {
     446                 :          0 :                     SwTblField* pFld = (SwTblField*)pFmtFld->GetFld();
     447                 :            : 
     448         [ #  # ]:          0 :                     if( pUpdtFld )
     449                 :            :                     {
     450                 :            :                         // table where this field is located
     451                 :            :                         const SwTableNode* pTblNd;
     452                 :          0 :                         const SwTxtNode& rTxtNd = pFmtFld->GetTxtFld()->GetTxtNode();
     453 [ #  # ][ #  # ]:          0 :                         if( !rTxtNd.GetNodes().IsDocNodes() ||
         [ #  # ][ #  # ]
                 [ #  # ]
     454                 :          0 :                             0 == ( pTblNd = rTxtNd.FindTableNode() ) )
     455                 :          0 :                             continue;
     456                 :            : 
     457   [ #  #  #  #  :          0 :                         switch( pUpdtFld->eFlags )
                      # ]
     458                 :            :                         {
     459                 :            :                         case TBL_CALC:
     460                 :            :                             // re-set the value flag
     461                 :            :                             // JP 17.06.96: internal representation of all formulas
     462                 :            :                             //              (reference to other table!!!)
     463 [ #  # ][ #  # ]:          0 :                             if( nsSwExtendedSubType::SUB_CMD & pFld->GetSubType() )
     464         [ #  # ]:          0 :                                 pFld->PtrToBoxNm( pUpdtFld->pTbl );
     465                 :            :                             else
     466                 :          0 :                                 pFld->ChgValid( sal_False );
     467                 :          0 :                             break;
     468                 :            :                         case TBL_BOXNAME:
     469                 :            :                             // is this the wanted table?
     470         [ #  # ]:          0 :                             if( &pTblNd->GetTable() == pUpdtFld->pTbl )
     471                 :            :                                 // to the external representation
     472         [ #  # ]:          0 :                                 pFld->PtrToBoxNm( pUpdtFld->pTbl );
     473                 :          0 :                             break;
     474                 :            :                         case TBL_BOXPTR:
     475                 :            :                             // to the internal representation
     476                 :            :                             // JP 17.06.96: internal representation on all formulas
     477                 :            :                             //              (reference to other table!!!)
     478         [ #  # ]:          0 :                             pFld->BoxNmToPtr( pUpdtFld->pTbl );
     479                 :          0 :                             break;
     480                 :            :                         case TBL_RELBOXNAME:
     481                 :            :                             // is this the wanted table?
     482         [ #  # ]:          0 :                             if( &pTblNd->GetTable() == pUpdtFld->pTbl )
     483                 :            :                                 // to the relative representation
     484         [ #  # ]:          0 :                                 pFld->ToRelBoxNm( pUpdtFld->pTbl );
     485                 :          0 :                             break;
     486                 :            :                         default:
     487                 :          0 :                             break;
     488                 :            :                         }
     489                 :            :                     }
     490                 :            :                     else
     491                 :            :                         // reset the value flag for all
     492                 :          0 :                         pFld->ChgValid( sal_False );
     493                 :            :                 }
     494                 :            :             }
     495                 :            : 
     496         [ +  - ]:        336 :             break;
     497                 :            :         }
     498                 :       4368 :         pFldType = 0;
     499                 :            :     }
     500                 :            : 
     501                 :            :     // process all table box formuals
     502                 :            :     const SfxPoolItem* pItem;
     503                 :        336 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_BOXATR_FORMULA );
     504         [ -  + ]:        336 :     for (sal_uInt32 i = 0; i < nMaxItems; ++i)
     505                 :            :     {
     506   [ #  #  #  # ]:          0 :         if( 0 != (pItem = GetAttrPool().GetItem2( RES_BOXATR_FORMULA, i ) ) &&
                 [ #  # ]
     507                 :          0 :             ((SwTblBoxFormula*)pItem)->GetDefinedIn() )
     508                 :            :         {
     509                 :          0 :             ((SwTblBoxFormula*)pItem)->ChangeState( pHt );
     510                 :            :         }
     511                 :            :     }
     512                 :            : 
     513                 :            : 
     514                 :            :     // all fields/boxes are now invalid, so we can start to calculate
     515 [ +  + ][ +  - ]:        336 :     if( pHt && ( RES_TABLEFML_UPDATE != pHt->Which() ||
         [ +  + ][ +  + ]
     516                 :            :                 TBL_CALC != ((SwTableFmlUpdate*)pHt)->eFlags ))
     517                 :        336 :         return ;
     518                 :            : 
     519                 :        216 :     SwCalc* pCalc = 0;
     520                 :            : 
     521         [ +  - ]:        216 :     if( pFldType )
     522                 :            :     {
     523         [ +  - ]:        216 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
     524 [ +  - ][ #  # ]:        216 :         for( SwFmtFld* pFmtFld = aIter.Last(); pFmtFld; pFmtFld = aIter.Previous() )
                 [ -  + ]
     525                 :            :         {
     526                 :            :                 // start calculation at the end
     527                 :            :                 // new fields are inserted at the beginning of the modify chain
     528                 :            :                 // that gives faster calculation on import
     529                 :            :                 // mba: do we really need this "optimization"? Is it still valid?
     530                 :            :                 SwTblField* pFld;
     531 [ #  # ][ #  # ]:          0 :                 if( !pFmtFld->GetTxtFld() || (nsSwExtendedSubType::SUB_CMD &
                 [ #  # ]
     532         [ #  # ]:          0 :                     (pFld = (SwTblField*)pFmtFld->GetFld())->GetSubType() ))
     533                 :          0 :                     continue;
     534                 :            : 
     535                 :            :                 // needs to be recalculated
     536         [ #  # ]:          0 :                 if( !pFld->IsValid() )
     537                 :            :                 {
     538                 :            :                     // table where this field is located
     539                 :          0 :                     const SwTxtNode& rTxtNd = pFmtFld->GetTxtFld()->GetTxtNode();
     540 [ #  # ][ #  # ]:          0 :                     if( !rTxtNd.GetNodes().IsDocNodes() )
     541                 :          0 :                         continue;
     542         [ #  # ]:          0 :                     const SwTableNode* pTblNd = rTxtNd.FindTableNode();
     543         [ #  # ]:          0 :                     if( !pTblNd )
     544                 :          0 :                         continue;
     545                 :            : 
     546                 :            :                     // if this field is not in the to-be-updated table, skip it
     547 [ #  # ][ #  # ]:          0 :                     if( pHt && &pTblNd->GetTable() !=
                 [ #  # ]
     548                 :            :                                             ((SwTableFmlUpdate*)pHt)->pTbl )
     549                 :          0 :                         continue;
     550                 :            : 
     551         [ #  # ]:          0 :                     if( !pCalc )
     552 [ #  # ][ #  # ]:          0 :                         pCalc = new SwCalc( *this );
     553                 :            : 
     554                 :            :                     // get the values of all SetExpression fields that are valid
     555                 :            :                     // until the table
     556                 :          0 :                     SwFrm* pFrm = 0;
     557 [ #  # ][ #  # ]:          0 :                     if( pTblNd->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
     558                 :            :                     {
     559                 :            :                         // is in the special section, that's expensive!
     560                 :          0 :                         Point aPt;      // return the first frame of the layout - Tab.Headline!!
     561 [ #  # ][ #  # ]:          0 :                         pFrm = rTxtNd.getLayoutFrm( GetCurrentLayout(), &aPt );
     562         [ #  # ]:          0 :                         if( pFrm )
     563                 :            :                         {
     564         [ #  # ]:          0 :                             SwPosition aPos( *pTblNd );
     565 [ #  # ][ #  # ]:          0 :                             if( GetBodyTxtNode( *this, aPos, *pFrm ) )
     566                 :            :                                 FldsToCalc( *pCalc, _SetGetExpFld(
     567                 :          0 :                                     aPos.nNode, pFmtFld->GetTxtFld(),
     568         [ #  # ]:          0 :                                     &aPos.nContent ));
     569                 :            :                             else
     570         [ #  # ]:          0 :                                 pFrm = 0;
     571                 :            :                         }
     572                 :            :                     }
     573         [ #  # ]:          0 :                     if( !pFrm )
     574                 :            :                     {
     575                 :            :                         // create index to determine the TextNode
     576         [ #  # ]:          0 :                         SwNodeIndex aIdx( rTxtNd );
     577                 :            :                         FldsToCalc( *pCalc,
     578 [ #  # ][ #  # ]:          0 :                             _SetGetExpFld( aIdx, pFmtFld->GetTxtFld() ));
     579                 :            :                     }
     580                 :            : 
     581         [ #  # ]:          0 :                     SwTblCalcPara aPara( *pCalc, pTblNd->GetTable() );
     582         [ #  # ]:          0 :                     pFld->CalcField( aPara );
     583         [ #  # ]:          0 :                     if( aPara.IsStackOverFlow() )
     584                 :            :                     {
     585         [ #  # ]:          0 :                         bool const bResult = aPara.CalcWithStackOverflow();
     586         [ #  # ]:          0 :                         if (bResult)
     587                 :            :                         {
     588         [ #  # ]:          0 :                             pFld->CalcField( aPara );
     589                 :            :                         }
     590                 :            :                         OSL_ENSURE(bResult,
     591                 :            :                                 "the chained formula could no be calculated");
     592                 :            :                     }
     593         [ #  # ]:          0 :                     pCalc->SetCalcError( CALC_NOERR );
     594                 :            :                 }
     595         [ #  # ]:          0 :                 pFmtFld->ModifyNotification( 0, pHt );
     596         [ +  - ]:        216 :         }
     597                 :            :     }
     598                 :            : 
     599                 :            :     // calculate the formula at the boxes
     600         [ -  + ]:        216 :     for (sal_uInt32 i = 0; i < nMaxItems; ++i )
     601                 :            :     {
     602   [ #  #  #  #  :          0 :         if( 0 != (pItem = GetAttrPool().GetItem2( RES_BOXATR_FORMULA, i ) ) &&
           #  # ][ #  # ]
     603                 :          0 :             ((SwTblBoxFormula*)pItem)->GetDefinedIn() &&
     604                 :          0 :             !((SwTblBoxFormula*)pItem)->IsValid() )
     605                 :            :         {
     606                 :          0 :             SwTblBoxFormula* pFml = (SwTblBoxFormula*)pItem;
     607                 :          0 :             SwTableBox* pBox = pFml->GetTableBox();
     608   [ #  #  #  # ]:          0 :             if( pBox && pBox->GetSttNd() &&
         [ #  # ][ #  # ]
     609                 :          0 :                 pBox->GetSttNd()->GetNodes().IsDocNodes() )
     610                 :            :             {
     611                 :          0 :                 const SwTableNode* pTblNd = pBox->GetSttNd()->FindTableNode();
     612 [ #  # ][ #  # ]:          0 :                 if( !pHt || &pTblNd->GetTable() ==
                 [ #  # ]
     613                 :            :                                             ((SwTableFmlUpdate*)pHt)->pTbl )
     614                 :            :                 {
     615                 :            :                     double nValue;
     616         [ #  # ]:          0 :                     if( !pCalc )
     617 [ #  # ][ #  # ]:          0 :                         pCalc = new SwCalc( *this );
     618                 :            : 
     619                 :            :                     // get the values of all SetExpression fields that are valid
     620                 :            :                     // until the table
     621                 :          0 :                     SwFrm* pFrm = 0;
     622 [ #  # ][ #  # ]:          0 :                     if( pTblNd->GetIndex() < GetNodes().GetEndOfExtras().GetIndex() )
     623                 :            :                     {
     624                 :            :                         // is in the special section, that's expensive!
     625                 :          0 :                         Point aPt;      // return the first frame of the layout - Tab.Headline!!
     626         [ #  # ]:          0 :                         SwNodeIndex aCNdIdx( *pTblNd, +2 );
     627                 :          0 :                         SwCntntNode* pCNd = aCNdIdx.GetNode().GetCntntNode();
     628         [ #  # ]:          0 :                         if( !pCNd )
     629 [ #  # ][ #  # ]:          0 :                             pCNd = GetNodes().GoNext( &aCNdIdx );
     630                 :            : 
     631 [ #  # ][ #  # ]:          0 :                         if( pCNd && 0 != (pFrm = pCNd->getLayoutFrm( GetCurrentLayout(), &aPt )) )
         [ #  # ][ #  # ]
                 [ #  # ]
     632                 :            :                         {
     633         [ #  # ]:          0 :                             SwPosition aPos( *pCNd );
     634 [ #  # ][ #  # ]:          0 :                             if( GetBodyTxtNode( *this, aPos, *pFrm ) )
     635         [ #  # ]:          0 :                                 FldsToCalc( *pCalc, _SetGetExpFld( aPos.nNode ));
     636                 :            :                             else
     637         [ #  # ]:          0 :                                 pFrm = 0;
     638         [ #  # ]:          0 :                         }
     639                 :            :                     }
     640         [ #  # ]:          0 :                     if( !pFrm )
     641                 :            :                     {
     642                 :            :                         // create index to determine the TextNode
     643         [ #  # ]:          0 :                         SwNodeIndex aIdx( *pTblNd );
     644 [ #  # ][ #  # ]:          0 :                         FldsToCalc( *pCalc, _SetGetExpFld( aIdx ));
     645                 :            :                     }
     646                 :            : 
     647         [ #  # ]:          0 :                     SwTblCalcPara aPara( *pCalc, pTblNd->GetTable() );
     648         [ #  # ]:          0 :                     pFml->Calc( aPara, nValue );
     649                 :            : 
     650         [ #  # ]:          0 :                     if( aPara.IsStackOverFlow() )
     651                 :            :                     {
     652         [ #  # ]:          0 :                         bool const bResult = aPara.CalcWithStackOverflow();
     653         [ #  # ]:          0 :                         if (bResult)
     654                 :            :                         {
     655         [ #  # ]:          0 :                             pFml->Calc( aPara, nValue );
     656                 :            :                         }
     657                 :            :                         OSL_ENSURE(bResult,
     658                 :            :                                 "the chained formula could no be calculated");
     659                 :            :                     }
     660                 :            : 
     661         [ #  # ]:          0 :                     SwFrmFmt* pFmt = pBox->ClaimFrmFmt();
     662                 :          0 :                     SfxItemSet aTmp( GetAttrPool(),
     663         [ #  # ]:          0 :                                     RES_BOXATR_BEGIN,RES_BOXATR_END-1 );
     664                 :            : 
     665         [ #  # ]:          0 :                     if( pCalc->IsCalcError() )
     666                 :          0 :                         nValue = DBL_MAX;
     667 [ #  # ][ #  # ]:          0 :                     aTmp.Put( SwTblBoxValue( nValue ));
                 [ #  # ]
     668 [ #  # ][ #  # ]:          0 :                     if( SFX_ITEM_SET != pFmt->GetItemState( RES_BOXATR_FORMAT ))
     669 [ #  # ][ #  # ]:          0 :                         aTmp.Put( SwTblBoxNumFormat( 0 ));
                 [ #  # ]
     670         [ #  # ]:          0 :                     pFmt->SetFmtAttr( aTmp );
     671                 :            : 
     672 [ #  # ][ #  # ]:          0 :                     pCalc->SetCalcError( CALC_NOERR );
     673                 :            :                 }
     674                 :            :             }
     675                 :            :         }
     676                 :            :     }
     677                 :            : 
     678         [ -  + ]:        216 :     delete pCalc;
     679                 :            : }
     680                 :            : 
     681                 :       1551 : void SwDoc::UpdatePageFlds( SfxPoolItem* pMsgHnt )
     682                 :            : {
     683                 :            :     SwFieldType* pFldType;
     684         [ +  + ]:      51183 :     for( sal_uInt16 i = 0; i < INIT_FLDTYPES; ++i )
     685      [ +  +  + ]:      49632 :         switch( ( pFldType = (*pFldTypes)[ i ] )->Which() )
     686                 :            :         {
     687                 :            :         case RES_PAGENUMBERFLD:
     688                 :            :         case RES_CHAPTERFLD:
     689                 :            :         case RES_GETEXPFLD:
     690                 :            :         case RES_REFPAGEGETFLD:
     691                 :       6204 :             pFldType->ModifyNotification( 0, pMsgHnt );
     692                 :       6204 :             break;
     693                 :            :         case RES_DOCSTATFLD:
     694                 :       1551 :             pFldType->ModifyNotification( 0, 0 );
     695                 :       1551 :             break;
     696                 :            :         }
     697                 :       1551 :     SetNewFldLst(true);
     698                 :       1551 : }
     699                 :            : 
     700                 :            : // ---- Remove all unreferenced field types of a document --
     701                 :          0 : void SwDoc::GCFieldTypes()
     702                 :            : {
     703         [ #  # ]:          0 :     for( sal_uInt16 n = pFldTypes->size(); n > INIT_FLDTYPES; )
     704         [ #  # ]:          0 :         if( !(*pFldTypes)[ --n ]->GetDepends() )
     705                 :          0 :             RemoveFldType( n );
     706                 :          0 : }
     707                 :            : 
     708                 :        174 : void SwDoc::LockExpFlds()
     709                 :            : {
     710                 :        174 :     ++nLockExpFld;
     711                 :        174 : }
     712                 :            : 
     713                 :        174 : void SwDoc::UnlockExpFlds()
     714                 :            : {
     715         [ +  - ]:        174 :     if( nLockExpFld )
     716                 :        174 :         --nLockExpFld;
     717                 :        174 : }
     718                 :            : 
     719                 :       1517 : bool SwDoc::IsExpFldsLocked() const
     720                 :            : {
     721                 :       1517 :     return 0 != nLockExpFld;
     722                 :            : }
     723                 :            : 
     724                 :      27941 : SwDocUpdtFld& SwDoc::GetUpdtFlds() const
     725                 :            : {
     726                 :      27941 :     return *pUpdtFlds;
     727                 :            : }
     728                 :            : 
     729                 :       1551 : bool SwDoc::IsNewFldLst() const
     730                 :            : {
     731                 :       1551 :     return mbNewFldLst;
     732                 :            : }
     733                 :            : 
     734                 :       1739 : void SwDoc::SetNewFldLst(bool bFlag)
     735                 :            : {
     736                 :       1739 :     mbNewFldLst = bFlag;
     737                 :       1739 : }
     738                 :            : 
     739                 :            : // the StartIndex can be supplied optionally (e.g. if it was queried before - is a virtual
     740                 :            : // method otherwise!)
     741                 :          0 : _SetGetExpFld::_SetGetExpFld( const SwNodeIndex& rNdIdx, const SwTxtFld* pFld,
     742                 :            :                             const SwIndex* pIdx )
     743                 :            : {
     744                 :          0 :     eSetGetExpFldType = TEXTFIELD;
     745                 :          0 :     CNTNT.pTxtFld = pFld;
     746                 :          0 :     nNode = rNdIdx.GetIndex();
     747         [ #  # ]:          0 :     if( pIdx )
     748                 :          0 :         nCntnt = pIdx->GetIndex();
     749         [ #  # ]:          0 :     else if( pFld )
     750                 :          0 :         nCntnt = *pFld->GetStart();
     751                 :            :     else
     752                 :          0 :         nCntnt = 0;
     753                 :          0 : }
     754                 :            : 
     755                 :          0 : _SetGetExpFld::_SetGetExpFld( const SwNodeIndex& rNdIdx,
     756                 :            :                             const SwTxtINetFmt& rINet, const SwIndex* pIdx )
     757                 :            : {
     758                 :          0 :     eSetGetExpFldType = TEXTINET;
     759                 :          0 :     CNTNT.pTxtINet = &rINet;
     760                 :          0 :     nNode = rNdIdx.GetIndex();
     761         [ #  # ]:          0 :     if( pIdx )
     762                 :          0 :         nCntnt = pIdx->GetIndex();
     763                 :            :     else
     764                 :          0 :         nCntnt = *rINet.GetStart();
     765                 :          0 : }
     766                 :            : 
     767                 :            : // Extension for Sections:
     768                 :            : // these always have content position 0xffff!
     769                 :            : // There is never a field on this, only up to STRING_MAXLEN possible
     770                 :          9 : _SetGetExpFld::_SetGetExpFld( const SwSectionNode& rSectNd,
     771                 :            :                                 const SwPosition* pPos )
     772                 :            : {
     773                 :          9 :     eSetGetExpFldType = SECTIONNODE;
     774                 :          9 :     CNTNT.pSection = &rSectNd.GetSection();
     775                 :            : 
     776         [ -  + ]:          9 :     if( pPos )
     777                 :            :     {
     778                 :          0 :         nNode = pPos->nNode.GetIndex();
     779                 :          0 :         nCntnt = pPos->nContent.GetIndex();
     780                 :            :     }
     781                 :            :     else
     782                 :            :     {
     783                 :          9 :         nNode = rSectNd.GetIndex();
     784                 :          9 :         nCntnt = 0;
     785                 :            :     }
     786                 :          9 : }
     787                 :            : 
     788                 :          0 : _SetGetExpFld::_SetGetExpFld( const SwTableBox& rTBox, const SwPosition* pPos )
     789                 :            : {
     790                 :          0 :     eSetGetExpFldType = TABLEBOX;
     791                 :          0 :     CNTNT.pTBox = &rTBox;
     792                 :            : 
     793         [ #  # ]:          0 :     if( pPos )
     794                 :            :     {
     795                 :          0 :         nNode = pPos->nNode.GetIndex();
     796                 :          0 :         nCntnt = pPos->nContent.GetIndex();
     797                 :            :     }
     798                 :            :     else
     799                 :            :     {
     800                 :          0 :         nNode = 0;
     801                 :          0 :         nCntnt = 0;
     802         [ #  # ]:          0 :         if( rTBox.GetSttNd() )
     803                 :            :         {
     804         [ #  # ]:          0 :             SwNodeIndex aIdx( *rTBox.GetSttNd() );
     805         [ #  # ]:          0 :             const SwCntntNode* pNd = aIdx.GetNode().GetNodes().GoNext( &aIdx );
     806         [ #  # ]:          0 :             if( pNd )
     807         [ #  # ]:          0 :                 nNode = pNd->GetIndex();
     808                 :            :         }
     809                 :            :     }
     810                 :          0 : }
     811                 :            : 
     812                 :          0 : _SetGetExpFld::_SetGetExpFld( const SwNodeIndex& rNdIdx,
     813                 :            :                                 const SwTxtTOXMark& rTOX,
     814                 :            :                                 const SwIndex* pIdx )
     815                 :            : {
     816                 :          0 :     eSetGetExpFldType = TEXTTOXMARK;
     817                 :          0 :     CNTNT.pTxtTOX = &rTOX;
     818                 :          0 :     nNode = rNdIdx.GetIndex();
     819         [ #  # ]:          0 :     if( pIdx )
     820                 :          0 :         nCntnt = pIdx->GetIndex();
     821                 :            :     else
     822                 :          0 :         nCntnt = *rTOX.GetStart();
     823                 :          0 : }
     824                 :            : 
     825                 :          0 : _SetGetExpFld::_SetGetExpFld( const SwPosition& rPos )
     826                 :            : {
     827                 :          0 :     eSetGetExpFldType = CRSRPOS;
     828                 :          0 :     CNTNT.pPos = &rPos;
     829                 :          0 :     nNode = rPos.nNode.GetIndex();
     830                 :          0 :     nCntnt = rPos.nContent.GetIndex();
     831                 :          0 : }
     832                 :            : 
     833                 :          0 : _SetGetExpFld::_SetGetExpFld( const SwFlyFrmFmt& rFlyFmt,
     834                 :            :                                 const SwPosition* pPos  )
     835                 :            : {
     836                 :          0 :     eSetGetExpFldType = FLYFRAME;
     837                 :          0 :     CNTNT.pFlyFmt = &rFlyFmt;
     838         [ #  # ]:          0 :     if( pPos )
     839                 :            :     {
     840                 :          0 :         nNode = pPos->nNode.GetIndex();
     841                 :          0 :         nCntnt = pPos->nContent.GetIndex();
     842                 :            :     }
     843                 :            :     else
     844                 :            :     {
     845                 :          0 :         const SwFmtCntnt& rCntnt = rFlyFmt.GetCntnt();
     846                 :          0 :         nNode = rCntnt.GetCntntIdx()->GetIndex() + 1;
     847                 :          0 :         nCntnt = 0;
     848                 :            :     }
     849                 :          0 : }
     850                 :            : 
     851                 :          0 : void _SetGetExpFld::GetPos( SwPosition& rPos ) const
     852                 :            : {
     853                 :          0 :     rPos.nNode = nNode;
     854         [ #  # ]:          0 :     rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(), nCntnt );
     855                 :          0 : }
     856                 :            : 
     857                 :          0 : void _SetGetExpFld::GetPosOfContent( SwPosition& rPos ) const
     858                 :            : {
     859                 :          0 :     const SwNode* pNd = GetNodeFromCntnt();
     860         [ #  # ]:          0 :     if( pNd )
     861         [ #  # ]:          0 :         pNd = pNd->GetCntntNode();
     862                 :            : 
     863         [ #  # ]:          0 :     if( pNd )
     864                 :            :     {
     865                 :          0 :         rPos.nNode = *pNd;
     866 [ #  # ][ #  # ]:          0 :         rPos.nContent.Assign( (SwCntntNode*)pNd,GetCntPosFromCntnt() );
                 [ #  # ]
     867                 :            :     }
     868                 :            :     else
     869                 :            :     {
     870                 :          0 :         rPos.nNode = nNode;
     871         [ #  # ]:          0 :         rPos.nContent.Assign( rPos.nNode.GetNode().GetCntntNode(), nCntnt );
     872                 :            :     }
     873                 :          0 : }
     874                 :            : 
     875                 :          0 : void _SetGetExpFld::SetBodyPos( const SwCntntFrm& rFrm )
     876                 :            : {
     877         [ #  # ]:          0 :     if( !rFrm.IsInDocBody() )
     878                 :            :     {
     879         [ #  # ]:          0 :         SwNodeIndex aIdx( *rFrm.GetNode() );
     880                 :          0 :         SwDoc& rDoc = *aIdx.GetNodes().GetDoc();
     881         [ #  # ]:          0 :         SwPosition aPos( aIdx );
     882         [ #  # ]:          0 :         bool const bResult = ::GetBodyTxtNode( rDoc, aPos, rFrm );
     883                 :            :         OSL_ENSURE(bResult, "Where is the field?");
     884                 :            :         (void) bResult; // unused in non-debug
     885                 :          0 :         nNode = aPos.nNode.GetIndex();
     886 [ #  # ][ #  # ]:          0 :         nCntnt = aPos.nContent.GetIndex();
     887                 :            :     }
     888                 :          0 : }
     889                 :            : 
     890                 :          0 : bool _SetGetExpFld::operator<( const _SetGetExpFld& rFld ) const
     891                 :            : {
     892 [ #  # ][ #  # ]:          0 :     if( nNode < rFld.nNode || ( nNode == rFld.nNode && nCntnt < rFld.nCntnt ))
                 [ #  # ]
     893                 :          0 :         return true;
     894 [ #  # ][ #  # ]:          0 :     else if( nNode != rFld.nNode || nCntnt != rFld.nCntnt )
     895                 :          0 :         return false;
     896                 :            : 
     897                 :          0 :     const SwNode *pFirst = GetNodeFromCntnt(),
     898                 :          0 :                  *pNext = rFld.GetNodeFromCntnt();
     899                 :            : 
     900                 :            :     // Position is the same: continue only if both field pointers are set!
     901 [ #  # ][ #  # ]:          0 :     if( !pFirst || !pNext )
     902                 :          0 :         return false;
     903                 :            : 
     904                 :            :     // same Section?
     905         [ #  # ]:          0 :     if( pFirst->StartOfSectionNode() != pNext->StartOfSectionNode() )
     906                 :            :     {
     907                 :            :         // is one in the table?
     908                 :            :         const SwNode *pFirstStt, *pNextStt;
     909                 :          0 :         const SwTableNode* pTblNd = pFirst->FindTableNode();
     910         [ #  # ]:          0 :         if( pTblNd )
     911                 :          0 :             pFirstStt = pTblNd->StartOfSectionNode();
     912                 :            :         else
     913                 :          0 :             pFirstStt = pFirst->StartOfSectionNode();
     914                 :            : 
     915         [ #  # ]:          0 :         if( 0 != ( pTblNd = pNext->FindTableNode() ) )
     916                 :          0 :             pNextStt = pTblNd->StartOfSectionNode();
     917                 :            :         else
     918                 :          0 :             pNextStt = pNext->StartOfSectionNode();
     919                 :            : 
     920         [ #  # ]:          0 :         if( pFirstStt != pNextStt )
     921                 :            :         {
     922 [ #  # ][ #  #  :          0 :             if( pFirst->IsTxtNode() && pNext->IsTxtNode() &&
             #  #  #  # ]
                 [ #  # ]
     923                 :          0 :                 ( pFirst->FindFlyStartNode() || pNext->FindFlyStartNode() ))
     924                 :            :             {
     925                 :            :                 return ::IsFrameBehind( *(SwTxtNode*)pNext, nCntnt,
     926 [ #  # ][ #  # ]:          0 :                                         *(SwTxtNode*)pFirst, nCntnt );
     927                 :            :             }
     928                 :          0 :             return pFirstStt->GetIndex() < pNextStt->GetIndex();
     929                 :            :         }
     930                 :            :     }
     931                 :            : 
     932                 :            :     // same Section: is the field in the same Node?
     933         [ #  # ]:          0 :     if( pFirst != pNext )
     934                 :          0 :         return pFirst->GetIndex() < pNext->GetIndex();
     935                 :            : 
     936                 :            :     // same Node in the Section, check Position in the Node
     937                 :          0 :     return GetCntPosFromCntnt() < rFld.GetCntPosFromCntnt();
     938                 :            : }
     939                 :            : 
     940                 :          0 : const SwNode* _SetGetExpFld::GetNodeFromCntnt() const
     941                 :            : {
     942                 :          0 :     const SwNode* pRet = 0;
     943         [ #  # ]:          0 :     if( CNTNT.pTxtFld )
     944   [ #  #  #  #  :          0 :         switch( eSetGetExpFldType )
             #  #  #  # ]
     945                 :            :         {
     946                 :            :         case TEXTFIELD:
     947         [ #  # ]:          0 :             pRet = &CNTNT.pTxtFld->GetTxtNode();
     948                 :          0 :             break;
     949                 :            : 
     950                 :            :         case TEXTINET:
     951         [ #  # ]:          0 :             pRet = &CNTNT.pTxtINet->GetTxtNode();
     952                 :          0 :             break;
     953                 :            : 
     954                 :            :         case SECTIONNODE:
     955                 :          0 :             pRet = CNTNT.pSection->GetFmt()->GetSectionNode();
     956                 :          0 :             break;
     957                 :            : 
     958                 :            :         case CRSRPOS:
     959                 :          0 :             pRet = &CNTNT.pPos->nNode.GetNode();
     960                 :          0 :             break;
     961                 :            : 
     962                 :            :         case TEXTTOXMARK:
     963         [ #  # ]:          0 :             pRet = &CNTNT.pTxtTOX->GetTxtNode();
     964                 :          0 :             break;
     965                 :            : 
     966                 :            :         case TABLEBOX:
     967         [ #  # ]:          0 :             if( CNTNT.pTBox->GetSttNd() )
     968                 :            :             {
     969         [ #  # ]:          0 :                 SwNodeIndex aIdx( *CNTNT.pTBox->GetSttNd() );
     970 [ #  # ][ #  # ]:          0 :                 pRet = aIdx.GetNode().GetNodes().GoNext( &aIdx );
                 [ #  # ]
     971                 :            :             }
     972                 :          0 :             break;
     973                 :            : 
     974                 :            :         case FLYFRAME:
     975                 :            :             {
     976 [ #  # ][ #  # ]:          0 :                 SwNodeIndex aIdx( *CNTNT.pFlyFmt->GetCntnt().GetCntntIdx() );
     977 [ #  # ][ #  # ]:          0 :                 pRet = aIdx.GetNode().GetNodes().GoNext( &aIdx );
                 [ #  # ]
     978                 :            :             }
     979                 :          0 :             break;
     980                 :            :         }
     981                 :          0 :     return pRet;
     982                 :            : }
     983                 :            : 
     984                 :          0 : xub_StrLen _SetGetExpFld::GetCntPosFromCntnt() const
     985                 :            : {
     986                 :          0 :     sal_uInt16 nRet = 0;
     987         [ #  # ]:          0 :     if( CNTNT.pTxtFld )
     988      [ #  #  # ]:          0 :         switch( eSetGetExpFldType )
     989                 :            :         {
     990                 :            :         case TEXTFIELD:
     991                 :            :         case TEXTINET:
     992                 :            :         case TEXTTOXMARK:
     993                 :          0 :             nRet = *CNTNT.pTxtFld->GetStart();
     994                 :          0 :             break;
     995                 :            :         case CRSRPOS:
     996                 :          0 :             nRet =  CNTNT.pPos->nContent.GetIndex();
     997                 :          0 :             break;
     998                 :            :         default:
     999                 :          0 :             break;
    1000                 :            :         }
    1001                 :          0 :     return nRet;
    1002                 :            : }
    1003                 :            : 
    1004                 :          3 : _HashStr::_HashStr( const String& rName, const String& rText,
    1005                 :            :                     _HashStr* pNxt )
    1006         [ +  - ]:          3 :     : SwHash( rName ), aSetStr( rText )
    1007                 :            : {
    1008                 :          3 :     pNext = pNxt;
    1009                 :          3 : }
    1010                 :            : 
    1011                 :            : // Look up the Name, if it is present, return it's String, otherwise return an empty String
    1012                 :          0 : void LookString( SwHash** ppTbl, sal_uInt16 nSize, const String& rName,
    1013                 :            :                     String& rRet, sal_uInt16* pPos )
    1014                 :            : {
    1015 [ #  # ][ #  # ]:          0 :     rRet = comphelper::string::strip(rName, ' ');
    1016                 :          0 :     SwHash* pFnd = Find( rRet, ppTbl, nSize, pPos );
    1017         [ #  # ]:          0 :     if( pFnd )
    1018                 :          0 :         rRet = ((_HashStr*)pFnd)->aSetStr;
    1019                 :            :     else
    1020                 :          0 :         rRet.Erase();
    1021                 :          0 : }
    1022                 :            : 
    1023                 :          0 : String lcl_GetDBVarName( SwDoc& rDoc, SwDBNameInfField& rDBFld )
    1024                 :            : {
    1025         [ #  # ]:          0 :     SwDBData aDBData( rDBFld.GetDBData( &rDoc ));
    1026         [ #  # ]:          0 :     String sDBNumNm;
    1027         [ #  # ]:          0 :     SwDBData aDocData = rDoc.GetDBData();
    1028                 :            : 
    1029         [ #  # ]:          0 :     if( aDBData != aDocData )
    1030                 :            :     {
    1031         [ #  # ]:          0 :         sDBNumNm = aDBData.sDataSource;
    1032         [ #  # ]:          0 :         sDBNumNm += DB_DELIM;
    1033 [ #  # ][ #  # ]:          0 :         sDBNumNm += String(aDBData.sCommand);
                 [ #  # ]
    1034         [ #  # ]:          0 :         sDBNumNm += DB_DELIM;
    1035                 :            :     }
    1036 [ #  # ][ #  # ]:          0 :     sDBNumNm += SwFieldType::GetTypeStr(TYP_DBSETNUMBERFLD);
    1037                 :            : 
    1038                 :          0 :     return sDBNumNm;
    1039                 :            : }
    1040                 :            : 
    1041                 :          8 : void lcl_CalcFld( SwDoc& rDoc, SwCalc& rCalc, const _SetGetExpFld& rSGEFld,
    1042                 :            :                         SwNewDBMgr* pMgr )
    1043                 :            : {
    1044                 :          8 :     const SwTxtFld* pTxtFld = rSGEFld.GetFld();
    1045         [ +  - ]:          8 :     if( !pTxtFld )
    1046                 :          8 :         return ;
    1047                 :            : 
    1048                 :          0 :     const SwField* pFld = pTxtFld->GetFld().GetFld();
    1049                 :          0 :     const sal_uInt16 nFldWhich = pFld->GetTyp()->Which();
    1050                 :            : 
    1051         [ #  # ]:          0 :     if( RES_SETEXPFLD == nFldWhich )
    1052                 :            :     {
    1053         [ #  # ]:          0 :         SwSbxValue aValue;
    1054 [ #  # ][ #  # ]:          0 :         if( nsSwGetSetExpType::GSE_EXPR & pFld->GetSubType() )
    1055 [ #  # ][ #  # ]:          0 :             aValue.PutDouble( ((SwSetExpField*)pFld)->GetValue() );
    1056                 :            :         else
    1057                 :            :             // Extension to calculate with Strings
    1058 [ #  # ][ #  # ]:          0 :             aValue.PutString( ((SwSetExpField*)pFld)->GetExpStr() );
    1059                 :            : 
    1060                 :            :         // set the new value in Calculator
    1061 [ #  # ][ #  # ]:          0 :         rCalc.VarChange( pFld->GetTyp()->GetName(), aValue );
         [ #  # ][ #  # ]
                 [ #  # ]
    1062                 :            :     }
    1063         [ #  # ]:          0 :     else if( pMgr )
    1064                 :            :     {
    1065      [ #  #  # ]:          0 :         switch( nFldWhich )
    1066                 :            :         {
    1067                 :            :         case RES_DBNUMSETFLD:
    1068                 :            :             {
    1069                 :          0 :                 SwDBNumSetField* pDBFld = (SwDBNumSetField*)pFld;
    1070                 :            : 
    1071         [ #  # ]:          0 :                 SwDBData aDBData(pDBFld->GetDBData(&rDoc));
    1072                 :            : 
    1073 [ #  # ][ #  # ]:          0 :                 if( pDBFld->IsCondValid() &&
                 [ #  # ]
    1074 [ #  # ][ #  # ]:          0 :                     pMgr->OpenDataSource( aDBData.sDataSource, aDBData.sCommand ))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    1075                 :            :                     rCalc.VarChange( lcl_GetDBVarName( rDoc, *pDBFld),
    1076 [ #  # ][ #  # ]:          0 :                                     pDBFld->GetFormat() );
                 [ #  # ]
    1077                 :            :             }
    1078                 :          0 :             break;
    1079                 :            :         case RES_DBNEXTSETFLD:
    1080                 :            :             {
    1081                 :          0 :                 SwDBNextSetField* pDBFld = (SwDBNextSetField*)pFld;
    1082         [ #  # ]:          0 :                 SwDBData aDBData(pDBFld->GetDBData(&rDoc));
    1083 [ #  # ][ #  # ]:          0 :                 if( !pDBFld->IsCondValid() ||
                 [ #  # ]
    1084 [ #  # ][ #  # ]:          0 :                     !pMgr->OpenDataSource( aDBData.sDataSource, aDBData.sCommand ))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    1085                 :            :                     break;
    1086                 :            : 
    1087         [ #  # ]:          0 :                 String sDBNumNm(lcl_GetDBVarName( rDoc, *pDBFld));
    1088         [ #  # ]:          0 :                 SwCalcExp* pExp = rCalc.VarLook( sDBNumNm );
    1089         [ #  # ]:          0 :                 if( pExp )
    1090 [ #  # ][ #  # ]:          0 :                     rCalc.VarChange( sDBNumNm, pExp->nValue.GetLong() + 1 );
         [ #  # ][ #  # ]
    1091                 :            :             }
    1092                 :          0 :             break;
    1093                 :            : 
    1094                 :            :         }
    1095                 :            :     }
    1096                 :            : }
    1097                 :            : 
    1098                 :          0 : void SwDoc::FldsToCalc( SwCalc& rCalc, const _SetGetExpFld& rToThisFld )
    1099                 :            : {
    1100                 :            :     // create the sorted list of all SetFields
    1101                 :          0 :     pUpdtFlds->MakeFldList( *this, mbNewFldLst, GETFLD_CALC );
    1102                 :          0 :     mbNewFldLst = sal_False;
    1103                 :            : 
    1104                 :          0 :     SwNewDBMgr* pMgr = GetNewDBMgr();
    1105                 :          0 :     pMgr->CloseAll(sal_False);
    1106                 :            : 
    1107         [ #  # ]:          0 :     if( !pUpdtFlds->GetSortLst()->empty() )
    1108                 :            :     {
    1109                 :            :         _SetGetExpFlds::const_iterator const itLast = std::upper_bound(
    1110                 :          0 :                 pUpdtFlds->GetSortLst()->begin(),
    1111                 :          0 :                 pUpdtFlds->GetSortLst()->end(),
    1112         [ #  # ]:          0 :                 const_cast<_SetGetExpFld*>(&rToThisFld));
    1113 [ #  # ][ #  # ]:          0 :         for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != itLast; ++it )
    1114         [ #  # ]:          0 :             lcl_CalcFld( *this, rCalc, **it, pMgr );
    1115                 :            :     }
    1116                 :            : 
    1117                 :          0 :     pMgr->CloseAll(sal_False);
    1118                 :          0 : }
    1119                 :            : 
    1120                 :         12 : void SwDoc::FldsToCalc( SwCalc& rCalc, sal_uLong nLastNd, sal_uInt16 nLastCnt )
    1121                 :            : {
    1122                 :            :     // create the sorted list of all SetFields
    1123                 :         12 :     pUpdtFlds->MakeFldList( *this, mbNewFldLst, GETFLD_CALC );
    1124                 :         12 :     mbNewFldLst = sal_False;
    1125                 :            : 
    1126                 :         12 :     SwNewDBMgr* pMgr = GetNewDBMgr();
    1127                 :         12 :     pMgr->CloseAll(sal_False);
    1128                 :            : 
    1129   [ +  +  +  -  :         84 :     for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin();
             +  -  +  - ]
                 [ +  + ]
    1130 [ +  - ][ +  - ]:         40 :         it != pUpdtFlds->GetSortLst()->end() &&
                 [ #  # ]
    1131                 :          8 :         ( (*it)->GetNode() < nLastNd ||
    1132                 :         16 :           ( (*it)->GetNode() == nLastNd && (*it)->GetCntnt() <= nLastCnt )
    1133                 :            :         );
    1134                 :            :         ++it )
    1135                 :            :     {
    1136         [ +  - ]:          8 :         lcl_CalcFld( *this, rCalc, **it, pMgr );
    1137                 :            :     }
    1138                 :            : 
    1139                 :         12 :     pMgr->CloseAll(sal_False);
    1140                 :         12 : }
    1141                 :            : 
    1142                 :          0 : void SwDoc::FldsToExpand( SwHash**& ppHashTbl, sal_uInt16& rTblSize,
    1143                 :            :                             const _SetGetExpFld& rToThisFld )
    1144                 :            : {
    1145                 :            :     // create the sorted list of all SetFields
    1146         [ #  # ]:          0 :     pUpdtFlds->MakeFldList( *this, mbNewFldLst, GETFLD_EXPAND );
    1147                 :          0 :     mbNewFldLst = sal_False;
    1148                 :            : 
    1149                 :            :     // Hash table for all string replacements is filled on-the-fly.
    1150                 :            :     // Try to fabricate an uneven number.
    1151                 :          0 :     rTblSize = (( pUpdtFlds->GetSortLst()->size() / 7 ) + 1 ) * 7;
    1152         [ #  # ]:          0 :     ppHashTbl = new SwHash*[ rTblSize ];
    1153                 :          0 :     memset( ppHashTbl, 0, sizeof( _HashStr* ) * rTblSize );
    1154                 :            : 
    1155                 :            :     _SetGetExpFlds::const_iterator const itLast = std::upper_bound(
    1156                 :          0 :         pUpdtFlds->GetSortLst()->begin(),
    1157                 :          0 :         pUpdtFlds->GetSortLst()->end(),
    1158         [ #  # ]:          0 :         const_cast<_SetGetExpFld*>(&rToThisFld));
    1159                 :            : 
    1160 [ #  # ][ #  # ]:          0 :     for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != itLast; ++it )
    1161                 :            :     {
    1162                 :          0 :         const SwTxtFld* pTxtFld = (*it)->GetFld();
    1163         [ #  # ]:          0 :         if( !pTxtFld )
    1164                 :          0 :             continue;
    1165                 :            : 
    1166                 :          0 :         const SwField* pFld = pTxtFld->GetFld().GetFld();
    1167      [ #  #  # ]:          0 :         switch( pFld->GetTyp()->Which() )
    1168                 :            :         {
    1169                 :            :         case RES_SETEXPFLD:
    1170 [ #  # ][ #  # ]:          0 :             if( nsSwGetSetExpType::GSE_STRING & pFld->GetSubType() )
    1171                 :            :             {
    1172                 :            :                 // set the new value in the hash table
    1173                 :            :                 // is the formula a field?
    1174                 :          0 :                 SwSetExpField* pSFld = (SwSetExpField*)pFld;
    1175         [ #  # ]:          0 :                 String aNew;
    1176 [ #  # ][ #  # ]:          0 :                 LookString( ppHashTbl, rTblSize, pSFld->GetFormula(), aNew );
                 [ #  # ]
    1177                 :            : 
    1178         [ #  # ]:          0 :                 if( !aNew.Len() )               // nothing found, then the formula is
    1179 [ #  # ][ #  # ]:          0 :                     aNew = pSFld->GetFormula(); // the new value
                 [ #  # ]
    1180                 :            : 
    1181                 :            :                 // #i3141# - update expression of field as in method
    1182                 :            :                 // <SwDoc::UpdateExpFlds(..)> for string/text fields
    1183         [ #  # ]:          0 :                 pSFld->ChgExpStr( aNew );
    1184                 :            : 
    1185                 :            :                 // look up the field's name
    1186         [ #  # ]:          0 :                 aNew = ((SwSetExpFieldType*)pSFld->GetTyp())->GetSetRefName();
    1187                 :            :                 // Entry present?
    1188                 :            :                 sal_uInt16 nPos;
    1189         [ #  # ]:          0 :                 SwHash* pFnd = Find( aNew, ppHashTbl, rTblSize, &nPos );
    1190         [ #  # ]:          0 :                 if( pFnd )
    1191                 :            :                     // modify entry in the hash table
    1192         [ #  # ]:          0 :                     ((_HashStr*)pFnd)->aSetStr = pSFld->GetExpStr();
    1193                 :            :                 else
    1194                 :            :                     // insert the new entry
    1195                 :          0 :                     *(ppHashTbl + nPos ) = new _HashStr( aNew,
    1196 [ #  # ][ #  # ]:          0 :                             pSFld->GetExpStr(), (_HashStr*)*(ppHashTbl + nPos) );
                 [ #  # ]
    1197                 :            :             }
    1198                 :          0 :             break;
    1199                 :            :         case RES_DBFLD:
    1200                 :            :             {
    1201 [ #  # ][ #  # ]:          0 :                 const String& rName = pFld->GetTyp()->GetName();
    1202                 :            : 
    1203                 :            :                 // Insert entry in the hash table
    1204                 :            :                 // Entry present?
    1205                 :            :                 sal_uInt16 nPos;
    1206         [ #  # ]:          0 :                 SwHash* pFnd = Find( rName, ppHashTbl, rTblSize, &nPos );
    1207         [ #  # ]:          0 :                 String const value(pFld->ExpandField(IsClipBoard()));
    1208         [ #  # ]:          0 :                 if( pFnd )
    1209                 :            :                 {
    1210                 :            :                     // modify entry in the hash table
    1211         [ #  # ]:          0 :                     static_cast<_HashStr*>(pFnd)->aSetStr = value;
    1212                 :            :                 }
    1213                 :            :                 else
    1214                 :            :                 {
    1215                 :            :                     // insert the new entry
    1216                 :          0 :                     *(ppHashTbl + nPos ) = new _HashStr( rName,
    1217 [ #  # ][ #  # ]:          0 :                         value, static_cast<_HashStr *>(*(ppHashTbl + nPos)));
    1218 [ #  # ][ #  # ]:          0 :                 }
    1219                 :            :             }
    1220                 :          0 :             break;
    1221                 :            :         }
    1222                 :            :     }
    1223                 :          0 : }
    1224                 :            : 
    1225                 :       1440 : void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
    1226                 :            : {
    1227 [ +  - ][ +  - ]:       1440 :     if( IsExpFldsLocked() || IsInReading() )
         [ +  + ][ +  + ]
    1228                 :            :         return;
    1229                 :            : 
    1230                 :         93 :     sal_Bool bOldInUpdateFlds = pUpdtFlds->IsInUpdateFlds();
    1231                 :         93 :     pUpdtFlds->SetInUpdateFlds( sal_True );
    1232                 :            : 
    1233         [ +  - ]:         93 :     pUpdtFlds->MakeFldList( *this, sal_True, GETFLD_ALL );
    1234                 :         93 :     mbNewFldLst = sal_False;
    1235                 :            : 
    1236         [ +  + ]:         93 :     if( pUpdtFlds->GetSortLst()->empty() )
    1237                 :            :     {
    1238         [ +  + ]:         84 :         if( bUpdRefFlds )
    1239         [ +  - ]:         36 :             UpdateRefFlds(NULL);
    1240                 :            : 
    1241                 :         84 :         pUpdtFlds->SetInUpdateFlds( bOldInUpdateFlds );
    1242                 :         84 :         pUpdtFlds->SetFieldsDirty( sal_False );
    1243                 :            :         return ;
    1244                 :            :     }
    1245                 :            : 
    1246                 :            :     sal_uInt16 nWhich, n;
    1247                 :            : 
    1248                 :            :     // Hash table for all string replacements is filled on-the-fly.
    1249                 :            :     // Try to fabricate an uneven number.
    1250                 :          9 :     sal_uInt16 nStrFmtCnt = (( pFldTypes->size() / 7 ) + 1 ) * 7;
    1251         [ +  - ]:          9 :     SwHash** pHashStrTbl = new SwHash*[ nStrFmtCnt ];
    1252                 :          9 :     memset( pHashStrTbl, 0, sizeof( _HashStr* ) * nStrFmtCnt );
    1253                 :            : 
    1254                 :            :     {
    1255                 :            :         const SwFieldType* pFldType;
    1256                 :            :         // process seperately:
    1257         [ +  + ]:        300 :         for( n = pFldTypes->size(); n; )
    1258         [ +  - ]:        291 :             switch( ( pFldType = (*pFldTypes)[ --n ] )->Which() )
              [ +  +  + ]
    1259                 :            :             {
    1260                 :            :             case RES_USERFLD:
    1261                 :            :                 {
    1262                 :            :                     // Entry present?
    1263                 :            :                     sal_uInt16 nPos;
    1264 [ +  - ][ +  - ]:          3 :                     const String& rNm = pFldType->GetName();
    1265         [ +  - ]:          3 :                     String sExpand(((SwUserFieldType*)pFldType)->Expand(nsSwGetSetExpType::GSE_STRING, 0, 0));
    1266         [ +  - ]:          3 :                     SwHash* pFnd = Find( rNm, pHashStrTbl, nStrFmtCnt, &nPos );
    1267         [ -  + ]:          3 :                     if( pFnd )
    1268                 :            :                         // modify entry in the hash table
    1269         [ #  # ]:          0 :                         ((_HashStr*)pFnd)->aSetStr = sExpand;
    1270                 :            :                     else
    1271                 :            :                         // insert the new entry
    1272                 :          3 :                         *(pHashStrTbl + nPos ) = new _HashStr( rNm, sExpand,
    1273 [ +  - ][ +  - ]:          3 :                                                 (_HashStr*)*(pHashStrTbl + nPos) );
         [ +  - ][ +  - ]
    1274                 :            :                 }
    1275                 :          3 :                 break;
    1276                 :            :             case RES_SETEXPFLD:
    1277                 :         36 :                 ((SwSetExpFieldType*)pFldType)->SetOutlineChgNd( 0 );
    1278                 :         36 :                 break;
    1279                 :            :             }
    1280                 :            :     }
    1281                 :            : 
    1282                 :            :     // The array is filled with all fields; start calculation.
    1283         [ +  - ]:          9 :     SwCalc aCalc( *this );
    1284                 :            : 
    1285 [ +  - ][ +  - ]:          9 :     String sDBNumNm( SwFieldType::GetTypeStr( TYP_DBSETNUMBERFLD ) );
    1286                 :            : 
    1287                 :            :     // already set the current record number
    1288                 :          9 :     SwNewDBMgr* pMgr = GetNewDBMgr();
    1289         [ +  - ]:          9 :     pMgr->CloseAll(sal_False);
    1290                 :            : 
    1291                 :            :     // Make sure we don't hide all sections, which would lead to a crash. First, count how many of them do we have.
    1292                 :          9 :     int nShownSections = 0;
    1293 [ +  - ][ +  + ]:         18 :     for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it )
    1294                 :            :     {
    1295                 :          9 :         SwSection* pSect = (SwSection*)(*it)->GetSection();
    1296 [ +  - ][ +  - ]:          9 :         if ( pSect && !pSect->IsCondHidden())
                 [ +  - ]
    1297                 :          9 :             nShownSections++;
    1298                 :            :     }
    1299                 :            : 
    1300         [ +  - ]:          9 :     String aNew;
    1301 [ +  - ][ +  + ]:         18 :     for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it )
    1302                 :            :     {
    1303                 :          9 :         SwSection* pSect = (SwSection*)(*it)->GetSection();
    1304         [ +  - ]:          9 :         if( pSect )
    1305                 :            :         {
    1306                 :            : 
    1307                 :            :             SwSbxValue aValue = aCalc.Calculate(
    1308         [ +  - ]:          9 :                                         pSect->GetCondition() );
    1309         [ +  + ]:          9 :             if(!aValue.IsVoidValue())
    1310                 :            :             {
    1311                 :            :                 // Do we want to hide this one?
    1312         [ +  - ]:          3 :                 bool bHide = aValue.GetBool();
    1313 [ +  - ][ +  - ]:          3 :                 if (bHide && !pSect->IsCondHidden())
                 [ +  - ]
    1314                 :            :                 {
    1315                 :            :                     // This section will be hidden, but it wasn't before
    1316         [ +  - ]:          3 :                     if (nShownSections == 1)
    1317                 :            :                     {
    1318                 :            :                         // This would be the last section, so set its condition to false, and avoid hiding it.
    1319                 :          3 :                         OUString aCond("0");
    1320 [ +  - ][ +  - ]:          3 :                         pSect->SetCondition(aCond);
                 [ +  - ]
    1321                 :          3 :                         bHide = false;
    1322                 :            :                     }
    1323                 :          3 :                     nShownSections--;
    1324                 :            :                 }
    1325         [ +  - ]:          3 :                 pSect->SetCondHidden( bHide );
    1326                 :            :             }
    1327         [ +  - ]:          9 :             continue;
    1328                 :            :         }
    1329                 :            : 
    1330                 :          0 :         SwTxtFld* pTxtFld = (SwTxtFld*)(*it)->GetFld();
    1331         [ #  # ]:          0 :         if( !pTxtFld )
    1332                 :            :         {
    1333                 :            :             OSL_ENSURE( !this, "what's wrong now'" );
    1334                 :          0 :             continue;
    1335                 :            :         }
    1336                 :            : 
    1337                 :          0 :         SwFmtFld* pFmtFld = (SwFmtFld*)&pTxtFld->GetFld();
    1338                 :          0 :         SwField* pFld = pFmtFld->GetFld();
    1339                 :            : 
    1340   [ #  #  #  #  :          0 :         switch( nWhich = pFld->GetTyp()->Which() )
                #  #  # ]
    1341                 :            :         {
    1342                 :            :         case RES_HIDDENTXTFLD:
    1343                 :            :         {
    1344                 :          0 :             SwHiddenTxtField* pHFld = (SwHiddenTxtField*)pFld;
    1345 [ #  # ][ #  # ]:          0 :             SwSbxValue aValue = aCalc.Calculate( pHFld->GetPar1() );
         [ #  # ][ #  # ]
    1346         [ #  # ]:          0 :             sal_Bool bValue = !aValue.GetBool();
    1347         [ #  # ]:          0 :             if(!aValue.IsVoidValue())
    1348                 :            :             {
    1349                 :          0 :                 pHFld->SetValue( bValue );
    1350                 :            :                 // evaluate field
    1351         [ #  # ]:          0 :                 pHFld->Evaluate(this);
    1352         [ #  # ]:          0 :             }
    1353                 :            :         }
    1354                 :          0 :         break;
    1355                 :            :         case RES_HIDDENPARAFLD:
    1356                 :            :         {
    1357                 :          0 :             SwHiddenParaField* pHPFld = (SwHiddenParaField*)pFld;
    1358 [ #  # ][ #  # ]:          0 :             SwSbxValue aValue = aCalc.Calculate( pHPFld->GetPar1() );
         [ #  # ][ #  # ]
    1359         [ #  # ]:          0 :             sal_Bool bValue = aValue.GetBool();
    1360         [ #  # ]:          0 :             if(!aValue.IsVoidValue())
    1361         [ #  # ]:          0 :                 pHPFld->SetHidden( bValue );
    1362                 :            :         }
    1363                 :          0 :         break;
    1364                 :            :         case RES_DBSETNUMBERFLD:
    1365                 :            :         {
    1366         [ #  # ]:          0 :             ((SwDBSetNumberField*)pFld)->Evaluate(this);
    1367         [ #  # ]:          0 :             aCalc.VarChange( sDBNumNm, ((SwDBSetNumberField*)pFld)->GetSetNumber());
    1368                 :            :         }
    1369                 :          0 :         break;
    1370                 :            :         case RES_DBNEXTSETFLD:
    1371                 :            :         case RES_DBNUMSETFLD:
    1372         [ #  # ]:          0 :             UpdateDBNumFlds( *(SwDBNameInfField*)pFld, aCalc );
    1373                 :          0 :         break;
    1374                 :            :         case RES_DBFLD:
    1375                 :            :         {
    1376                 :            :             // evaluate field
    1377         [ #  # ]:          0 :             ((SwDBField*)pFld)->Evaluate();
    1378                 :            : 
    1379                 :          0 :             SwDBData aTmpDBData(((SwDBField*)pFld)->GetDBData());
    1380                 :            : 
    1381 [ #  # ][ #  # ]:          0 :             if( pMgr->IsDataSourceOpen(aTmpDBData.sDataSource, aTmpDBData.sCommand, sal_False))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1382 [ #  # ][ #  # ]:          0 :                 aCalc.VarChange( sDBNumNm, pMgr->GetSelectedRecordId(aTmpDBData.sDataSource, aTmpDBData.sCommand, aTmpDBData.nCommandType));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1383                 :            : 
    1384 [ #  # ][ #  # ]:          0 :             const String& rName = pFld->GetTyp()->GetName();
    1385                 :            : 
    1386                 :            :             // Set value for Calculator
    1387                 :            : //JP 10.02.96: GetValue doesn't make sense here
    1388                 :            : //          ((SwDBField*)pFld)->GetValue();
    1389                 :            : 
    1390                 :            : //!OK           aCalc.VarChange(aName, ((SwDBField*)pFld)->GetValue(aCalc));
    1391                 :            : 
    1392                 :            :             // Add entry to hash table
    1393                 :            :             // Entry present?
    1394                 :            :             sal_uInt16 nPos;
    1395         [ #  # ]:          0 :             SwHash* pFnd = Find( rName, pHashStrTbl, nStrFmtCnt, &nPos );
    1396         [ #  # ]:          0 :             String const value(pFld->ExpandField(IsClipBoard()));
    1397         [ #  # ]:          0 :             if( pFnd )
    1398                 :            :             {
    1399                 :            :                 // Modify entry in the hash table
    1400         [ #  # ]:          0 :                 static_cast<_HashStr*>(pFnd)->aSetStr = value;
    1401                 :            :             }
    1402                 :            :             else
    1403                 :            :             {
    1404                 :            :                 // insert new entry
    1405                 :          0 :                 *(pHashStrTbl + nPos ) = new _HashStr( rName,
    1406 [ #  # ][ #  # ]:          0 :                     value, static_cast<_HashStr *>(*(pHashStrTbl + nPos)));
    1407 [ #  # ][ #  # ]:          0 :             }
    1408                 :            :         }
    1409                 :          0 :         break;
    1410                 :            :         case RES_GETEXPFLD:
    1411                 :            :         case RES_SETEXPFLD:
    1412                 :            :         {
    1413 [ #  # ][ #  # ]:          0 :             if( nsSwGetSetExpType::GSE_STRING & pFld->GetSubType() )        // replace String
    1414                 :            :             {
    1415         [ #  # ]:          0 :                 if( RES_GETEXPFLD == nWhich )
    1416                 :            :                 {
    1417                 :          0 :                     SwGetExpField* pGFld = (SwGetExpField*)pFld;
    1418                 :            : 
    1419         [ #  # ]:          0 :                     if( (!pUpdtFld || pUpdtFld == pTxtFld )
           [ #  #  #  # ]
                 [ #  # ]
    1420                 :          0 :                         && pGFld->IsInBodyTxt() )
    1421                 :            :                     {
    1422                 :            :                         LookString( pHashStrTbl, nStrFmtCnt,
    1423 [ #  # ][ #  # ]:          0 :                                     pGFld->GetFormula(), aNew );
                 [ #  # ]
    1424         [ #  # ]:          0 :                         pGFld->ChgExpStr( aNew );
    1425                 :            :                     }
    1426                 :            :                 }
    1427                 :            :                 else
    1428                 :            :                 {
    1429                 :          0 :                     SwSetExpField* pSFld = (SwSetExpField*)pFld;
    1430                 :            :                     // is the "formula" a field?
    1431                 :            :                     LookString( pHashStrTbl, nStrFmtCnt,
    1432 [ #  # ][ #  # ]:          0 :                                 pSFld->GetFormula(), aNew );
                 [ #  # ]
    1433                 :            : 
    1434         [ #  # ]:          0 :                     if( !aNew.Len() )               // nothing found then the formula is the new value
    1435 [ #  # ][ #  # ]:          0 :                         aNew = pSFld->GetFormula();
                 [ #  # ]
    1436                 :            : 
    1437                 :            :                     // only update one field
    1438 [ #  # ][ #  # ]:          0 :                     if( !pUpdtFld || pUpdtFld == pTxtFld )
    1439         [ #  # ]:          0 :                         pSFld->ChgExpStr( aNew );
    1440                 :            : 
    1441                 :            :                     // lookup the field's name
    1442         [ #  # ]:          0 :                     aNew = ((SwSetExpFieldType*)pSFld->GetTyp())->GetSetRefName();
    1443                 :            :                     // Entry present?
    1444                 :            :                     sal_uInt16 nPos;
    1445         [ #  # ]:          0 :                     SwHash* pFnd = Find( aNew, pHashStrTbl, nStrFmtCnt, &nPos );
    1446         [ #  # ]:          0 :                     if( pFnd )
    1447                 :            :                         // Modify entry in the hash table
    1448         [ #  # ]:          0 :                         ((_HashStr*)pFnd)->aSetStr = pSFld->GetExpStr();
    1449                 :            :                     else
    1450                 :            :                         // insert new entry
    1451                 :          0 :                         *(pHashStrTbl + nPos ) = pFnd = new _HashStr( aNew,
    1452                 :            :                                         pSFld->GetExpStr(),
    1453 [ #  # ][ #  # ]:          0 :                                         (_HashStr*)*(pHashStrTbl + nPos) );
    1454                 :            : 
    1455                 :            :                     // Extension for calculation with Strings
    1456         [ #  # ]:          0 :                     SwSbxValue aValue;
    1457 [ #  # ][ #  # ]:          0 :                     aValue.PutString( ((_HashStr*)pFnd)->aSetStr );
    1458 [ #  # ][ #  # ]:          0 :                     aCalc.VarChange( aNew, aValue );
    1459                 :            :                 }
    1460                 :            :             }
    1461                 :            :             else            // recalculate formula
    1462                 :            :             {
    1463         [ #  # ]:          0 :                 if( RES_GETEXPFLD == nWhich )
    1464                 :            :                 {
    1465                 :          0 :                     SwGetExpField* pGFld = (SwGetExpField*)pFld;
    1466                 :            : 
    1467         [ #  # ]:          0 :                     if( (!pUpdtFld || pUpdtFld == pTxtFld )
           [ #  #  #  # ]
                 [ #  # ]
    1468                 :          0 :                         && pGFld->IsInBodyTxt() )
    1469                 :            :                     {
    1470                 :            :                         SwSbxValue aValue = aCalc.Calculate(
    1471 [ #  # ][ #  # ]:          0 :                                         pGFld->GetFormula());
                 [ #  # ]
    1472         [ #  # ]:          0 :                         if(!aValue.IsVoidValue())
    1473 [ #  # ][ #  # ]:          0 :                             pGFld->SetValue(aValue.GetDouble() );
                 [ #  # ]
    1474                 :            :                     }
    1475                 :            :                 }
    1476                 :            :                 else
    1477                 :            :                 {
    1478                 :          0 :                     SwSetExpField* pSFld = (SwSetExpField*)pFld;
    1479                 :          0 :                     SwSetExpFieldType* pSFldTyp = (SwSetExpFieldType*)pFld->GetTyp();
    1480 [ #  # ][ #  # ]:          0 :                     aNew = pSFldTyp->GetName();
    1481                 :            : 
    1482                 :          0 :                     SwNode* pSeqNd = 0;
    1483                 :            : 
    1484         [ #  # ]:          0 :                     if( pSFld->IsSequenceFld() )
    1485                 :            :                     {
    1486                 :          0 :                         const sal_uInt8 nLvl = pSFldTyp->GetOutlineLvl();
    1487         [ #  # ]:          0 :                         if( MAXLEVEL > nLvl )
    1488                 :            :                         {
    1489                 :            :                             // test if the Number needs to be updated
    1490 [ #  # ][ #  # ]:          0 :                             pSeqNd = GetNodes()[ (*it)->GetNode() ];
    1491                 :            : 
    1492                 :            :                             const SwTxtNode* pOutlNd = pSeqNd->
    1493         [ #  # ]:          0 :                                     FindOutlineNodeOfLevel( nLvl );
    1494 [ #  # ][ #  # ]:          0 :                             if( pSFldTyp->GetOutlineChgNd() != pOutlNd )
    1495                 :            :                             {
    1496         [ #  # ]:          0 :                                 pSFldTyp->SetOutlineChgNd( pOutlNd );
    1497         [ #  # ]:          0 :                                 aCalc.VarChange( aNew, 0 );
    1498                 :            :                             }
    1499                 :            :                         }
    1500                 :            :                     }
    1501                 :            : 
    1502         [ #  # ]:          0 :                     aNew += '=';
    1503 [ #  # ][ #  # ]:          0 :                     aNew += pSFld->GetFormula();
                 [ #  # ]
    1504                 :            : 
    1505         [ #  # ]:          0 :                     SwSbxValue aValue = aCalc.Calculate( aNew );
    1506         [ #  # ]:          0 :                     double nErg = aValue.GetDouble();
    1507                 :            :                     // only update one field
    1508 [ #  # ][ #  # ]:          0 :                     if( !aValue.IsVoidValue() && (!pUpdtFld || pUpdtFld == pTxtFld) )
         [ #  # ][ #  # ]
    1509                 :            :                     {
    1510         [ #  # ]:          0 :                         pSFld->SetValue( nErg );
    1511                 :            : 
    1512         [ #  # ]:          0 :                         if( pSeqNd )
    1513         [ #  # ]:          0 :                             pSFldTyp->SetChapter( *pSFld, *pSeqNd );
    1514         [ #  # ]:          0 :                     }
    1515                 :            :                 }
    1516                 :            :             }
    1517                 :            :         }
    1518                 :            :         } // switch
    1519                 :            : 
    1520         [ #  # ]:          0 :         pFmtFld->ModifyNotification( 0, 0 );        // trigger formatting
    1521                 :            : 
    1522         [ #  # ]:          0 :         if( pUpdtFld == pTxtFld )       // if only this one is updated
    1523                 :            :         {
    1524 [ #  # ][ #  # ]:          0 :             if( RES_GETEXPFLD == nWhich ||      // only GetField or
                 [ #  # ]
    1525                 :            :                 RES_HIDDENTXTFLD == nWhich ||   // HiddenTxt?
    1526                 :            :                 RES_HIDDENPARAFLD == nWhich)    // HiddenParaFld?
    1527                 :          0 :                 break;                          // quit
    1528                 :          0 :             pUpdtFld = 0;                       // update all from here on
    1529                 :            :         }
    1530                 :            :     }
    1531                 :            : 
    1532         [ +  - ]:          9 :     pMgr->CloseAll(sal_False);
    1533                 :            :     // delete hash table
    1534         [ +  - ]:          9 :     ::DeleteHashTable( pHashStrTbl, nStrFmtCnt );
    1535                 :            : 
    1536                 :            :     // update reference fields
    1537         [ +  + ]:          9 :     if( bUpdRefFlds )
    1538         [ +  - ]:          6 :         UpdateRefFlds(NULL);
    1539                 :            : 
    1540                 :          9 :     pUpdtFlds->SetInUpdateFlds( bOldInUpdateFlds );
    1541 [ +  - ][ +  - ]:       1440 :     pUpdtFlds->SetFieldsDirty( sal_False );
                 [ +  - ]
    1542                 :            : }
    1543                 :            : 
    1544                 :          0 : void SwDoc::UpdateDBNumFlds( SwDBNameInfField& rDBFld, SwCalc& rCalc )
    1545                 :            : {
    1546                 :          0 :     SwNewDBMgr* pMgr = GetNewDBMgr();
    1547                 :            : 
    1548                 :          0 :     sal_uInt16 nFldType = rDBFld.Which();
    1549                 :            : 
    1550 [ #  # ][ #  # ]:          0 :     sal_Bool bPar1 = rCalc.Calculate( rDBFld.GetPar1() ).GetBool();
                 [ #  # ]
    1551                 :            : 
    1552         [ #  # ]:          0 :     if( RES_DBNEXTSETFLD == nFldType )
    1553                 :          0 :         ((SwDBNextSetField&)rDBFld).SetCondValid( bPar1 );
    1554                 :            :     else
    1555                 :          0 :         ((SwDBNumSetField&)rDBFld).SetCondValid( bPar1 );
    1556                 :            : 
    1557         [ #  # ]:          0 :     if( !rDBFld.GetRealDBData().sDataSource.isEmpty() )
    1558                 :            :     {
    1559                 :            :         // Edit a certain database
    1560         [ #  # ]:          0 :         if( RES_DBNEXTSETFLD == nFldType )
    1561         [ #  # ]:          0 :             ((SwDBNextSetField&)rDBFld).Evaluate(this);
    1562                 :            :         else
    1563         [ #  # ]:          0 :             ((SwDBNumSetField&)rDBFld).Evaluate(this);
    1564                 :            : 
    1565         [ #  # ]:          0 :         SwDBData aTmpDBData( rDBFld.GetDBData(this) );
    1566                 :            : 
    1567 [ #  # ][ #  # ]:          0 :         if( pMgr->OpenDataSource( aTmpDBData.sDataSource, aTmpDBData.sCommand, -1, false ))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1568                 :            :             rCalc.VarChange( lcl_GetDBVarName( *this, rDBFld),
    1569 [ #  # ][ #  # ]:          0 :                         pMgr->GetSelectedRecordId(aTmpDBData.sDataSource, aTmpDBData.sCommand, aTmpDBData.nCommandType) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
    1570                 :            :     }
    1571                 :            :     else
    1572                 :            :     {
    1573                 :            :         OSL_FAIL("TODO: what should happen with unnamed DBFields?");
    1574                 :            :     }
    1575                 :          0 : }
    1576                 :            : 
    1577                 :       1549 : void SwDoc::_InitFieldTypes()       // is being called by the CTOR
    1578                 :            : {
    1579                 :            :     // Field types
    1580 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDateTimeFieldType(this) );
    1581 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwChapterFieldType );
    1582 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwPageNumberFieldType );
    1583 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwAuthorFieldType );
    1584 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwFileNameFieldType(this) );
    1585 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDBNameFieldType(this) );
    1586 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwGetExpFieldType(this) );
    1587 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwGetRefFieldType( this ) );
    1588 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwHiddenTxtFieldType );
    1589 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwPostItFieldType(this) );
    1590 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDocStatFieldType(this) );
    1591 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDocInfoFieldType(this) );
    1592 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwInputFieldType( this ) );
    1593 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwTblFieldType( this ) );
    1594 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwMacroFieldType(this) );
    1595 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwHiddenParaFieldType );
    1596 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDBNextSetFieldType );
    1597 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDBNumSetFieldType );
    1598 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDBSetNumberFieldType );
    1599 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwTemplNameFieldType(this) );
    1600 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwTemplNameFieldType(this) );
    1601 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwExtUserFieldType );
    1602 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwRefPageSetFieldType );
    1603 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwRefPageGetFieldType( this ) );
    1604 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwJumpEditFieldType( this ) );
    1605 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwScriptFieldType( this ) );
    1606 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwCombinedCharFieldType );
    1607 [ +  - ][ +  - ]:       1549 :     pFldTypes->push_back( new SwDropDownFieldType );
    1608                 :            : 
    1609                 :            :     // Types have to be at the end!
    1610                 :            :     // We expect this in the InsertFldType!
    1611                 :            :     // MIB 14.04.95: In Sw3StringPool::Setup (sw3imp.cxx) and
    1612                 :            :     //               lcl_sw3io_InSetExpField (sw3field.cxx) now also
    1613                 :            :     pFldTypes->push_back( new SwSetExpFieldType(this,
    1614 [ +  - ][ +  - ]:       1549 :                 SW_RESSTR(STR_POOLCOLL_LABEL_ABB), nsSwGetSetExpType::GSE_SEQ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1615                 :            :     pFldTypes->push_back( new SwSetExpFieldType(this,
    1616 [ +  - ][ +  - ]:       1549 :                 SW_RESSTR(STR_POOLCOLL_LABEL_TABLE), nsSwGetSetExpType::GSE_SEQ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1617                 :            :     pFldTypes->push_back( new SwSetExpFieldType(this,
    1618 [ +  - ][ +  - ]:       1549 :                 SW_RESSTR(STR_POOLCOLL_LABEL_FRAME), nsSwGetSetExpType::GSE_SEQ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1619                 :            :     pFldTypes->push_back( new SwSetExpFieldType(this,
    1620 [ +  - ][ +  - ]:       1549 :                 SW_RESSTR(STR_POOLCOLL_LABEL_DRAWING), nsSwGetSetExpType::GSE_SEQ) );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
    1621                 :            : 
    1622                 :            :     OSL_ENSURE( pFldTypes->size() == INIT_FLDTYPES, "Bad initsize: SwFldTypes" );
    1623                 :       1549 : }
    1624                 :            : 
    1625                 :          0 : void SwDoc::InsDelFldInFldLst( bool bIns, const SwTxtFld& rFld )
    1626                 :            : {
    1627 [ #  # ][ #  # ]:          0 :     if( !mbNewFldLst || !IsInDtor() )
                 [ #  # ]
    1628                 :          0 :         pUpdtFlds->InsDelFldInFldLst( bIns, rFld );
    1629                 :          0 : }
    1630                 :            : 
    1631                 :        207 : SwDBData SwDoc::GetDBData()
    1632                 :            : {
    1633                 :        207 :     return GetDBDesc();
    1634                 :            : }
    1635                 :            : 
    1636                 :        268 : const SwDBData& SwDoc::GetDBDesc()
    1637                 :            : {
    1638         [ +  + ]:        268 :     if(aDBData.sDataSource.isEmpty())
    1639                 :            :     {
    1640                 :        252 :         const sal_uInt16 nSize = pFldTypes->size();
    1641 [ +  + ][ +  - ]:       8322 :         for(sal_uInt16 i = 0; i < nSize && aDBData.sDataSource.isEmpty(); ++i)
                 [ +  + ]
    1642                 :            :         {
    1643                 :       8070 :             SwFieldType& rFldType = *((*pFldTypes)[i]);
    1644                 :       8070 :             sal_uInt16 nWhich = rFldType.Which();
    1645         [ +  + ]:       8070 :             if(IsUsed(rFldType))
    1646                 :            :             {
    1647         [ -  + ]:          9 :                 switch(nWhich)
    1648                 :            :                 {
    1649                 :            :                     case RES_DBFLD:
    1650                 :            :                     case RES_DBNEXTSETFLD:
    1651                 :            :                     case RES_DBNUMSETFLD:
    1652                 :            :                     case RES_DBSETNUMBERFLD:
    1653                 :            :                     {
    1654         [ #  # ]:          0 :                         SwIterator<SwFmtFld,SwFieldType> aIter( rFldType );
    1655 [ #  # ][ #  # ]:          0 :                         for( SwFmtFld* pFld = aIter.First(); pFld; pFld = aIter.Next() )
                 [ #  # ]
    1656                 :            :                         {
    1657 [ #  # ][ #  # ]:          0 :                             if(pFld->IsFldInDoc())
    1658                 :            :                             {
    1659         [ #  # ]:          0 :                                 if(RES_DBFLD == nWhich)
    1660                 :            :                                     aDBData =
    1661                 :          0 :                                         (static_cast < SwDBFieldType * > (pFld->GetFld()->GetTyp()))
    1662                 :          0 :                                             ->GetDBData();
    1663                 :            :                                 else
    1664                 :          0 :                                     aDBData = (static_cast < SwDBNameInfField* > (pFld->GetFld()))->GetRealDBData();
    1665                 :          0 :                                 break;
    1666                 :            :                             }
    1667         [ #  # ]:          0 :                         }
    1668                 :            :                     }
    1669                 :          9 :                     break;
    1670                 :            :                 }
    1671                 :            :             }
    1672                 :            :         }
    1673                 :            :     }
    1674         [ +  + ]:        268 :     if(aDBData.sDataSource.isEmpty())
    1675                 :        252 :         aDBData = GetNewDBMgr()->GetAddressDBName();
    1676                 :        268 :     return aDBData;
    1677                 :            : }
    1678                 :            : 
    1679                 :        102 : void SwDoc::SetInitDBFields( sal_Bool b )
    1680                 :            : {
    1681                 :        102 :     GetNewDBMgr()->SetInitDBFields( b );
    1682                 :        102 : }
    1683                 :            : 
    1684                 :            : /*--------------------------------------------------------------------
    1685                 :            :     Description: Get all databases that are used by fields
    1686                 :            :  --------------------------------------------------------------------*/
    1687                 :          0 : String lcl_DBDataToString(const SwDBData& rData)
    1688                 :            : {
    1689                 :          0 :     String sRet = rData.sDataSource;
    1690         [ #  # ]:          0 :     sRet += DB_DELIM;
    1691 [ #  # ][ #  # ]:          0 :     sRet += (String)rData.sCommand;
                 [ #  # ]
    1692         [ #  # ]:          0 :     sRet += DB_DELIM;
    1693 [ #  # ][ #  # ]:          0 :     sRet += String::CreateFromInt32(rData.nCommandType);
                 [ #  # ]
    1694                 :          0 :     return sRet;
    1695                 :            : }
    1696                 :            : 
    1697                 :          0 : void SwDoc::GetAllUsedDB( std::vector<String>& rDBNameList,
    1698                 :            :                           const std::vector<String>* pAllDBNames )
    1699                 :            : {
    1700         [ #  # ]:          0 :     std::vector<String> aUsedDBNames;
    1701         [ #  # ]:          0 :     std::vector<String> aAllDBNames;
    1702                 :            : 
    1703         [ #  # ]:          0 :     if( !pAllDBNames )
    1704                 :            :     {
    1705         [ #  # ]:          0 :         GetAllDBNames( aAllDBNames );
    1706                 :          0 :         pAllDBNames = &aAllDBNames;
    1707                 :            :     }
    1708                 :            : 
    1709                 :          0 :     SwSectionFmts& rArr = GetSections();
    1710         [ #  # ]:          0 :     for (sal_uInt16 n = rArr.size(); n; )
    1711                 :            :     {
    1712 [ #  # ][ #  # ]:          0 :         SwSection* pSect = rArr[ --n ]->GetSection();
    1713                 :            : 
    1714         [ #  # ]:          0 :         if( pSect )
    1715                 :            :         {
    1716         [ #  # ]:          0 :             String aCond( pSect->GetCondition() );
    1717                 :            :             AddUsedDBToList( rDBNameList, FindUsedDBs( *pAllDBNames,
    1718 [ #  # ][ #  # ]:          0 :                                                 aCond, aUsedDBNames ) );
    1719         [ #  # ]:          0 :             aUsedDBNames.clear();
    1720                 :            :         }
    1721                 :            :     }
    1722                 :            : 
    1723                 :            :     const SfxPoolItem* pItem;
    1724         [ #  # ]:          0 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_FIELD );
    1725         [ #  # ]:          0 :     for (sal_uInt32 n = 0; n < nMaxItems; ++n)
    1726                 :            :     {
    1727 [ #  # ][ #  # ]:          0 :         if( 0 == (pItem = GetAttrPool().GetItem2( RES_TXTATR_FIELD, n ) ))
    1728                 :          0 :             continue;
    1729                 :            : 
    1730                 :          0 :         const SwFmtFld* pFmtFld = (SwFmtFld*)pItem;
    1731                 :          0 :         const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
    1732 [ #  # ][ #  # ]:          0 :         if( !pTxtFld || !pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
         [ #  # ][ #  # ]
    1733                 :          0 :             continue;
    1734                 :            : 
    1735                 :          0 :         const SwField* pFld = pFmtFld->GetFld();
    1736   [ #  #  #  #  :          0 :         switch( pFld->GetTyp()->Which() )
                   #  # ]
    1737                 :            :         {
    1738                 :            :             case RES_DBFLD:
    1739                 :            :                 AddUsedDBToList( rDBNameList,
    1740 [ #  # ][ #  # ]:          0 :                                 lcl_DBDataToString(((SwDBField*)pFld)->GetDBData() ));
                 [ #  # ]
    1741                 :          0 :                 break;
    1742                 :            : 
    1743                 :            :             case RES_DBSETNUMBERFLD:
    1744                 :            :             case RES_DBNAMEFLD:
    1745                 :            :                 AddUsedDBToList( rDBNameList,
    1746 [ #  # ][ #  # ]:          0 :                                 lcl_DBDataToString(((SwDBNameInfField*)pFld)->GetRealDBData() ));
                 [ #  # ]
    1747                 :          0 :                 break;
    1748                 :            : 
    1749                 :            :             case RES_DBNUMSETFLD:
    1750                 :            :             case RES_DBNEXTSETFLD:
    1751                 :            :                 AddUsedDBToList( rDBNameList,
    1752 [ #  # ][ #  # ]:          0 :                                 lcl_DBDataToString(((SwDBNameInfField*)pFld)->GetRealDBData() ));
                 [ #  # ]
    1753                 :            :                 // no break  // JP: is that right like that?
    1754                 :            : 
    1755                 :            :             case RES_HIDDENTXTFLD:
    1756                 :            :             case RES_HIDDENPARAFLD:
    1757                 :            :                 AddUsedDBToList(rDBNameList, FindUsedDBs( *pAllDBNames,
    1758 [ #  # ][ #  # ]:          0 :                                             pFld->GetPar1(), aUsedDBNames ));
         [ #  # ][ #  # ]
                 [ #  # ]
    1759                 :          0 :                 aUsedDBNames.clear();
    1760                 :          0 :                 break;
    1761                 :            : 
    1762                 :            :             case RES_SETEXPFLD:
    1763                 :            :             case RES_GETEXPFLD:
    1764                 :            :             case RES_TABLEFLD:
    1765                 :            :                 AddUsedDBToList(rDBNameList, FindUsedDBs( *pAllDBNames,
    1766 [ #  # ][ #  # ]:          0 :                                         pFld->GetFormula(), aUsedDBNames ));
         [ #  # ][ #  # ]
    1767                 :          0 :                 aUsedDBNames.clear();
    1768                 :          0 :                 break;
    1769                 :            :         }
    1770                 :          0 :     }
    1771                 :          0 : }
    1772                 :            : 
    1773                 :          0 : void SwDoc::GetAllDBNames( std::vector<String>& rAllDBNames )
    1774                 :            : {
    1775                 :          0 :     SwNewDBMgr* pMgr = GetNewDBMgr();
    1776                 :            : 
    1777                 :          0 :     const SwDSParamArr& rArr = pMgr->GetDSParamArray();
    1778         [ #  # ]:          0 :     for(sal_uInt16 i = 0; i < rArr.size(); i++)
    1779                 :            :     {
    1780                 :          0 :         const SwDSParam* pParam = &rArr[i];
    1781         [ #  # ]:          0 :         String* pStr = new String( pParam->sDataSource );
    1782                 :          0 :         (*pStr) += DB_DELIM;
    1783         [ #  # ]:          0 :         (*pStr) += (String)pParam->sCommand;
    1784                 :          0 :         rAllDBNames.push_back(*pStr);
    1785                 :            :     }
    1786                 :          0 : }
    1787                 :            : 
    1788                 :          0 : std::vector<String>& SwDoc::FindUsedDBs( const std::vector<String>& rAllDBNames,
    1789                 :            :                                     const String& rFormel,
    1790                 :            :                                    std::vector<String>& rUsedDBNames )
    1791                 :            : {
    1792         [ #  # ]:          0 :     const CharClass& rCC = GetAppCharClass();
    1793         [ #  # ]:          0 :     String  sFormel( rFormel);
    1794                 :            : #ifndef UNX
    1795                 :            :     sFormel = rCC.uppercase( sFormel );
    1796                 :            : #endif
    1797                 :            : 
    1798                 :            :     xub_StrLen nPos;
    1799         [ #  # ]:          0 :     for (sal_uInt16 i = 0; i < rAllDBNames.size(); ++i )
    1800                 :            :     {
    1801 [ #  # ][ #  # ]:          0 :         String pStr(rAllDBNames[i]);
    1802                 :            : 
    1803         [ #  # ]:          0 :         if( STRING_NOTFOUND != (nPos = sFormel.Search( pStr )) &&
           [ #  #  #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
    1804                 :          0 :             sFormel.GetChar( nPos + pStr.Len() ) == '.' &&
    1805         [ #  # ]:          0 :             (!nPos || !rCC.isLetterNumeric( sFormel, nPos - 1 )))
    1806                 :            :         {
    1807                 :            :             // Look up table name
    1808                 :            :             xub_StrLen nEndPos;
    1809                 :          0 :             nPos += pStr.Len() + 1;
    1810 [ #  # ][ #  # ]:          0 :             if( STRING_NOTFOUND != (nEndPos = sFormel.Search('.', nPos)) )
    1811                 :            :             {
    1812         [ #  # ]:          0 :                 pStr.Append( DB_DELIM );
    1813 [ #  # ][ #  # ]:          0 :                 pStr.Append( sFormel.Copy( nPos, nEndPos - nPos ));
                 [ #  # ]
    1814         [ #  # ]:          0 :                 rUsedDBNames.push_back(pStr);
    1815                 :            :             }
    1816                 :            :         }
    1817         [ #  # ]:          0 :     }
    1818         [ #  # ]:          0 :     return rUsedDBNames;
    1819                 :            : }
    1820                 :            : 
    1821                 :          0 : void SwDoc::AddUsedDBToList( std::vector<String>& rDBNameList,
    1822                 :            :                              const std::vector<String>& rUsedDBNames )
    1823                 :            : {
    1824         [ #  # ]:          0 :     for (sal_uInt16 i = 0; i < rUsedDBNames.size(); ++i)
    1825                 :          0 :         AddUsedDBToList( rDBNameList, rUsedDBNames[i] );
    1826                 :          0 : }
    1827                 :            : 
    1828                 :          0 : void SwDoc::AddUsedDBToList( std::vector<String>& rDBNameList, const String& rDBName)
    1829                 :            : {
    1830         [ #  # ]:          0 :     if( !rDBName.Len() )
    1831                 :            :         return;
    1832                 :            : 
    1833                 :            : #ifdef UNX
    1834         [ #  # ]:          0 :     for( sal_uInt16 i = 0; i < rDBNameList.size(); ++i )
    1835 [ #  # ][ #  # ]:          0 :         if( rDBName == rDBNameList[i].GetToken(0) )
         [ #  # ][ #  # ]
                 [ #  # ]
    1836                 :            :             return;
    1837                 :            : #else
    1838                 :            :     const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
    1839                 :            :     for( sal_uInt16 i = 0; i < rDBNameList.size(); ++i )
    1840                 :            :         if( rSCmp.isEqual( rDBName, rDBNameList[i].GetToken(0) ) )
    1841                 :            :             return;
    1842                 :            : #endif
    1843                 :            : 
    1844                 :          0 :     SwDBData aData;
    1845 [ #  # ][ #  # ]:          0 :     aData.sDataSource = rDBName.GetToken(0, DB_DELIM);
                 [ #  # ]
    1846 [ #  # ][ #  # ]:          0 :     aData.sCommand = rDBName.GetToken(1, DB_DELIM);
                 [ #  # ]
    1847                 :          0 :     aData.nCommandType = -1;
    1848         [ #  # ]:          0 :     GetNewDBMgr()->CreateDSData(aData);
    1849         [ #  # ]:          0 :     rDBNameList.push_back(rDBName);
    1850                 :            : }
    1851                 :            : 
    1852                 :          0 : void SwDoc::ChangeDBFields( const std::vector<String>& rOldNames,
    1853                 :            :                             const String& rNewName )
    1854                 :            : {
    1855                 :          0 :     SwDBData aNewDBData;
    1856 [ #  # ][ #  # ]:          0 :     aNewDBData.sDataSource = rNewName.GetToken(0, DB_DELIM);
                 [ #  # ]
    1857 [ #  # ][ #  # ]:          0 :     aNewDBData.sCommand = rNewName.GetToken(1, DB_DELIM);
                 [ #  # ]
    1858 [ #  # ][ #  # ]:          0 :     aNewDBData.nCommandType = (short)rNewName.GetToken(2, DB_DELIM).ToInt32();
                 [ #  # ]
    1859                 :            : 
    1860         [ #  # ]:          0 :     String sFormel;
    1861                 :            : 
    1862                 :          0 :     SwSectionFmts& rArr = GetSections();
    1863         [ #  # ]:          0 :     for (sal_uInt16 n = rArr.size(); n; )
    1864                 :            :     {
    1865 [ #  # ][ #  # ]:          0 :         SwSection* pSect = rArr[ --n ]->GetSection();
    1866                 :            : 
    1867         [ #  # ]:          0 :         if( pSect )
    1868                 :            :         {
    1869         [ #  # ]:          0 :             sFormel = pSect->GetCondition();
    1870         [ #  # ]:          0 :             ReplaceUsedDBs( rOldNames, rNewName, sFormel);
    1871         [ #  # ]:          0 :             pSect->SetCondition(sFormel);
    1872                 :            :         }
    1873                 :            :     }
    1874                 :            : 
    1875                 :            :     const SfxPoolItem* pItem;
    1876         [ #  # ]:          0 :     sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_FIELD );
    1877                 :            : 
    1878         [ #  # ]:          0 :     for (sal_uInt32 n = 0; n < nMaxItems; ++n )
    1879                 :            :     {
    1880 [ #  # ][ #  # ]:          0 :         if( 0 == (pItem = GetAttrPool().GetItem2( RES_TXTATR_FIELD, n ) ))
    1881                 :          0 :             continue;
    1882                 :            : 
    1883                 :          0 :         SwFmtFld* pFmtFld = (SwFmtFld*)pItem;
    1884                 :          0 :         SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
    1885 [ #  # ][ #  # ]:          0 :         if( !pTxtFld || !pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
         [ #  # ][ #  # ]
    1886                 :          0 :             continue;
    1887                 :            : 
    1888                 :          0 :         SwField* pFld = pFmtFld->GetFld();
    1889                 :          0 :         sal_Bool bExpand = sal_False;
    1890                 :            : 
    1891   [ #  #  #  #  :          0 :         switch( pFld->GetTyp()->Which() )
                   #  # ]
    1892                 :            :         {
    1893                 :            :             case RES_DBFLD:
    1894 [ #  # ][ #  # ]:          0 :                 if( IsNameInArray( rOldNames, lcl_DBDataToString(((SwDBField*)pFld)->GetDBData())))
         [ #  # ][ #  # ]
    1895                 :            :                 {
    1896                 :          0 :                     SwDBFieldType* pOldTyp = (SwDBFieldType*)pFld->GetTyp();
    1897                 :            : 
    1898                 :            :                     SwDBFieldType* pTyp = (SwDBFieldType*)InsertFldType(
    1899 [ #  # ][ #  # ]:          0 :                             SwDBFieldType(this, pOldTyp->GetColumnName(), aNewDBData));
                 [ #  # ]
    1900                 :            : 
    1901         [ #  # ]:          0 :                     pFmtFld->RegisterToFieldType( *pTyp );
    1902         [ #  # ]:          0 :                     pFld->ChgTyp(pTyp);
    1903                 :            : 
    1904                 :          0 :                     ((SwDBField*)pFld)->ClearInitialized();
    1905         [ #  # ]:          0 :                     ((SwDBField*)pFld)->InitContent();
    1906                 :            : 
    1907                 :          0 :                     bExpand = sal_True;
    1908                 :            :                 }
    1909                 :          0 :                 break;
    1910                 :            : 
    1911                 :            :             case RES_DBSETNUMBERFLD:
    1912                 :            :             case RES_DBNAMEFLD:
    1913         [ #  # ]:          0 :                 if( IsNameInArray( rOldNames,
    1914 [ #  # ][ #  # ]:          0 :                                 lcl_DBDataToString(((SwDBNameInfField*)pFld)->GetRealDBData())))
                 [ #  # ]
    1915                 :            :                 {
    1916         [ #  # ]:          0 :                     ((SwDBNameInfField*)pFld)->SetDBData(aNewDBData);
    1917                 :          0 :                     bExpand = sal_True;
    1918                 :            :                 }
    1919                 :          0 :                 break;
    1920                 :            : 
    1921                 :            :             case RES_DBNUMSETFLD:
    1922                 :            :             case RES_DBNEXTSETFLD:
    1923         [ #  # ]:          0 :                 if( IsNameInArray( rOldNames,
    1924 [ #  # ][ #  # ]:          0 :                                 lcl_DBDataToString(((SwDBNameInfField*)pFld)->GetRealDBData())))
                 [ #  # ]
    1925                 :            :                 {
    1926         [ #  # ]:          0 :                     ((SwDBNameInfField*)pFld)->SetDBData(aNewDBData);
    1927                 :          0 :                     bExpand = sal_True;
    1928                 :            :                 }
    1929                 :            :                 // no break;
    1930                 :            :             case RES_HIDDENTXTFLD:
    1931                 :            :             case RES_HIDDENPARAFLD:
    1932 [ #  # ][ #  # ]:          0 :                 sFormel = pFld->GetPar1();
    1933         [ #  # ]:          0 :                 ReplaceUsedDBs( rOldNames, rNewName, sFormel);
    1934 [ #  # ][ #  # ]:          0 :                 pFld->SetPar1( sFormel );
    1935                 :          0 :                 bExpand = sal_True;
    1936                 :          0 :                 break;
    1937                 :            : 
    1938                 :            :             case RES_SETEXPFLD:
    1939                 :            :             case RES_GETEXPFLD:
    1940                 :            :             case RES_TABLEFLD:
    1941 [ #  # ][ #  # ]:          0 :                 sFormel = pFld->GetFormula();
                 [ #  # ]
    1942         [ #  # ]:          0 :                 ReplaceUsedDBs( rOldNames, rNewName, sFormel);
    1943 [ #  # ][ #  # ]:          0 :                 pFld->SetPar2( sFormel );
    1944                 :          0 :                 bExpand = sal_True;
    1945                 :          0 :                 break;
    1946                 :            :         }
    1947                 :            : 
    1948         [ #  # ]:          0 :         if (bExpand)
    1949         [ #  # ]:          0 :             pTxtFld->ExpandAlways();
    1950                 :            :     }
    1951 [ #  # ][ #  # ]:          0 :     SetModified();
    1952                 :          0 : }
    1953                 :            : 
    1954                 :          0 : void SwDoc::ReplaceUsedDBs( const std::vector<String>& rUsedDBNames,
    1955                 :            :                             const String& rNewName, String& rFormel )
    1956                 :            : {
    1957         [ #  # ]:          0 :     const CharClass& rCC = GetAppCharClass();
    1958         [ #  # ]:          0 :     String  sFormel(rFormel);
    1959         [ #  # ]:          0 :     String  sNewName( rNewName );
    1960         [ #  # ]:          0 :     sNewName.SearchAndReplace( DB_DELIM, '.');
    1961                 :            :     //the command type is not part of the condition
    1962 [ #  # ][ #  # ]:          0 :     sNewName = sNewName.GetToken(0, DB_DELIM);
                 [ #  # ]
    1963         [ #  # ]:          0 :     String sUpperNewNm( sNewName );
    1964                 :            : 
    1965         [ #  # ]:          0 :     for( sal_uInt16 i = 0; i < rUsedDBNames.size(); ++i )
    1966                 :            :     {
    1967 [ #  # ][ #  # ]:          0 :         String  sDBName( rUsedDBNames[i] );
    1968                 :            : 
    1969         [ #  # ]:          0 :         sDBName.SearchAndReplace( DB_DELIM, '.');
    1970                 :            :         //cut off command type
    1971 [ #  # ][ #  # ]:          0 :         sDBName = sDBName.GetToken(0, DB_DELIM);
                 [ #  # ]
    1972 [ #  # ][ #  # ]:          0 :         if( !sDBName.Equals( sUpperNewNm ))
    1973                 :            :         {
    1974                 :          0 :             xub_StrLen nPos = 0;
    1975                 :            : 
    1976 [ #  # ][ #  # ]:          0 :             while ((nPos = sFormel.Search(sDBName, nPos)) != STRING_NOTFOUND)
    1977                 :            :             {
    1978 [ #  # ][ #  # ]:          0 :                 if( sFormel.GetChar( nPos + sDBName.Len() ) == '.' &&
         [ #  # ][ #  # ]
    1979         [ #  # ]:          0 :                     (!nPos || !rCC.isLetterNumeric( sFormel, nPos - 1 )))
    1980                 :            :                 {
    1981         [ #  # ]:          0 :                     rFormel.Erase( nPos, sDBName.Len() );
    1982         [ #  # ]:          0 :                     rFormel.Insert( sNewName, nPos );
    1983                 :            :                     //prevent re-searching - this is useless and provokes
    1984                 :            :                     //endless loops when names containing each other and numbers are exchanged
    1985                 :            :                     //e.g.: old ?12345.12345  new: i12345.12345
    1986                 :          0 :                     nPos = nPos + sNewName.Len();
    1987         [ #  # ]:          0 :                     sFormel = rFormel;
    1988                 :            :                 }
    1989                 :            :             }
    1990                 :            :         }
    1991 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
    1992                 :          0 : }
    1993                 :            : 
    1994                 :          0 : sal_Bool SwDoc::IsNameInArray( const std::vector<String>& rArr, const String& rName )
    1995                 :            : {
    1996                 :            : #ifdef UNX
    1997         [ #  # ]:          0 :     for( sal_uInt16 i = 0; i < rArr.size(); ++i )
    1998         [ #  # ]:          0 :         if( rName == rArr[ i ] )
    1999                 :          0 :             return sal_True;
    2000                 :            : #else
    2001                 :            :     const ::utl::TransliterationWrapper& rSCmp = GetAppCmpStrIgnore();
    2002                 :            :     for( sal_uInt16 i = 0; i < rArr.size(); ++i )
    2003                 :            :         if( rSCmp.isEqual( rName, rArr[ i] ))
    2004                 :            :             return sal_True;
    2005                 :            : #endif
    2006                 :          0 :     return sal_False;
    2007                 :            : }
    2008                 :            : 
    2009                 :         17 : void SwDoc::SetFixFields( bool bOnlyTimeDate, const DateTime* pNewDateTime )
    2010                 :            : {
    2011         [ +  - ]:         17 :     sal_Bool bIsModified = IsModified();
    2012                 :            : 
    2013                 :            :     sal_uLong nDate, nTime;
    2014         [ -  + ]:         17 :     if( pNewDateTime )
    2015                 :            :     {
    2016                 :          0 :         nDate = pNewDateTime->GetDate();
    2017                 :          0 :         nTime = pNewDateTime->GetTime();
    2018                 :            :     }
    2019                 :            :     else
    2020                 :            :     {
    2021         [ +  - ]:         17 :         nDate = Date( Date::SYSTEM ).GetDate();
    2022         [ +  - ]:         17 :         nTime = Time( Time::SYSTEM ).GetTime();
    2023                 :            :     }
    2024                 :            : 
    2025                 :            :     sal_uInt16 aTypes[5] = {
    2026                 :            :         /*0*/   RES_DOCINFOFLD,
    2027                 :            :         /*1*/   RES_AUTHORFLD,
    2028                 :            :         /*2*/   RES_EXTUSERFLD,
    2029                 :            :         /*3*/   RES_FILENAMEFLD,
    2030                 :         17 :         /*4*/   RES_DATETIMEFLD };  // MUST be at the end!
    2031                 :            : 
    2032         [ -  + ]:         17 :     sal_uInt16 nStt = bOnlyTimeDate ? 4 : 0;
    2033                 :            : 
    2034         [ +  + ]:        102 :     for( ; nStt < 5; ++nStt )
    2035                 :            :     {
    2036         [ +  - ]:         85 :         SwFieldType* pFldType = GetSysFldType( aTypes[ nStt ] );
    2037         [ +  - ]:         85 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
    2038 [ +  - ][ +  - ]:         89 :         for( SwFmtFld* pFld = aIter.First(); pFld; pFld = aIter.Next() )
                 [ +  + ]
    2039                 :            :         {
    2040 [ +  - ][ +  - ]:          4 :             if( pFld && pFld->GetTxtFld() )
                 [ +  - ]
    2041                 :            :             {
    2042                 :          4 :                 sal_Bool bChgd = sal_False;
    2043   [ -  -  -  +  :          4 :                 switch( aTypes[ nStt ] )
                   -  - ]
    2044                 :            :                 {
    2045                 :            :                 case RES_DOCINFOFLD:
    2046 [ #  # ][ #  # ]:          0 :                     if( ((SwDocInfoField*)pFld->GetFld())->IsFixed() )
    2047                 :            :                     {
    2048                 :          0 :                         bChgd = sal_True;
    2049                 :          0 :                         SwDocInfoField* pDocInfFld = (SwDocInfoField*)pFld->GetFld();
    2050                 :            :                         pDocInfFld->SetExpansion( ((SwDocInfoFieldType*)
    2051                 :          0 :                                     pDocInfFld->GetTyp())->Expand(
    2052         [ #  # ]:          0 :                                         pDocInfFld->GetSubType(),
    2053                 :            :                                         pDocInfFld->GetFormat(),
    2054                 :          0 :                                         pDocInfFld->GetLanguage(),
    2055 [ #  # ][ #  # ]:          0 :                                         pDocInfFld->GetName() ) );
                 [ #  # ]
           [ #  #  #  # ]
    2056                 :            :                     }
    2057                 :          0 :                     break;
    2058                 :            : 
    2059                 :            :                 case RES_AUTHORFLD:
    2060 [ #  # ][ #  # ]:          0 :                     if( ((SwAuthorField*)pFld->GetFld())->IsFixed() )
    2061                 :            :                     {
    2062                 :          0 :                         bChgd = sal_True;
    2063                 :          0 :                         SwAuthorField* pAuthorFld = (SwAuthorField*)pFld->GetFld();
    2064                 :            :                         pAuthorFld->SetExpansion( ((SwAuthorFieldType*)
    2065                 :          0 :                                     pAuthorFld->GetTyp())->Expand(
    2066 [ #  # ][ #  # ]:          0 :                                                 pAuthorFld->GetFormat() ) );
                 [ #  # ]
    2067                 :            :                     }
    2068                 :          0 :                     break;
    2069                 :            : 
    2070                 :            :                 case RES_EXTUSERFLD:
    2071 [ #  # ][ #  # ]:          0 :                     if( ((SwExtUserField*)pFld->GetFld())->IsFixed() )
    2072                 :            :                     {
    2073                 :          0 :                         bChgd = sal_True;
    2074                 :          0 :                         SwExtUserField* pExtUserFld = (SwExtUserField*)pFld->GetFld();
    2075                 :            :                         pExtUserFld->SetExpansion( ((SwExtUserFieldType*)
    2076                 :          0 :                                     pExtUserFld->GetTyp())->Expand(
    2077         [ #  # ]:          0 :                                             pExtUserFld->GetSubType(),
    2078 [ #  # ][ #  # ]:          0 :                                             pExtUserFld->GetFormat()));
                 [ #  # ]
    2079                 :            :                     }
    2080                 :          0 :                     break;
    2081                 :            : 
    2082                 :            :                 case RES_DATETIMEFLD:
    2083 [ +  - ][ -  + ]:          4 :                     if( ((SwDateTimeField*)pFld->GetFld())->IsFixed() )
    2084                 :            :                     {
    2085                 :          0 :                         bChgd = sal_True;
    2086                 :          0 :                         ((SwDateTimeField*)pFld->GetFld())->SetDateTime(
    2087   [ #  #  #  # ]:          0 :                                                     DateTime(Date(nDate), Time(nTime)) );
    2088                 :            :                     }
    2089                 :          4 :                     break;
    2090                 :            : 
    2091                 :            :                 case RES_FILENAMEFLD:
    2092 [ #  # ][ #  # ]:          0 :                     if( ((SwFileNameField*)pFld->GetFld())->IsFixed() )
    2093                 :            :                     {
    2094                 :          0 :                         bChgd = sal_True;
    2095                 :            :                         SwFileNameField* pFileNameFld =
    2096                 :          0 :                             (SwFileNameField*)pFld->GetFld();
    2097                 :            :                         pFileNameFld->SetExpansion( ((SwFileNameFieldType*)
    2098                 :          0 :                                     pFileNameFld->GetTyp())->Expand(
    2099 [ #  # ][ #  # ]:          0 :                                             pFileNameFld->GetFormat() ) );
                 [ #  # ]
    2100                 :            :                     }
    2101                 :          0 :                     break;
    2102                 :            :                 }
    2103                 :            : 
    2104                 :            :                 // Trigger formatting
    2105         [ -  + ]:          4 :                 if( bChgd )
    2106         [ #  # ]:          0 :                     pFld->ModifyNotification( 0, 0 );
    2107                 :            :             }
    2108                 :            :         }
    2109         [ +  - ]:         85 :     }
    2110                 :            : 
    2111         [ +  + ]:         17 :     if( !bIsModified )
    2112         [ +  - ]:          5 :         ResetModified();
    2113                 :         17 : }
    2114                 :            : 
    2115                 :      12143 : bool SwDoc::SetFieldsDirty( bool b, const SwNode* pChk, sal_uLong nLen )
    2116                 :            : {
    2117                 :            :     // See if the supplied nodes actually contain fields.
    2118                 :            :     // If they don't, the flag doesn't need to be changed.
    2119                 :      12143 :     sal_Bool bFldsFnd = sal_False;
    2120 [ +  + ][ +  + ]:      12143 :     if( b && pChk && !GetUpdtFlds().IsFieldsDirty() && !IsInDtor()
         [ +  + ][ +  - ]
                 [ +  + ]
    2121                 :            :         // ?? what's up with Undo, this is also wanted there!
    2122                 :            :         /*&& &pChk->GetNodes() == &GetNodes()*/ )
    2123                 :            :     {
    2124                 :      10765 :         b = sal_False;
    2125         [ -  + ]:      10765 :         if( !nLen )
    2126                 :          0 :             ++nLen;
    2127                 :      10765 :         sal_uLong nStt = pChk->GetIndex();
    2128                 :      10765 :         const SwNodes& rNds = pChk->GetNodes();
    2129         [ +  + ]:      21514 :         while( nLen-- )
    2130                 :            :         {
    2131                 :      10783 :             const SwTxtNode* pTNd = rNds[ nStt++ ]->GetTxtNode();
    2132         [ +  + ]:      10783 :             if( pTNd )
    2133                 :            :             {
    2134         [ -  + ]:      10779 :                 if( pTNd->GetAttrOutlineLevel() != 0 )
    2135                 :            :                     // update chapter fields
    2136                 :          0 :                     b = sal_True;
    2137 [ +  + ][ +  - ]:      10779 :                 else if( pTNd->GetpSwpHints() && pTNd->GetSwpHints().Count() )
                 [ +  + ]
    2138         [ +  + ]:       1280 :                     for( sal_uInt16 n = 0, nEnd = pTNd->GetSwpHints().Count();
    2139                 :            :                             n < nEnd; ++n )
    2140                 :            :                     {
    2141                 :        738 :                         const SwTxtAttr* pAttr = pTNd->GetSwpHints()[ n ];
    2142         [ +  + ]:        738 :                         if( RES_TXTATR_FIELD == pAttr->Which() )
    2143                 :            :                         {
    2144                 :         34 :                             b = sal_True;
    2145                 :         34 :                             break;
    2146                 :            :                         }
    2147                 :            :                     }
    2148                 :            : 
    2149         [ +  + ]:      10779 :                 if( b )
    2150                 :         34 :                     break;
    2151                 :            :             }
    2152                 :            :         }
    2153                 :      10765 :         bFldsFnd = b;
    2154                 :            :     }
    2155                 :      12143 :     GetUpdtFlds().SetFieldsDirty( b );
    2156                 :      12143 :     return bFldsFnd;
    2157                 :            : }
    2158                 :            : 
    2159                 :          0 : void SwDoc::ChangeAuthorityData( const SwAuthEntry* pNewData )
    2160                 :            : {
    2161                 :          0 :     const sal_uInt16 nSize = pFldTypes->size();
    2162                 :            : 
    2163         [ #  # ]:          0 :     for( sal_uInt16 i = INIT_FLDTYPES; i < nSize; ++i )
    2164                 :            :     {
    2165                 :          0 :         SwFieldType* pFldType = (*pFldTypes)[i];
    2166         [ #  # ]:          0 :         if( RES_AUTHORITY  == pFldType->Which() )
    2167                 :            :         {
    2168                 :          0 :             SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)pFldType;
    2169                 :          0 :             pAuthType->ChangeEntryContent(pNewData);
    2170                 :          0 :             break;
    2171                 :            :         }
    2172                 :            :     }
    2173                 :            : 
    2174                 :          0 : }
    2175                 :            : 
    2176                 :          0 : void SwDocUpdtFld::InsDelFldInFldLst( sal_Bool bIns, const SwTxtFld& rFld )
    2177                 :            : {
    2178                 :          0 :     sal_uInt16 nWhich = rFld.GetFld().GetFld()->GetTyp()->Which();
    2179         [ #  # ]:          0 :     switch( nWhich )
    2180                 :            :     {
    2181                 :            :     case RES_DBFLD:
    2182                 :            :     case RES_SETEXPFLD:
    2183                 :            :     case RES_HIDDENPARAFLD:
    2184                 :            :     case RES_HIDDENTXTFLD:
    2185                 :            :     case RES_DBNUMSETFLD:
    2186                 :            :     case RES_DBNEXTSETFLD:
    2187                 :            :     case RES_DBSETNUMBERFLD:
    2188                 :            :     case RES_GETEXPFLD:
    2189                 :          0 :         break;          // these have to be added/removed!
    2190                 :            : 
    2191                 :            :     default:
    2192                 :          0 :         return;
    2193                 :            :     }
    2194                 :            : 
    2195                 :          0 :     SetFieldsDirty( sal_True );
    2196         [ #  # ]:          0 :     if( !pFldSortLst )
    2197                 :            :     {
    2198         [ #  # ]:          0 :         if( !bIns )             // if list is present and deleted
    2199                 :          0 :             return;             // don't do a thing
    2200         [ #  # ]:          0 :         pFldSortLst = new _SetGetExpFlds;
    2201                 :            :     }
    2202                 :            : 
    2203         [ #  # ]:          0 :     if( bIns )      // insert anew:
    2204                 :          0 :         GetBodyNode( rFld, nWhich );
    2205                 :            :     else
    2206                 :            :     {
    2207                 :            :         // look up via the pTxtFld pointer. It is a sorted list, but it's sorted by node
    2208                 :            :         // position. Until this is found, the search for the pointer is already done.
    2209         [ #  # ]:          0 :         for( sal_uInt16 n = 0; n < pFldSortLst->size(); ++n )
    2210         [ #  # ]:          0 :             if( &rFld == (*pFldSortLst)[ n ]->GetPointer() )
    2211                 :            :             {
    2212                 :          0 :                 delete (*pFldSortLst)[n];
    2213                 :          0 :                 pFldSortLst->erase(n);
    2214                 :          0 :                 n--; // one field can occur multiple times
    2215                 :            :             }
    2216                 :            :     }
    2217                 :            : }
    2218                 :            : 
    2219                 :        105 : void SwDocUpdtFld::MakeFldList( SwDoc& rDoc, int bAll, int eGetMode )
    2220                 :            : {
    2221 [ +  + ][ +  + ]:        117 :     if( !pFldSortLst || bAll || !( eGetMode & nFldLstGetMode ) ||
           [ +  -  -  + ]
                 [ +  + ]
    2222                 :         12 :         rDoc.GetNodes().Count() != nNodes )
    2223                 :         93 :         _MakeFldList( rDoc, eGetMode );
    2224                 :        105 : }
    2225                 :            : 
    2226                 :         93 : void SwDocUpdtFld::_MakeFldList( SwDoc& rDoc, int eGetMode )
    2227                 :            : {
    2228                 :            :     // new version: walk all fields of the attribute pool
    2229 [ +  + ][ +  - ]:         93 :     delete pFldSortLst;
    2230 [ +  - ][ +  - ]:         93 :     pFldSortLst = new _SetGetExpFlds;
    2231                 :            : 
    2232                 :            :     /// consider and unhide sections
    2233                 :            :     ///     with hide condition, only in mode GETFLD_ALL (<eGetMode == GETFLD_ALL>)
    2234                 :            :     ///     notes by OD:
    2235                 :            :     ///         eGetMode == GETFLD_CALC in call from methods SwDoc::FldsToCalc
    2236                 :            :     ///         eGetMode == GETFLD_EXPAND in call from method SwDoc::FldsToExpand
    2237                 :            :     ///         eGetMode == GETFLD_ALL in call from method SwDoc::UpdateExpFlds
    2238                 :            :     ///         I figured out that hidden section only have to be shown,
    2239                 :            :     ///         if fields have updated (call by SwDoc::UpdateExpFlds) and thus
    2240                 :            :     ///         the hide conditions of section have to be updated.
    2241                 :            :     ///         For correct updating the hide condition of a section, its position
    2242                 :            :     ///         have to be known in order to insert the hide condition as a new
    2243                 :            :     ///         expression field into the sorted field list (<pFldSortLst>).
    2244         [ +  - ]:         93 :     if ( eGetMode == GETFLD_ALL )
    2245                 :            :     // Collect the sections first. Supply sections that are hidden by condition
    2246                 :            :     // with frames so that the contained fields are sorted properly.
    2247                 :            :     {
    2248                 :            :         // In order for the frames to be created the right way, they have to be expanded
    2249                 :            :         // from top to bottom
    2250         [ +  - ]:         93 :         std::vector<sal_uLong> aTmpArr;
    2251                 :         93 :         SwSectionFmts& rArr = rDoc.GetSections();
    2252                 :            :         SwSectionNode* pSectNd;
    2253                 :         93 :         sal_uInt16 nArrStt = 0;
    2254         [ +  - ]:         93 :         sal_uLong nSttCntnt = rDoc.GetNodes().GetEndOfExtras().GetIndex();
    2255                 :            : 
    2256         [ +  + ]:        114 :         for (sal_uInt16 n = rArr.size(); n; )
    2257                 :            :         {
    2258 [ +  - ][ +  - ]:         21 :             SwSection* pSect = rArr[ --n ]->GetSection();
    2259 [ +  - ][ +  + ]:         30 :             if( pSect && pSect->IsHidden() && pSect->GetCondition().Len() &&
           [ +  +  +  - ]
         [ +  - ][ +  + ]
    2260                 :          9 :                 0 != ( pSectNd = pSect->GetFmt()->GetSectionNode() ))
    2261                 :            :             {
    2262                 :          9 :                 sal_uLong nIdx = pSectNd->GetIndex();
    2263         [ +  - ]:          9 :                 aTmpArr.push_back( nIdx );
    2264         [ -  + ]:          9 :                 if( nIdx < nSttCntnt )
    2265                 :          9 :                     ++nArrStt;
    2266                 :            :             }
    2267                 :            :         }
    2268         [ +  - ]:         93 :         std::sort(aTmpArr.begin(), aTmpArr.end());
    2269                 :            : 
    2270                 :            :         // Display all first so that we have frames. The BodyAnchor is defined by that.
    2271                 :            :         // First the ContentArea, then the special areas!
    2272         [ +  + ]:        102 :         for (sal_uInt16 n = nArrStt; n < aTmpArr.size(); ++n)
    2273                 :            :         {
    2274 [ +  - ][ +  - ]:          9 :             pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode();
                 [ +  - ]
    2275                 :            :             OSL_ENSURE( pSectNd, "Where is my SectionNode" );
    2276         [ +  - ]:          9 :             pSectNd->GetSection().SetCondHidden( sal_False );
    2277                 :            :         }
    2278         [ -  + ]:         93 :         for (sal_uInt16 n = 0; n < nArrStt; ++n)
    2279                 :            :         {
    2280 [ #  # ][ #  # ]:          0 :             pSectNd = rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode();
                 [ #  # ]
    2281                 :            :             OSL_ENSURE( pSectNd, "Where is my SectionNode" );
    2282         [ #  # ]:          0 :             pSectNd->GetSection().SetCondHidden( sal_False );
    2283                 :            :         }
    2284                 :            : 
    2285                 :            :         // add all to the list so that they are sorted
    2286         [ +  + ]:        102 :         for (sal_uInt16 n = 0; n < aTmpArr.size(); ++n)
    2287                 :            :         {
    2288 [ +  - ][ +  - ]:          9 :             GetBodyNode( *rDoc.GetNodes()[ aTmpArr[ n ] ]->GetSectionNode() );
         [ +  - ][ +  - ]
    2289                 :         93 :         }
    2290                 :            :     }
    2291                 :            : 
    2292                 :         93 :     rtl::OUString sTrue("TRUE"), sFalse("FALSE");
    2293                 :            : 
    2294                 :         93 :     sal_Bool bIsDBMgr = 0 != rDoc.GetNewDBMgr();
    2295                 :            :     sal_uInt16 nWhich, n;
    2296                 :         93 :     const rtl::OUString* pFormel = 0;
    2297                 :            :     const SfxPoolItem* pItem;
    2298         [ +  - ]:         93 :     sal_uInt32 nMaxItems = rDoc.GetAttrPool().GetItemCount2( RES_TXTATR_FIELD );
    2299         [ +  + ]:        427 :     for( n = 0; n < nMaxItems; ++n )
    2300                 :            :     {
    2301 [ +  - ][ +  + ]:        334 :         if( 0 == (pItem = rDoc.GetAttrPool().GetItem2( RES_TXTATR_FIELD, n )) )
    2302                 :         83 :             continue;
    2303                 :            : 
    2304                 :        251 :         const SwFmtFld* pFmtFld = (SwFmtFld*)pItem;
    2305                 :        251 :         const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
    2306 [ +  - ][ -  + ]:        251 :         if( !pTxtFld || !pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
         [ +  + ][ +  + ]
    2307                 :          6 :             continue;
    2308                 :            : 
    2309                 :        245 :         const SwField* pFld = pFmtFld->GetFld();
    2310   [ -  -  -  -  :        245 :         switch( nWhich = pFld->GetTyp()->Which() )
             -  -  -  + ]
    2311                 :            :         {
    2312                 :            :             case RES_DBSETNUMBERFLD:
    2313                 :            :             case RES_GETEXPFLD:
    2314         [ #  # ]:          0 :                 if( GETFLD_ALL == eGetMode )
    2315                 :          0 :                     pFormel = &sTrue;
    2316                 :          0 :                 break;
    2317                 :            : 
    2318                 :            :             case RES_DBFLD:
    2319         [ #  # ]:          0 :                 if( GETFLD_EXPAND & eGetMode )
    2320                 :          0 :                     pFormel = &sTrue;
    2321                 :          0 :                 break;
    2322                 :            : 
    2323                 :            :             case RES_SETEXPFLD:
    2324 [ #  # ][ #  # ]:          0 :                 if ( !(eGetMode == GETFLD_EXPAND) ||
                 [ #  # ]
    2325         [ #  # ]:          0 :                      (nsSwGetSetExpType::GSE_STRING & pFld->GetSubType()) )
    2326                 :            :                 {
    2327                 :          0 :                     pFormel = &sTrue;
    2328                 :            :                 }
    2329                 :          0 :                 break;
    2330                 :            : 
    2331                 :            :             case RES_HIDDENPARAFLD:
    2332         [ #  # ]:          0 :                 if( GETFLD_ALL == eGetMode )
    2333                 :            :                 {
    2334         [ #  # ]:          0 :                     pFormel = &pFld->GetPar1();
    2335 [ #  # ][ #  # ]:          0 :                     if (pFormel->isEmpty() || pFormel->equals(sFalse))
                 [ #  # ]
    2336                 :          0 :                         ((SwHiddenParaField*)pFld)->SetHidden( sal_False );
    2337         [ #  # ]:          0 :                     else if (pFormel->equals(sTrue))
    2338                 :          0 :                         ((SwHiddenParaField*)pFld)->SetHidden( sal_True );
    2339                 :            :                     else
    2340                 :          0 :                         break;
    2341                 :            : 
    2342                 :          0 :                     pFormel = 0;
    2343                 :            :                     // trigger formatting
    2344         [ #  # ]:          0 :                     ((SwFmtFld*)pFmtFld)->ModifyNotification( 0, 0 );
    2345                 :            :                 }
    2346                 :          0 :                 break;
    2347                 :            : 
    2348                 :            :             case RES_HIDDENTXTFLD:
    2349         [ #  # ]:          0 :                 if( GETFLD_ALL == eGetMode )
    2350                 :            :                 {
    2351         [ #  # ]:          0 :                     pFormel = &pFld->GetPar1();
    2352 [ #  # ][ #  # ]:          0 :                     if (pFormel->isEmpty() || pFormel->equals(sFalse))
                 [ #  # ]
    2353                 :          0 :                         ((SwHiddenTxtField*)pFld)->SetValue( sal_True );
    2354         [ #  # ]:          0 :                     else if (pFormel->equals(sTrue))
    2355                 :          0 :                         ((SwHiddenTxtField*)pFld)->SetValue( sal_False );
    2356                 :            :                     else
    2357                 :          0 :                         break;
    2358                 :            : 
    2359                 :          0 :                     pFormel = 0;
    2360                 :            : 
    2361                 :            :                     // evaluate field
    2362         [ #  # ]:          0 :                     ((SwHiddenTxtField*)pFld)->Evaluate(&rDoc);
    2363                 :            :                     // trigger formatting
    2364         [ #  # ]:          0 :                     ((SwFmtFld*)pFmtFld)->ModifyNotification( 0, 0 );
    2365                 :            :                 }
    2366                 :          0 :                 break;
    2367                 :            : 
    2368                 :            :             case RES_DBNUMSETFLD:
    2369                 :            :             {
    2370         [ #  # ]:          0 :                 SwDBData aDBData(((SwDBNumSetField*)pFld)->GetDBData(&rDoc));
    2371                 :            : 
    2372 [ #  # ][ #  # ]:          0 :                 if (
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
    2373 [ #  # ][ #  # ]:          0 :                      (bIsDBMgr && rDoc.GetNewDBMgr()->OpenDataSource(aDBData.sDataSource, aDBData.sCommand)) &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    2374                 :          0 :                      (GETFLD_ALL == eGetMode || (GETFLD_CALC & eGetMode && ((SwDBNumSetField*)pFld)->IsCondValid()))
    2375                 :            :                    )
    2376                 :            :                 {
    2377         [ #  # ]:          0 :                     pFormel = &pFld->GetPar1();
    2378                 :          0 :                 }
    2379                 :            :             }
    2380                 :          0 :             break;
    2381                 :            :             case RES_DBNEXTSETFLD:
    2382                 :            :             {
    2383         [ #  # ]:          0 :                 SwDBData aDBData(((SwDBNextSetField*)pFld)->GetDBData(&rDoc));
    2384                 :            : 
    2385 [ #  # ][ #  # ]:          0 :                 if (
                 [ #  # ]
           [ #  #  #  # ]
                 [ #  # ]
    2386 [ #  # ][ #  # ]:          0 :                      (bIsDBMgr && rDoc.GetNewDBMgr()->OpenDataSource(aDBData.sDataSource, aDBData.sCommand)) &&
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
           [ #  #  #  # ]
    2387                 :          0 :                      (GETFLD_ALL == eGetMode || (GETFLD_CALC & eGetMode && ((SwDBNextSetField*)pFld)->IsCondValid()))
    2388                 :            :                    )
    2389                 :            :                 {
    2390         [ #  # ]:          0 :                     pFormel = &pFld->GetPar1();
    2391                 :          0 :                 }
    2392                 :            :             }
    2393                 :          0 :             break;
    2394                 :            :         }
    2395                 :            : 
    2396 [ -  + ][ #  # ]:        245 :         if (pFormel && !pFormel->isEmpty())
                 [ -  + ]
    2397                 :            :         {
    2398         [ #  # ]:          0 :             GetBodyNode( *pTxtFld, nWhich );
    2399                 :          0 :             pFormel = 0;
    2400                 :            :         }
    2401                 :            :     }
    2402                 :         93 :     nFldLstGetMode = static_cast<sal_uInt8>( eGetMode );
    2403         [ +  - ]:         93 :     nNodes = rDoc.GetNodes().Count();
    2404                 :         93 : }
    2405                 :            : 
    2406                 :          0 : void SwDocUpdtFld::GetBodyNode( const SwTxtFld& rTFld, sal_uInt16 nFldWhich )
    2407                 :            : {
    2408                 :          0 :     const SwTxtNode& rTxtNd = rTFld.GetTxtNode();
    2409                 :          0 :     const SwDoc& rDoc = *rTxtNd.GetDoc();
    2410                 :            : 
    2411                 :            :     // always the first! (in tab headline, header-/footer)
    2412                 :          0 :     Point aPt;
    2413 [ #  # ][ #  # ]:          0 :     const SwCntntFrm* pFrm = rTxtNd.getLayoutFrm( rDoc.GetCurrentLayout(), &aPt, 0, sal_False );
    2414                 :            : 
    2415                 :          0 :     _SetGetExpFld* pNew = NULL;
    2416                 :          0 :     sal_Bool bIsInBody = sal_False;
    2417                 :            : 
    2418 [ #  # ][ #  # ]:          0 :     if( !pFrm || pFrm->IsInDocBody() )
         [ #  # ][ #  # ]
    2419                 :            :     {
    2420                 :            :         // create index to determine the TextNode
    2421         [ #  # ]:          0 :         SwNodeIndex aIdx( rTxtNd );
    2422         [ #  # ]:          0 :         bIsInBody = rDoc.GetNodes().GetEndOfExtras().GetIndex() < aIdx.GetIndex();
    2423                 :            : 
    2424                 :            :         // We don't want to update fields in redlines, or those
    2425                 :            :         // in frames whose anchor is in redline. However, we do want to update
    2426                 :            :         // fields in hidden sections. So: In order to be updated, a field 1)
    2427                 :            :         // must have a frame, or 2) it must be in the document body.
    2428 [ #  # ][ #  # ]:          0 :         if( (pFrm != NULL) || bIsInBody )
    2429 [ #  # ][ #  # ]:          0 :             pNew = new _SetGetExpFld( aIdx, &rTFld );
    2430                 :            :     }
    2431                 :            :     else
    2432                 :            :     {
    2433                 :            :         // create index to determine the TextNode
    2434 [ #  # ][ #  # ]:          0 :         SwPosition aPos( rDoc.GetNodes().GetEndOfPostIts() );
    2435         [ #  # ]:          0 :         bool const bResult = GetBodyTxtNode( rDoc, aPos, *pFrm );
    2436                 :            :         OSL_ENSURE(bResult, "where is the Field");
    2437                 :            :         (void) bResult; // unused in non-debug
    2438 [ #  # ][ #  # ]:          0 :         pNew = new _SetGetExpFld( aPos.nNode, &rTFld, &aPos.nContent );
    2439                 :            :     }
    2440                 :            : 
    2441                 :            :     // always set the BodyTxtFlag in GetExp or DB fields
    2442         [ #  # ]:          0 :     if( RES_GETEXPFLD == nFldWhich )
    2443                 :            :     {
    2444                 :          0 :         SwGetExpField* pGetFld = (SwGetExpField*)rTFld.GetFld().GetFld();
    2445                 :          0 :         pGetFld->ChgBodyTxtFlag( bIsInBody );
    2446                 :            :     }
    2447         [ #  # ]:          0 :     else if( RES_DBFLD == nFldWhich )
    2448                 :            :     {
    2449                 :          0 :         SwDBField* pDBFld = (SwDBField*)rTFld.GetFld().GetFld();
    2450                 :          0 :         pDBFld->ChgBodyTxtFlag( bIsInBody );
    2451                 :            :     }
    2452                 :            : 
    2453         [ #  # ]:          0 :     if( pNew != NULL )
    2454 [ #  # ][ #  # ]:          0 :         if( !pFldSortLst->insert( pNew ).second )
    2455                 :          0 :             delete pNew;
    2456                 :          0 : }
    2457                 :            : 
    2458                 :          9 : void SwDocUpdtFld::GetBodyNode( const SwSectionNode& rSectNd )
    2459                 :            : {
    2460                 :          9 :     const SwDoc& rDoc = *rSectNd.GetDoc();
    2461                 :          9 :     _SetGetExpFld* pNew = 0;
    2462                 :            : 
    2463 [ -  + ][ +  - ]:          9 :     if( rSectNd.GetIndex() < rDoc.GetNodes().GetEndOfExtras().GetIndex() )
    2464                 :            :     {
    2465                 :            :         do {            // middle check loop
    2466                 :            : 
    2467                 :            :             // we need to get the anchor first
    2468                 :            :             // create index to determine the TextNode
    2469         [ #  # ]:          0 :             SwPosition aPos( rSectNd );
    2470 [ #  # ][ #  # ]:          0 :             SwCntntNode* pCNd = rDoc.GetNodes().GoNext( &aPos.nNode ); // to the next ContentNode
    2471                 :            : 
    2472 [ #  # ][ #  # ]:          0 :             if( !pCNd || !pCNd->IsTxtNode() )
                 [ #  # ]
    2473                 :            :                 break;
    2474                 :            : 
    2475                 :            :             // always the first! (in tab headline, header-/footer)
    2476                 :          0 :             Point aPt;
    2477 [ #  # ][ #  # ]:          0 :             const SwCntntFrm* pFrm = pCNd->getLayoutFrm( rDoc.GetCurrentLayout(), &aPt, 0, sal_False );
    2478         [ #  # ]:          0 :             if( !pFrm )
    2479                 :            :                 break;
    2480                 :            : 
    2481         [ #  # ]:          0 :             bool const bResult = GetBodyTxtNode( rDoc, aPos, *pFrm );
    2482                 :            :             OSL_ENSURE(bResult, "where is the Field");
    2483                 :            :             (void) bResult; // unused in non-debug
    2484 [ #  # ][ #  # ]:          0 :             pNew = new _SetGetExpFld( rSectNd, &aPos );
                 [ #  # ]
    2485                 :            : 
    2486                 :            :         } while( sal_False );
    2487                 :            :     }
    2488                 :            : 
    2489         [ +  - ]:          9 :     if( !pNew )
    2490         [ +  - ]:          9 :         pNew = new _SetGetExpFld( rSectNd );
    2491                 :            : 
    2492 [ +  - ][ -  + ]:          9 :     if( !pFldSortLst->insert( pNew ).second )
    2493                 :          0 :         delete pNew;
    2494                 :          9 : }
    2495                 :            : 
    2496                 :         57 : void SwDocUpdtFld::InsertFldType( const SwFieldType& rType )
    2497                 :            : {
    2498         [ +  - ]:         57 :     String sFldName;
    2499      [ +  +  - ]:         57 :     switch( rType.Which() )
    2500                 :            :     {
    2501                 :            :     case RES_USERFLD :
    2502 [ +  - ][ +  - ]:         54 :         sFldName = ((SwUserFieldType&)rType).GetName();
    2503                 :         54 :         break;
    2504                 :            :     case RES_SETEXPFLD:
    2505 [ +  - ][ +  - ]:          3 :         sFldName = ((SwSetExpFieldType&)rType).GetName();
    2506                 :          3 :         break;
    2507                 :            :     default:
    2508                 :            :         OSL_ENSURE( !this, "kein gueltiger FeldTyp" );
    2509                 :            :     }
    2510                 :            : 
    2511         [ +  - ]:         57 :     if( sFldName.Len() )
    2512                 :            :     {
    2513                 :         57 :         SetFieldsDirty( sal_True );
    2514                 :            :         // look up and remove from the hash table
    2515 [ +  - ][ +  - ]:         57 :         sFldName = GetAppCharClass().lowercase( sFldName );
         [ +  - ][ +  - ]
    2516                 :            :         sal_uInt16 n;
    2517                 :            : 
    2518         [ +  - ]:         57 :         SwHash* pFnd = Find( sFldName, GetFldTypeTable(), TBLSZ, &n );
    2519                 :            : 
    2520         [ +  - ]:         57 :         if( !pFnd )
    2521                 :            :         {
    2522 [ +  - ][ +  - ]:         57 :             SwCalcFldType* pNew = new SwCalcFldType( sFldName, &rType );
    2523                 :         57 :             pNew->pNext = aFldTypeTable[ n ];
    2524                 :         57 :             aFldTypeTable[ n ] = pNew;
    2525                 :            :         }
    2526         [ +  - ]:         57 :     }
    2527                 :         57 : }
    2528                 :            : 
    2529                 :          0 : void SwDocUpdtFld::RemoveFldType( const SwFieldType& rType )
    2530                 :            : {
    2531         [ #  # ]:          0 :     String sFldName;
    2532      [ #  #  # ]:          0 :     switch( rType.Which() )
    2533                 :            :     {
    2534                 :            :     case RES_USERFLD :
    2535 [ #  # ][ #  # ]:          0 :         sFldName = ((SwUserFieldType&)rType).GetName();
    2536                 :          0 :         break;
    2537                 :            :     case RES_SETEXPFLD:
    2538 [ #  # ][ #  # ]:          0 :         sFldName = ((SwSetExpFieldType&)rType).GetName();
    2539                 :          0 :         break;
    2540                 :            :     }
    2541                 :            : 
    2542         [ #  # ]:          0 :     if( sFldName.Len() )
    2543                 :            :     {
    2544                 :          0 :         SetFieldsDirty( sal_True );
    2545                 :            :         // look up and remove from the hash table
    2546 [ #  # ][ #  # ]:          0 :         sFldName = GetAppCharClass().lowercase( sFldName );
         [ #  # ][ #  # ]
    2547                 :            :         sal_uInt16 n;
    2548                 :            : 
    2549         [ #  # ]:          0 :         SwHash* pFnd = Find( sFldName, GetFldTypeTable(), TBLSZ, &n );
    2550         [ #  # ]:          0 :         if( pFnd )
    2551                 :            :         {
    2552         [ #  # ]:          0 :             if( aFldTypeTable[ n ] == pFnd )
    2553                 :          0 :                 aFldTypeTable[ n ] = (SwCalcFldType*)pFnd->pNext;
    2554                 :            :             else
    2555                 :            :             {
    2556                 :          0 :                 SwHash* pPrev = aFldTypeTable[ n ];
    2557         [ #  # ]:          0 :                 while( pPrev->pNext != pFnd )
    2558                 :          0 :                     pPrev = pPrev->pNext;
    2559                 :          0 :                 pPrev->pNext = pFnd->pNext;
    2560                 :            :             }
    2561                 :          0 :             pFnd->pNext = 0;
    2562 [ #  # ][ #  # ]:          0 :             delete pFnd;
    2563                 :            :         }
    2564         [ #  # ]:          0 :     }
    2565                 :          0 : }
    2566                 :            : 
    2567                 :       1549 : SwDocUpdtFld::SwDocUpdtFld()
    2568                 :       1549 :     : pFldSortLst(0),  nFldUpdtPos(LONG_MAX), nFldLstGetMode(0)
    2569                 :            : {
    2570                 :       1549 :     bInUpdateFlds = bFldsDirty = sal_False;
    2571                 :       1549 :     memset( aFldTypeTable, 0, sizeof( aFldTypeTable ) );
    2572                 :       1549 : }
    2573                 :            : 
    2574                 :       1458 : SwDocUpdtFld::~SwDocUpdtFld()
    2575                 :            : {
    2576         [ +  + ]:       1458 :     delete pFldSortLst;
    2577                 :            : 
    2578         [ +  + ]:      69984 :     for( sal_uInt16 n = 0; n < TBLSZ; ++n )
    2579         [ +  + ]:      68526 :         delete aFldTypeTable[n];
    2580                 :       1458 : }
    2581                 :            : 
    2582                 :          0 : bool SwDoc::UpdateFld(SwTxtFld * pDstTxtFld, SwField & rSrcFld,
    2583                 :            :                       SwMsgPoolItem * pMsgHnt,
    2584                 :            :                       bool bUpdateFlds)
    2585                 :            : {
    2586                 :            :     OSL_ENSURE(pDstTxtFld, "no field to update!");
    2587                 :            : 
    2588                 :          0 :     sal_Bool bTblSelBreak = sal_False;
    2589                 :            : 
    2590                 :          0 :     SwFmtFld * pDstFmtFld = (SwFmtFld*)&pDstTxtFld->GetFld();
    2591                 :          0 :     SwField * pDstFld = pDstFmtFld->GetFld();
    2592                 :          0 :     sal_uInt16 nFldWhich = rSrcFld.GetTyp()->Which();
    2593         [ #  # ]:          0 :     SwNodeIndex aTblNdIdx(pDstTxtFld->GetTxtNode());
    2594                 :            : 
    2595         [ #  # ]:          0 :     if (pDstFld->GetTyp()->Which() ==
    2596                 :          0 :         rSrcFld.GetTyp()->Which())
    2597                 :            :     {
    2598 [ #  # ][ #  # ]:          0 :         if (GetIDocumentUndoRedo().DoesUndo())
                 [ #  # ]
    2599                 :            :         {
    2600         [ #  # ]:          0 :             SwPosition aPosition( pDstTxtFld->GetTxtNode() );
    2601         [ #  # ]:          0 :             aPosition.nContent = *pDstTxtFld->GetStart();
    2602                 :            : 
    2603                 :            :             SwUndo *const pUndo( new SwUndoFieldFromDoc(
    2604 [ #  # ][ #  # ]:          0 :                         aPosition, *pDstFld, rSrcFld, pMsgHnt, bUpdateFlds) );
    2605 [ #  # ][ #  # ]:          0 :             GetIDocumentUndoRedo().AppendUndo(pUndo);
                 [ #  # ]
    2606                 :            :         }
    2607                 :            : 
    2608         [ #  # ]:          0 :         SwField * pNewFld = rSrcFld.CopyField();
    2609         [ #  # ]:          0 :         pDstFmtFld->SetFld(pNewFld);
    2610                 :            : 
    2611   [ #  #  #  #  :          0 :         switch( nFldWhich )
                   #  # ]
    2612                 :            :         {
    2613                 :            :         case RES_SETEXPFLD:
    2614                 :            :         case RES_GETEXPFLD:
    2615                 :            :         case RES_HIDDENTXTFLD:
    2616                 :            :         case RES_HIDDENPARAFLD:
    2617         [ #  # ]:          0 :             UpdateExpFlds( pDstTxtFld, true );
    2618                 :          0 :             break;
    2619                 :            : 
    2620                 :            :         case RES_TABLEFLD:
    2621                 :            :             {
    2622                 :            :                 const SwTableNode* pTblNd =
    2623         [ #  # ]:          0 :                     IsIdxInTbl(aTblNdIdx);
    2624         [ #  # ]:          0 :                 if( pTblNd )
    2625                 :            :                 {
    2626                 :            :                     SwTableFmlUpdate aTblUpdate( &pTblNd->
    2627         [ #  # ]:          0 :                                                  GetTable() );
    2628         [ #  # ]:          0 :                     if (bUpdateFlds)
    2629         [ #  # ]:          0 :                         UpdateTblFlds( &aTblUpdate );
    2630                 :            :                     else
    2631         [ #  # ]:          0 :                         pNewFld->GetTyp()->ModifyNotification(0, &aTblUpdate);
    2632                 :            : 
    2633         [ #  # ]:          0 :                     if (! bUpdateFlds)
    2634         [ #  # ]:          0 :                         bTblSelBreak = sal_True;
    2635                 :            :                 }
    2636                 :            :             }
    2637                 :          0 :             break;
    2638                 :            : 
    2639                 :            :         case RES_MACROFLD:
    2640 [ #  # ][ #  # ]:          0 :             if( bUpdateFlds && pDstTxtFld->GetpTxtNode() )
                 [ #  # ]
    2641                 :          0 :                 (pDstTxtFld->GetpTxtNode())->
    2642         [ #  # ]:          0 :                     ModifyNotification( 0, pDstFmtFld );
    2643                 :          0 :             break;
    2644                 :            : 
    2645                 :            :         case RES_DBNAMEFLD:
    2646                 :            :         case RES_DBNEXTSETFLD:
    2647                 :            :         case RES_DBNUMSETFLD:
    2648                 :            :         case RES_DBSETNUMBERFLD:
    2649         [ #  # ]:          0 :             ChgDBData(((SwDBNameInfField*) pNewFld)->GetRealDBData());
    2650         [ #  # ]:          0 :             pNewFld->GetTyp()->UpdateFlds();
    2651                 :            : 
    2652                 :          0 :             break;
    2653                 :            : 
    2654                 :            :         case RES_DBFLD:
    2655                 :            :             {
    2656                 :            :                 // JP 10.02.96: call ChgValue, so that the style change sets the
    2657                 :            :                 // ContentString correctly
    2658                 :          0 :                 SwDBField* pDBFld = (SwDBField*)pNewFld;
    2659         [ #  # ]:          0 :                 if (pDBFld->IsInitialized())
    2660 [ #  # ][ #  # ]:          0 :                     pDBFld->ChgValue( pDBFld->GetValue(), sal_True );
    2661                 :            : 
    2662                 :          0 :                 pDBFld->ClearInitialized();
    2663         [ #  # ]:          0 :                 pDBFld->InitContent();
    2664                 :            :             }
    2665                 :            :             // no break;
    2666                 :            : 
    2667                 :            :         default:
    2668         [ #  # ]:          0 :             pDstFmtFld->ModifyNotification( 0, pMsgHnt );
    2669                 :            :         }
    2670                 :            : 
    2671                 :            :         // The fields we can calculate here are being triggered for an update
    2672                 :            :         // here explicitly.
    2673         [ #  # ]:          0 :         if( nFldWhich == RES_USERFLD )
    2674         [ #  # ]:          0 :             UpdateUsrFlds();
    2675                 :            :     }
    2676                 :            : 
    2677         [ #  # ]:          0 :     return bTblSelBreak;
    2678                 :            : }
    2679                 :            : 
    2680                 :         62 : bool SwDoc::PutValueToField(const SwPosition & rPos,
    2681                 :            :                             const Any& rVal, sal_uInt16 nWhich)
    2682                 :            : {
    2683                 :         62 :     Any aOldVal;
    2684         [ +  - ]:         62 :     SwField * pField = GetField(rPos);
    2685                 :            : 
    2686                 :            : 
    2687 [ +  - ][ +  - ]:        124 :     if (GetIDocumentUndoRedo().DoesUndo() &&
         [ +  - ][ +  - ]
                 [ +  - ]
    2688         [ +  - ]:         62 :         pField->QueryValue(aOldVal, nWhich))
    2689                 :            :     {
    2690 [ +  - ][ +  - ]:         62 :         SwUndo *const pUndo(new SwUndoFieldFromAPI(rPos, aOldVal, rVal, nWhich));
    2691 [ +  - ][ +  - ]:         62 :         GetIDocumentUndoRedo().AppendUndo(pUndo);
    2692                 :            :     }
    2693                 :            : 
    2694         [ +  - ]:         62 :     return pField->PutValue(rVal, nWhich);
    2695                 :            : }
    2696                 :            : 
    2697                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10