LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/fields - docufld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 297 1267 23.4 %
Date: 2013-07-09 Functions: 58 167 34.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <textapi.hxx>
      21             : 
      22             : #include <hintids.hxx>
      23             : #include <com/sun/star/text/XText.hpp>
      24             : #include <com/sun/star/script/Converter.hpp>
      25             : #include <com/sun/star/text/SetVariableType.hpp>
      26             : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
      27             : #include <com/sun/star/text/UserDataPart.hpp>
      28             : #include <com/sun/star/text/ChapterFormat.hpp>
      29             : #include <com/sun/star/text/XTextField.hpp>
      30             : #include <com/sun/star/text/PlaceholderType.hpp>
      31             : #include <com/sun/star/text/TemplateDisplayFormat.hpp>
      32             : #include <com/sun/star/text/UserFieldFormat.hpp>
      33             : #include <com/sun/star/text/PageNumberType.hpp>
      34             : #include <com/sun/star/text/ReferenceFieldPart.hpp>
      35             : #include <com/sun/star/text/FilenameDisplayFormat.hpp>
      36             : #include <com/sun/star/text/XDependentTextField.hpp>
      37             : #include <com/sun/star/text/DocumentStatistic.hpp>
      38             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      39             : #include <com/sun/star/document/XDocumentProperties.hpp>
      40             : #include <com/sun/star/util/Date.hpp>
      41             : #include <com/sun/star/util/Duration.hpp>
      42             : #include <unotools/localedatawrapper.hxx>
      43             : #include <editeng/unolingu.hxx>
      44             : #include <comphelper/processfactory.hxx>
      45             : #include <comphelper/types.hxx>
      46             : #include <comphelper/string.hxx>
      47             : #include <tools/urlobj.hxx>
      48             : #include <vcl/svapp.hxx>
      49             : #include <svl/urihelper.hxx>
      50             : #include <unotools/useroptions.hxx>
      51             : #include <unotools/syslocale.hxx>
      52             : #include <svl/zforlist.hxx>
      53             : 
      54             : #include <tools/time.hxx>
      55             : #include <tools/datetime.hxx>
      56             : 
      57             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      58             : #include <com/sun/star/util/DateTime.hpp>
      59             : #include <com/sun/star/util/Time.hpp>
      60             : 
      61             : #include <tools/shl.hxx>
      62             : #include <swmodule.hxx>
      63             : #include <sfx2/app.hxx>
      64             : #include <sfx2/docfile.hxx>
      65             : #include <sfx2/doctempl.hxx>
      66             : #include <fmtfld.hxx>
      67             : #include <txtfld.hxx>
      68             : #include <charfmt.hxx>
      69             : #include <docstat.hxx>
      70             : #include <pagedesc.hxx>
      71             : #include <fmtpdsc.hxx>
      72             : #include <doc.hxx>
      73             : #include <rootfrm.hxx>      // AuthorField
      74             : #include <pagefrm.hxx>      //
      75             : #include <cntfrm.hxx>       //
      76             : #include <pam.hxx>
      77             : #include <viewsh.hxx>
      78             : #include <dbmgr.hxx>
      79             : #include <shellres.hxx>
      80             : #include <docufld.hxx>
      81             : #include <flddat.hxx>
      82             : #include <docfld.hxx>
      83             : #include <ndtxt.hxx>
      84             : #include <expfld.hxx>
      85             : #include <poolfmt.hxx>
      86             : #include <docsh.hxx>
      87             : #include <unofldmid.h>
      88             : #include <swunohelper.hxx>
      89             : #include <comcore.hrc>
      90             : 
      91             : #include <editeng/outliner.hxx>
      92             : #include <editeng/outlobj.hxx>
      93             : #include <switerator.hxx>
      94             : #include <docary.hxx>
      95             : 
      96             : #define URL_DECODE  INetURLObject::DECODE_UNAMBIGUOUS
      97             : 
      98             : using namespace ::com::sun::star;
      99             : using namespace ::com::sun::star::uno;
     100             : using namespace nsSwDocInfoSubType;
     101             : 
     102             : // SwPageNumberFieldType
     103             : 
     104         898 : SwPageNumberFieldType::SwPageNumberFieldType()
     105             :     : SwFieldType( RES_PAGENUMBERFLD ),
     106             :     nNumberingType( SVX_NUM_ARABIC ),
     107         898 :     bVirtuell( false )
     108             : {
     109         898 : }
     110             : 
     111         487 : String& SwPageNumberFieldType::Expand( sal_uInt32 nFmt, short nOff,
     112             :          sal_uInt16 const nPageNumber, sal_uInt16 const nMaxPage,
     113             :                                 const String& rUserStr, String& rRet ) const
     114             : {
     115         487 :     sal_uInt32 nTmpFmt = (SVX_NUM_PAGEDESC == nFmt) ? (sal_uInt32)nNumberingType : nFmt;
     116         487 :     int const nTmp = nPageNumber + nOff;
     117             : 
     118         487 :     if (0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMaxPage))
     119         482 :         rRet = aEmptyStr;
     120           5 :     else if( SVX_NUM_CHAR_SPECIAL == nTmpFmt )
     121           0 :         rRet = rUserStr;
     122             :     else
     123           5 :         rRet = FormatNumber( (sal_uInt16)nTmp, nTmpFmt );
     124         487 :     return rRet;
     125             : }
     126             : 
     127           0 : SwFieldType* SwPageNumberFieldType::Copy() const
     128             : {
     129           0 :     SwPageNumberFieldType *pTmp = new SwPageNumberFieldType();
     130             : 
     131           0 :     pTmp->nNumberingType = nNumberingType;
     132           0 :     pTmp->bVirtuell  = bVirtuell;
     133             : 
     134           0 :     return pTmp;
     135             : }
     136             : 
     137           5 : void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc,
     138             :                                             sal_Bool bVirt,
     139             :                                             const sal_Int16* pNumFmt )
     140             : {
     141           5 :     if( pNumFmt )
     142           5 :         nNumberingType = *pNumFmt;
     143             : 
     144           5 :     bVirtuell = false;
     145           5 :     if( bVirt )
     146             :     {
     147             :         // check the flag since the layout NEVER sets it back
     148           0 :         const SfxItemPool &rPool = pDoc->GetAttrPool();
     149             :         const SwFmtPageDesc *pDesc;
     150           0 :         sal_uInt32 nMaxItems = rPool.GetItemCount2( RES_PAGEDESC );
     151           0 :         for( sal_uInt32 n = 0; n < nMaxItems; ++n )
     152           0 :             if( 0 != (pDesc = (SwFmtPageDesc*)rPool.GetItem2( RES_PAGEDESC, n ) )
     153           0 :                 && pDesc->GetNumOffset() && pDesc->GetDefinedIn() )
     154             :             {
     155           0 :                 SwCntntNode* pNd = PTR_CAST( SwCntntNode, pDesc->GetDefinedIn() );
     156           0 :                 if( pNd )
     157             :                 {
     158           0 :                     if ( SwIterator<SwFrm,SwCntntNode>::FirstElement(*pNd) )
     159           0 :                         bVirtuell = true;
     160             :                 }
     161           0 :                 else if( pDesc->GetDefinedIn()->ISA( SwFmt ))
     162             :                 {
     163           0 :                     SwAutoFmtGetDocNode aGetHt( &pDoc->GetNodes() );
     164           0 :                     bVirtuell = !pDesc->GetDefinedIn()->GetInfo( aGetHt );
     165           0 :                     break;
     166             :                 }
     167             :             }
     168             :     }
     169           5 : }
     170             : 
     171             : // SwPageNumberField
     172             : 
     173        2414 : SwPageNumberField::SwPageNumberField(SwPageNumberFieldType* pTyp,
     174             :           sal_uInt16 nSub, sal_uInt32 nFmt, short nOff,
     175             :           sal_uInt16 const nPageNumber, sal_uInt16 const nMaxPage)
     176             :     : SwField(pTyp, nFmt), nSubType(nSub), nOffset(nOff)
     177             :     , m_nPageNumber(nPageNumber)
     178        2414 :     , m_nMaxPage(nMaxPage)
     179             : {
     180        2414 : }
     181             : 
     182           5 : void SwPageNumberField::ChangeExpansion(sal_uInt16 const nPageNumber,
     183             :         sal_uInt16 const nMaxPage)
     184             : {
     185           5 :     m_nPageNumber = nPageNumber;
     186           5 :     m_nMaxPage = nMaxPage;
     187           5 : }
     188             : 
     189         487 : String SwPageNumberField::Expand() const
     190             : {
     191         487 :     String sRet;
     192         487 :     SwPageNumberFieldType* pFldType = (SwPageNumberFieldType*)GetTyp();
     193             : 
     194         487 :     if( PG_NEXT == nSubType && 1 != nOffset )
     195             :     {
     196           0 :         if (pFldType->Expand(GetFormat(), 1, m_nPageNumber, m_nMaxPage,
     197           0 :                     sUserStr, sRet).Len())
     198             :         {
     199             :             pFldType->Expand(GetFormat(), nOffset, m_nPageNumber, m_nMaxPage,
     200           0 :                     sUserStr, sRet);
     201             :         }
     202             :     }
     203         487 :     else if( PG_PREV == nSubType && -1 != nOffset )
     204             :     {
     205           0 :         if (pFldType->Expand(GetFormat(), -1, m_nPageNumber, m_nMaxPage,
     206           0 :                     sUserStr, sRet).Len())
     207             :         {
     208             :             pFldType->Expand(GetFormat(), nOffset, m_nPageNumber, m_nMaxPage,
     209           0 :                     sUserStr, sRet);
     210             :         }
     211             :     }
     212             :     else
     213             :         pFldType->Expand(GetFormat(), nOffset, m_nPageNumber, m_nMaxPage,
     214         487 :                 sUserStr, sRet);
     215         487 :     return sRet;
     216             : }
     217             : 
     218        1933 : SwField* SwPageNumberField::Copy() const
     219             : {
     220             :     SwPageNumberField *pTmp = new SwPageNumberField(
     221        1933 :                 static_cast<SwPageNumberFieldType*>(GetTyp()), nSubType,
     222        1933 :                 GetFormat(), nOffset, m_nPageNumber, m_nMaxPage);
     223        1933 :     pTmp->SetLanguage( GetLanguage() );
     224        1933 :     pTmp->SetUserString( sUserStr );
     225        1933 :     return pTmp;
     226             : }
     227             : 
     228           0 : OUString SwPageNumberField::GetPar2() const
     229             : {
     230           0 :     return OUString::number(nOffset);
     231             : }
     232             : 
     233           0 : void SwPageNumberField::SetPar2(const OUString& rStr)
     234             : {
     235           0 :     nOffset = (short)rStr.toInt32();
     236           0 : }
     237             : 
     238           0 : sal_uInt16 SwPageNumberField::GetSubType() const
     239             : {
     240           0 :     return nSubType;
     241             : }
     242             : 
     243           0 : bool SwPageNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     244             : {
     245           0 :     switch( nWhichId )
     246             :     {
     247             :     case FIELD_PROP_FORMAT:
     248           0 :         rAny <<= (sal_Int16)GetFormat();
     249           0 :         break;
     250             :     case FIELD_PROP_USHORT1:
     251           0 :         rAny <<= nOffset;
     252           0 :         break;
     253             :     case FIELD_PROP_SUBTYPE:
     254             :         {
     255             :              text::PageNumberType eType;
     256           0 :             eType = text::PageNumberType_CURRENT;
     257           0 :             if(nSubType == PG_PREV)
     258           0 :                 eType = text::PageNumberType_PREV;
     259           0 :             else if(nSubType == PG_NEXT)
     260           0 :                 eType = text::PageNumberType_NEXT;
     261           0 :             rAny.setValue(&eType, ::getCppuType((const text::PageNumberType*)0));
     262             :         }
     263           0 :         break;
     264             :     case FIELD_PROP_PAR1:
     265           0 :         rAny <<= OUString(sUserStr);
     266           0 :         break;
     267             : 
     268             :     default:
     269             :         OSL_FAIL("illegal property");
     270             :     }
     271           0 :     return true;
     272             : }
     273             : 
     274           6 : bool SwPageNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     275             : {
     276           6 :     bool bRet = true;
     277           6 :     sal_Int16 nSet = 0;
     278           6 :     switch( nWhichId )
     279             :     {
     280             :     case FIELD_PROP_FORMAT:
     281           0 :         rAny >>= nSet;
     282             : 
     283             :         // TODO: woher kommen die defines?
     284           0 :         if(nSet <= SVX_NUM_PAGEDESC )
     285           0 :             SetFormat(nSet);
     286             :         else {
     287             :         }
     288           0 :         break;
     289             :     case FIELD_PROP_USHORT1:
     290           0 :         rAny >>= nSet;
     291           0 :         nOffset = nSet;
     292           0 :         break;
     293             :     case FIELD_PROP_SUBTYPE:
     294           6 :         switch( SWUnoHelper::GetEnumAsInt32( rAny ) )
     295             :         {
     296             :             case text::PageNumberType_CURRENT:
     297           6 :                 nSubType = PG_RANDOM;
     298           6 :             break;
     299             :             case text::PageNumberType_PREV:
     300           0 :                 nSubType = PG_PREV;
     301           0 :             break;
     302             :             case text::PageNumberType_NEXT:
     303           0 :                 nSubType = PG_NEXT;
     304           0 :             break;
     305             :             default:
     306           0 :                 bRet = false;
     307             :         }
     308           6 :         break;
     309             :     case FIELD_PROP_PAR1:
     310           0 :         ::GetString( rAny, sUserStr );
     311           0 :         break;
     312             : 
     313             :     default:
     314             :         OSL_FAIL("illegal property");
     315             :     }
     316           6 :     return bRet;
     317             : }
     318             : // SwAuthorFieldType
     319             : 
     320         898 : SwAuthorFieldType::SwAuthorFieldType()
     321         898 :     : SwFieldType( RES_AUTHORFLD )
     322             : {
     323         898 : }
     324             : 
     325         134 : String SwAuthorFieldType::Expand(sal_uLong nFmt) const
     326             : {
     327         134 :     String sRet;
     328         134 :     SvtUserOptions&  rOpt = SW_MOD()->GetUserOptions();
     329         134 :     if((nFmt & 0xff) == AF_NAME)
     330           0 :         sRet = rOpt.GetFullName();
     331             :     else
     332         134 :         sRet = rOpt.GetID();
     333         134 :     return sRet;
     334             : }
     335             : 
     336           0 : SwFieldType* SwAuthorFieldType::Copy() const
     337             : {
     338           0 :     return new SwAuthorFieldType;
     339             : }
     340             : 
     341             : // SwAuthorField
     342             : 
     343         134 : SwAuthorField::SwAuthorField(SwAuthorFieldType* pTyp, sal_uInt32 nFmt)
     344         134 :     : SwField(pTyp, nFmt)
     345             : {
     346         134 :     aContent = ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
     347         134 : }
     348             : 
     349          58 : String SwAuthorField::Expand() const
     350             : {
     351          58 :     if (!IsFixed())
     352           0 :         ((SwAuthorField*)this)->aContent =
     353           0 :                     ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat());
     354             : 
     355          58 :     return aContent;
     356             : }
     357             : 
     358         115 : SwField* SwAuthorField::Copy() const
     359             : {
     360         115 :     SwAuthorField *pTmp = new SwAuthorField( (SwAuthorFieldType*)GetTyp(),
     361         115 :                                                 GetFormat());
     362         115 :     pTmp->SetExpansion(aContent);
     363         115 :     return pTmp;
     364             : }
     365             : 
     366          40 : bool SwAuthorField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     367             : {
     368             :     bool bVal;
     369          40 :     switch( nWhichId )
     370             :     {
     371             :     case FIELD_PROP_BOOL1:
     372           0 :         bVal = (GetFormat() & 0xff) == AF_NAME;
     373           0 :         rAny.setValue(&bVal, ::getBooleanCppuType());
     374           0 :         break;
     375             : 
     376             :     case FIELD_PROP_BOOL2:
     377          20 :         bVal = IsFixed();
     378          20 :         rAny.setValue(&bVal, ::getBooleanCppuType());
     379          20 :         break;
     380             : 
     381             :     case FIELD_PROP_PAR1:
     382          20 :         rAny <<= OUString(GetContent());
     383          20 :         break;
     384             : 
     385             :     default:
     386             :         OSL_FAIL("illegal property");
     387             :     }
     388          40 :     return true;
     389             : }
     390             : 
     391           0 : bool SwAuthorField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     392             : {
     393           0 :     switch( nWhichId )
     394             :     {
     395             :     case FIELD_PROP_BOOL1:
     396           0 :         SetFormat( *(sal_Bool*)rAny.getValue() ? AF_NAME : AF_SHORTCUT );
     397           0 :         break;
     398             : 
     399             :     case FIELD_PROP_BOOL2:
     400           0 :         if( *(sal_Bool*)rAny.getValue() )
     401           0 :             SetFormat( GetFormat() | AF_FIXED);
     402             :         else
     403           0 :             SetFormat( GetFormat() & ~AF_FIXED);
     404           0 :         break;
     405             : 
     406             :     case FIELD_PROP_PAR1:
     407           0 :         ::GetString( rAny, aContent );
     408           0 :         break;
     409             : 
     410             :     default:
     411             :         OSL_FAIL("illegal property");
     412             :     }
     413           0 :     return true;
     414             : }
     415             : 
     416             : // SwFileNameFieldType
     417             : 
     418         899 : SwFileNameFieldType::SwFileNameFieldType(SwDoc *pDocument)
     419         899 :     : SwFieldType( RES_FILENAMEFLD )
     420             : {
     421         899 :     pDoc = pDocument;
     422         899 : }
     423             : 
     424           4 : String SwFileNameFieldType::Expand(sal_uLong nFmt) const
     425             : {
     426           4 :     String aRet;
     427           4 :     const SwDocShell* pDShell = pDoc->GetDocShell();
     428           4 :     if( pDShell && pDShell->HasName() )
     429             :     {
     430           4 :         const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject();
     431           4 :         switch( nFmt & ~FF_FIXED )
     432             :         {
     433             :             case FF_PATH:
     434             :                 {
     435           1 :                     if( INET_PROT_FILE == rURLObj.GetProtocol() )
     436             :                     {
     437           1 :                         INetURLObject aTemp(rURLObj);
     438           1 :                         aTemp.removeSegment();
     439             :                         // last slash should belong to the pathname
     440           1 :                         aRet = aTemp.PathToFileName();
     441             :                     }
     442             :                     else
     443             :                     {
     444           0 :                         aRet = URIHelper::removePassword(
     445             :                                     rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
     446           0 :                                     INetURLObject::WAS_ENCODED, URL_DECODE );
     447             :                         aRet.Erase( aRet.Search( String(rURLObj.GetLastName(
     448           0 :                                                     URL_DECODE )) ) );
     449             :                     }
     450             :                 }
     451           1 :                 break;
     452             : 
     453             :             case FF_NAME:
     454           1 :                 aRet = rURLObj.GetLastName( INetURLObject::DECODE_WITH_CHARSET );
     455           1 :                 break;
     456             : 
     457             :             case FF_NAME_NOEXT:
     458           1 :                 aRet = rURLObj.GetBase();
     459           1 :                 break;
     460             : 
     461             :             default:
     462           1 :                 if( INET_PROT_FILE == rURLObj.GetProtocol() )
     463           1 :                     aRet = rURLObj.GetFull();
     464             :                 else
     465           0 :                     aRet = URIHelper::removePassword(
     466             :                                     rURLObj.GetMainURL( INetURLObject::NO_DECODE ),
     467           0 :                                     INetURLObject::WAS_ENCODED, URL_DECODE );
     468             :         }
     469             :     }
     470           4 :     return aRet;
     471             : }
     472             : 
     473           0 : SwFieldType* SwFileNameFieldType::Copy() const
     474             : {
     475           0 :     SwFieldType *pTmp = new SwFileNameFieldType(pDoc);
     476           0 :     return pTmp;
     477             : }
     478             : 
     479             : // SwFileNameField
     480             : 
     481           0 : SwFileNameField::SwFileNameField(SwFileNameFieldType* pTyp, sal_uInt32 nFmt)
     482           0 :     : SwField(pTyp, nFmt)
     483             : {
     484           0 :     aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
     485           0 : }
     486             : 
     487           0 : String SwFileNameField::Expand() const
     488             : {
     489           0 :     if (!IsFixed())
     490           0 :         ((SwFileNameField*)this)->aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat());
     491             : 
     492           0 :     return aContent;
     493             : }
     494             : 
     495           0 : SwField* SwFileNameField::Copy() const
     496             : {
     497             :     SwFileNameField *pTmp =
     498           0 :         new SwFileNameField((SwFileNameFieldType*)GetTyp(), GetFormat());
     499           0 :     pTmp->SetExpansion(aContent);
     500             : 
     501           0 :     return pTmp;
     502             : }
     503             : 
     504           0 : bool SwFileNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     505             : {
     506           0 :     switch( nWhichId )
     507             :     {
     508             :     case FIELD_PROP_FORMAT:
     509             :         {
     510             :             sal_Int16 nRet;
     511           0 :             switch( GetFormat() &(~FF_FIXED) )
     512             :             {
     513             :                 case FF_PATH:
     514           0 :                     nRet = text::FilenameDisplayFormat::PATH;
     515           0 :                 break;
     516             :                 case FF_NAME_NOEXT:
     517           0 :                     nRet = text::FilenameDisplayFormat::NAME;
     518           0 :                 break;
     519             :                 case FF_NAME:
     520           0 :                     nRet = text::FilenameDisplayFormat::NAME_AND_EXT;
     521           0 :                 break;
     522           0 :                 default:    nRet = text::FilenameDisplayFormat::FULL;
     523             :             }
     524           0 :             rAny <<= nRet;
     525             :         }
     526           0 :         break;
     527             : 
     528             :     case FIELD_PROP_BOOL2:
     529             :         {
     530           0 :             sal_Bool bVal = IsFixed();
     531           0 :             rAny.setValue(&bVal, ::getBooleanCppuType());
     532             :         }
     533           0 :         break;
     534             : 
     535             :     case FIELD_PROP_PAR3:
     536           0 :         rAny <<= OUString(GetContent());
     537           0 :         break;
     538             :     default:
     539             :         OSL_FAIL("illegal property");
     540             :     }
     541           0 :     return true;
     542             : }
     543             : 
     544           0 : bool SwFileNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     545             : {
     546           0 :     switch( nWhichId )
     547             :     {
     548             :     case FIELD_PROP_FORMAT:
     549             :         {
     550             :             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
     551             :             //              called with a int32 value! But normally we need
     552             :             //              here only a int16
     553           0 :             sal_Int32 nType = 0;
     554           0 :             rAny >>= nType;
     555           0 :             sal_Bool bFixed = IsFixed();
     556           0 :             switch( nType )
     557             :             {
     558             :                 case text::FilenameDisplayFormat::PATH:
     559           0 :                     nType = FF_PATH;
     560           0 :                 break;
     561             :                 case text::FilenameDisplayFormat::NAME:
     562           0 :                     nType = FF_NAME_NOEXT;
     563           0 :                 break;
     564             :                 case text::FilenameDisplayFormat::NAME_AND_EXT:
     565           0 :                     nType = FF_NAME;
     566           0 :                 break;
     567           0 :                 default:    nType = FF_PATHNAME;
     568             :             }
     569           0 :             if(bFixed)
     570           0 :                 nType |= FF_FIXED;
     571           0 :             SetFormat(nType);
     572             :         }
     573           0 :         break;
     574             : 
     575             :     case FIELD_PROP_BOOL2:
     576           0 :         if( *(sal_Bool*)rAny.getValue() )
     577           0 :             SetFormat( GetFormat() | FF_FIXED);
     578             :         else
     579           0 :             SetFormat( GetFormat() & ~FF_FIXED);
     580           0 :         break;
     581             : 
     582             :     case FIELD_PROP_PAR3:
     583           0 :         ::GetString( rAny, aContent );
     584           0 :         break;
     585             : 
     586             :     default:
     587             :         OSL_FAIL("illegal property");
     588             :     }
     589           0 :     return true;
     590             : }
     591             : 
     592             : // SwTemplNameFieldType
     593             : 
     594        1796 : SwTemplNameFieldType::SwTemplNameFieldType(SwDoc *pDocument)
     595        1796 :     : SwFieldType( RES_TEMPLNAMEFLD )
     596             : {
     597        1796 :     pDoc = pDocument;
     598        1796 : }
     599             : 
     600           0 : String SwTemplNameFieldType::Expand(sal_uLong nFmt) const
     601             : {
     602             :     OSL_ENSURE( nFmt < FF_END, "Expand: kein guelt. Fmt!" );
     603             : 
     604           0 :     String aRet;
     605           0 :     SwDocShell *pDocShell(pDoc->GetDocShell());
     606             :     OSL_ENSURE(pDocShell, "no SwDocShell");
     607           0 :     if (pDocShell) {
     608             :         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     609           0 :             pDocShell->GetModel(), uno::UNO_QUERY_THROW);
     610             :         uno::Reference<document::XDocumentProperties> xDocProps(
     611           0 :             xDPS->getDocumentProperties());
     612             :         OSL_ENSURE(xDocProps.is(), "Doc has no DocumentProperties");
     613             : 
     614           0 :         if( FF_UI_NAME == nFmt )
     615           0 :             aRet = xDocProps->getTemplateName();
     616           0 :         else if( !xDocProps->getTemplateURL().isEmpty() )
     617             :         {
     618           0 :             if( FF_UI_RANGE == nFmt )
     619             :             {
     620             :                 // fuers besorgen vom RegionNamen !!
     621           0 :                 SfxDocumentTemplates aFac;
     622           0 :                 aFac.Construct();
     623           0 :                 String sTmp;
     624           0 :                 aFac.GetLogicNames( xDocProps->getTemplateURL(), aRet, sTmp );
     625             :             }
     626             :             else
     627             :             {
     628           0 :                 INetURLObject aPathName( xDocProps->getTemplateURL() );
     629           0 :                 if( FF_NAME == nFmt )
     630           0 :                     aRet = aPathName.GetName(URL_DECODE);
     631           0 :                 else if( FF_NAME_NOEXT == nFmt )
     632           0 :                     aRet = aPathName.GetBase();
     633             :                 else
     634             :                 {
     635           0 :                     if( FF_PATH == nFmt )
     636             :                     {
     637           0 :                         aPathName.removeSegment();
     638           0 :                         aRet = aPathName.GetFull();
     639             :                     }
     640             :                     else
     641           0 :                         aRet = aPathName.GetFull();
     642           0 :                 }
     643             :             }
     644           0 :         }
     645             :     }
     646           0 :     return aRet;
     647             : }
     648             : 
     649           0 : SwFieldType* SwTemplNameFieldType::Copy() const
     650             : {
     651           0 :     SwFieldType *pTmp = new SwTemplNameFieldType(pDoc);
     652           0 :     return pTmp;
     653             : }
     654             : // SwTemplNameField
     655             : 
     656           0 : SwTemplNameField::SwTemplNameField(SwTemplNameFieldType* pTyp, sal_uInt32 nFmt)
     657           0 :     : SwField(pTyp, nFmt)
     658           0 : {}
     659             : 
     660           0 : String SwTemplNameField::Expand() const
     661             : {
     662           0 :     return((SwTemplNameFieldType*)GetTyp())->Expand(GetFormat());
     663             : }
     664             : 
     665           0 : SwField* SwTemplNameField::Copy() const
     666             : {
     667             :     SwTemplNameField *pTmp =
     668           0 :         new SwTemplNameField((SwTemplNameFieldType*)GetTyp(), GetFormat());
     669           0 :     return pTmp;
     670             : }
     671             : 
     672           0 : bool SwTemplNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     673             : {
     674           0 :     switch ( nWhichId )
     675             :     {
     676             :     case FIELD_PROP_FORMAT:
     677             :         {
     678             :             sal_Int16 nRet;
     679           0 :             switch( GetFormat() )
     680             :             {
     681           0 :                 case FF_PATH:       nRet = text::FilenameDisplayFormat::PATH; break;
     682           0 :                 case FF_NAME_NOEXT: nRet = text::FilenameDisplayFormat::NAME; break;
     683           0 :                 case FF_NAME:       nRet = text::FilenameDisplayFormat::NAME_AND_EXT; break;
     684           0 :                 case FF_UI_RANGE:   nRet = text::TemplateDisplayFormat::AREA; break;
     685           0 :                 case FF_UI_NAME:    nRet = text::TemplateDisplayFormat::TITLE;  break;
     686           0 :                 default:    nRet = text::FilenameDisplayFormat::FULL;
     687             : 
     688             :             }
     689           0 :             rAny <<= nRet;
     690             :         }
     691           0 :         break;
     692             :     default:
     693             :         OSL_FAIL("illegal property");
     694             :     }
     695           0 :     return true;
     696             : }
     697             : 
     698           0 : bool SwTemplNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     699             : {
     700           0 :     switch ( nWhichId )
     701             :     {
     702             :     case FIELD_PROP_FORMAT:
     703             :         {
     704             :             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
     705             :             //              called with a int32 value! But normally we need
     706             :             //              here only a int16
     707           0 :             sal_Int32 nType = 0;
     708           0 :             rAny >>= nType;
     709           0 :             switch( nType )
     710             :             {
     711             :             case text::FilenameDisplayFormat::PATH:
     712           0 :                 SetFormat(FF_PATH);
     713           0 :             break;
     714             :             case text::FilenameDisplayFormat::NAME:
     715           0 :                 SetFormat(FF_NAME_NOEXT);
     716           0 :             break;
     717             :             case text::FilenameDisplayFormat::NAME_AND_EXT:
     718           0 :                 SetFormat(FF_NAME);
     719           0 :             break;
     720             :             case text::TemplateDisplayFormat::AREA  :
     721           0 :                 SetFormat(FF_UI_RANGE);
     722           0 :             break;
     723             :             case text::TemplateDisplayFormat::TITLE  :
     724           0 :                 SetFormat(FF_UI_NAME);
     725           0 :             break;
     726           0 :             default:    SetFormat(FF_PATHNAME);
     727             :             }
     728             :         }
     729           0 :         break;
     730             :     default:
     731             :         OSL_FAIL("illegal property");
     732             :     }
     733           0 :     return true;
     734             : }
     735             : 
     736             : // SwDocStatFieldType
     737             : 
     738         898 : SwDocStatFieldType::SwDocStatFieldType(SwDoc* pDocument)
     739         898 :     : SwFieldType( RES_DOCSTATFLD ), nNumberingType( SVX_NUM_ARABIC )
     740             : {
     741         898 :     pDoc = pDocument;
     742         898 : }
     743             : 
     744           0 : String SwDocStatFieldType::Expand(sal_uInt16 nSubType, sal_uInt32 nFmt) const
     745             : {
     746           0 :     sal_uInt32 nVal = 0;
     747           0 :     const SwDocStat& rDStat = pDoc->GetDocStat();
     748           0 :     switch( nSubType )
     749             :     {
     750           0 :         case DS_TBL:  nVal = rDStat.nTbl;   break;
     751           0 :         case DS_GRF:  nVal = rDStat.nGrf;   break;
     752           0 :         case DS_OLE:  nVal = rDStat.nOLE;   break;
     753           0 :         case DS_PARA: nVal = rDStat.nPara;  break;
     754           0 :         case DS_WORD: nVal = rDStat.nWord;  break;
     755           0 :         case DS_CHAR: nVal = rDStat.nChar;  break;
     756             :         case DS_PAGE:
     757           0 :             if( pDoc->GetCurrentLayout() )//swmod 080218
     758           0 :                 ((SwDocStat &)rDStat).nPage = pDoc->GetCurrentLayout()->GetPageNum();   //swmod 080218
     759           0 :             nVal = rDStat.nPage;
     760           0 :             if( SVX_NUM_PAGEDESC == nFmt )
     761           0 :                 nFmt = (sal_uInt32)nNumberingType;
     762           0 :             break;
     763             :         default:
     764             :             OSL_FAIL( "SwDocStatFieldType::Expand: unbekannter SubType" );
     765             :     }
     766             : 
     767           0 :     String sRet;
     768           0 :     if( nVal <= SHRT_MAX )
     769           0 :         sRet = FormatNumber( (sal_uInt16)nVal, nFmt );
     770             :     else
     771           0 :         sRet = OUString::number( nVal );
     772           0 :     return sRet;
     773             : }
     774             : 
     775           0 : SwFieldType* SwDocStatFieldType::Copy() const
     776             : {
     777           0 :     SwDocStatFieldType *pTmp = new SwDocStatFieldType(pDoc);
     778           0 :     return pTmp;
     779             : }
     780             : 
     781             : /**
     782             :  * @param pTyp
     783             :  * @param nSub SubType
     784             :  * @param nFmt
     785             :  */
     786           0 : SwDocStatField::SwDocStatField(SwDocStatFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
     787             :     : SwField(pTyp, nFmt),
     788           0 :     nSubType(nSub)
     789           0 : {}
     790             : 
     791           0 : String SwDocStatField::Expand() const
     792             : {
     793           0 :     return((SwDocStatFieldType*)GetTyp())->Expand(nSubType, GetFormat());
     794             : }
     795             : 
     796           0 : SwField* SwDocStatField::Copy() const
     797             : {
     798             :     SwDocStatField *pTmp = new SwDocStatField(
     799           0 :                     (SwDocStatFieldType*)GetTyp(), nSubType, GetFormat() );
     800           0 :     return pTmp;
     801             : }
     802             : 
     803           0 : sal_uInt16 SwDocStatField::GetSubType() const
     804             : {
     805           0 :     return nSubType;
     806             : }
     807             : 
     808           0 : void SwDocStatField::SetSubType(sal_uInt16 nSub)
     809             : {
     810           0 :     nSubType = nSub;
     811           0 : }
     812             : 
     813           0 : void SwDocStatField::ChangeExpansion( const SwFrm* pFrm )
     814             : {
     815           0 :     if( DS_PAGE == nSubType && SVX_NUM_PAGEDESC == GetFormat() )
     816           0 :         ((SwDocStatFieldType*)GetTyp())->SetNumFormat(
     817           0 :                 pFrm->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType() );
     818           0 : }
     819             : 
     820           0 : bool SwDocStatField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     821             : {
     822           0 :     switch ( nWhichId )
     823             :     {
     824             :     case FIELD_PROP_USHORT2:
     825           0 :         rAny <<= (sal_Int16)GetFormat();
     826           0 :         break;
     827             :     default:
     828             :         OSL_FAIL("illegal property");
     829             :     }
     830           0 :     return true;
     831             : }
     832             : 
     833           0 : bool SwDocStatField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     834             : {
     835           0 :     bool bRet = false;
     836           0 :     switch ( nWhichId )
     837             :     {
     838             :     case FIELD_PROP_USHORT2:
     839             :         {
     840           0 :             sal_Int16 nSet = 0;
     841           0 :             rAny >>= nSet;
     842           0 :             if(nSet <= SVX_NUM_CHARS_LOWER_LETTER_N &&
     843           0 :                 nSet != SVX_NUM_CHAR_SPECIAL &&
     844           0 :                     nSet != SVX_NUM_BITMAP)
     845             :             {
     846           0 :                 SetFormat(nSet);
     847           0 :                 bRet = true;
     848             :             }
     849             :         }
     850           0 :         break;
     851             : 
     852             :     default:
     853             :         OSL_FAIL("illegal property");
     854             :     }
     855           0 :     return bRet;
     856             : }
     857             : 
     858             : // Document info field type
     859             : 
     860         898 : SwDocInfoFieldType::SwDocInfoFieldType(SwDoc* pDc)
     861         898 :     : SwValueFieldType( pDc, RES_DOCINFOFLD )
     862             : {
     863         898 : }
     864             : 
     865           0 : SwFieldType* SwDocInfoFieldType::Copy() const
     866             : {
     867           0 :     SwDocInfoFieldType* pTyp = new SwDocInfoFieldType(GetDoc());
     868           0 :     return pTyp;
     869             : }
     870             : 
     871           0 : static void lcl_GetLocalDataWrapper( sal_uLong nLang,
     872             :                               const LocaleDataWrapper **ppAppLocalData,
     873             :                               const LocaleDataWrapper **ppLocalData )
     874             : {
     875           0 :     SvtSysLocale aLocale;
     876           0 :     *ppAppLocalData = &aLocale.GetLocaleData();
     877           0 :     *ppLocalData = *ppAppLocalData;
     878           0 :     if( nLang != (*ppLocalData)->getLanguageTag().getLanguageType() )
     879             :         *ppLocalData = new LocaleDataWrapper(
     880           0 :                         LanguageTag( static_cast<LanguageType>(nLang) ));
     881           0 : }
     882             : 
     883          10 : String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat,
     884             :                                     sal_uInt16 nLang, const String& rName ) const
     885             : {
     886          10 :     String aStr;
     887          10 :     const LocaleDataWrapper *pAppLocalData = 0, *pLocalData = 0;
     888          10 :     SwDocShell *pDocShell(GetDoc()->GetDocShell());
     889             :     OSL_ENSURE(pDocShell, "no SwDocShell");
     890          10 :     if (!pDocShell) { return aStr; }
     891             : 
     892             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     893          20 :         pDocShell->GetModel(), uno::UNO_QUERY_THROW);
     894             :     uno::Reference<document::XDocumentProperties> xDocProps(
     895          20 :         xDPS->getDocumentProperties());
     896             :     OSL_ENSURE(xDocProps.is(), "Doc has no DocumentProperties");
     897             : 
     898          10 :     sal_uInt16 nExtSub = nSub & 0xff00;
     899          10 :     nSub &= 0xff;   // ExtendedSubTypes nicht beachten
     900             : 
     901          10 :     switch(nSub)
     902             :     {
     903           0 :     case DI_TITEL:  aStr = xDocProps->getTitle();       break;
     904           0 :     case DI_THEMA:  aStr = xDocProps->getSubject();     break;
     905           0 :     case DI_KEYS:   aStr = ::comphelper::string::convertCommaSeparated(
     906           0 :                                 xDocProps->getKeywords());
     907           0 :                     break;
     908           0 :     case DI_COMMENT:aStr = xDocProps->getDescription(); break;
     909           0 :     case DI_DOCNO:  aStr = OUString::number(
     910           0 :                                         xDocProps->getEditingCycles() );
     911           0 :                     break;
     912             :     case DI_EDIT:
     913           0 :         if ( !nFormat )
     914             :         {
     915           0 :             lcl_GetLocalDataWrapper( nLang, &pAppLocalData, &pLocalData );
     916           0 :             sal_Int32 dur = xDocProps->getEditingDuration();
     917           0 :             aStr = pLocalData->getTime( Time(dur/3600, (dur%3600)/60, dur%60),
     918           0 :                                         sal_False, sal_False);
     919             :         }
     920             :         else
     921             :         {
     922           0 :             sal_Int32 dur = xDocProps->getEditingDuration();
     923           0 :             double fVal = Time(dur/3600, (dur%3600)/60, dur%60).GetTimeInDays();
     924           0 :             aStr = ExpandValue(fVal, nFormat, nLang);
     925             :         }
     926           0 :         break;
     927             :     case DI_CUSTOM:
     928             :         {
     929           0 :             OUString sVal;
     930             :             try
     931             :             {
     932           0 :                 uno::Any aAny;
     933             :                 uno::Reference < beans::XPropertySet > xSet(
     934           0 :                     xDocProps->getUserDefinedProperties(),
     935           0 :                     uno::UNO_QUERY_THROW);
     936           0 :                 aAny = xSet->getPropertyValue( rName );
     937             : 
     938           0 :                 uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(comphelper::getProcessComponentContext()) );
     939           0 :                 uno::Any aNew;
     940           0 :                     aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
     941           0 :                 aNew >>= sVal;
     942             :             }
     943           0 :             catch (uno::Exception&) {}
     944           0 :             return sVal;
     945             :         }
     946             : 
     947             :     default:
     948             :         {
     949          10 :             String aName( xDocProps->getAuthor() );
     950          10 :             util::DateTime uDT( xDocProps->getCreationDate() );
     951          10 :             Date aD(uDT.Day, uDT.Month, uDT.Year);
     952          10 :             Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
     953          10 :             DateTime aDate(aD,aT);
     954          10 :             if( nSub == DI_CREATE )
     955             :                 ;       // das wars schon!!
     956          10 :             else if( nSub == DI_CHANGE )
     957             :             {
     958          10 :                 aName = xDocProps->getModifiedBy();
     959          10 :                 uDT = xDocProps->getModificationDate();
     960          10 :                 Date bD(uDT.Day, uDT.Month, uDT.Year);
     961          10 :                 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
     962          10 :                 DateTime bDate(bD,bT);
     963          10 :                 aDate = bDate;
     964             :             }
     965           0 :             else if( nSub == DI_PRINT )
     966             :             {
     967           0 :                 aName = xDocProps->getPrintedBy();
     968           0 :                 uDT = xDocProps->getPrintDate();
     969           0 :                 Date bD(uDT.Day, uDT.Month, uDT.Year);
     970           0 :                 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
     971           0 :                 DateTime bDate(bD,bT);
     972           0 :                 aDate = bDate;
     973             :             }
     974             :             else
     975           0 :                 break;
     976             : 
     977          10 :             if (aDate.IsValidAndGregorian())
     978             :             {
     979          10 :                 switch (nExtSub & ~DI_SUB_FIXED)
     980             :                 {
     981             :                 case DI_SUB_AUTHOR:
     982           0 :                     aStr = aName;
     983           0 :                     break;
     984             : 
     985             :                 case DI_SUB_TIME:
     986           0 :                     if (!nFormat)
     987             :                     {
     988             :                         lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
     989           0 :                                                         &pLocalData );
     990           0 :                         aStr = pLocalData->getTime( aDate,
     991           0 :                                                     sal_False, sal_False);
     992             :                     }
     993             :                     else
     994             :                     {
     995             :                         // Numberformatter anwerfen!
     996             :                         double fVal = SwDateTimeField::GetDateTime( GetDoc(),
     997           0 :                                                     aDate);
     998           0 :                         aStr = ExpandValue(fVal, nFormat, nLang);
     999             :                     }
    1000           0 :                     break;
    1001             : 
    1002             :                 case DI_SUB_DATE:
    1003          10 :                     if (!nFormat)
    1004             :                     {
    1005             :                         lcl_GetLocalDataWrapper( nLang, &pAppLocalData,
    1006           0 :                                                  &pLocalData );
    1007           0 :                         aStr = pLocalData->getDate( aDate );
    1008             :                     }
    1009             :                     else
    1010             :                     {
    1011             :                         // Numberformatter anwerfen!
    1012             :                         double fVal = SwDateTimeField::GetDateTime( GetDoc(),
    1013          10 :                                                     aDate);
    1014          10 :                         aStr = ExpandValue(fVal, nFormat, nLang);
    1015             :                     }
    1016          10 :                     break;
    1017             :                 }
    1018          10 :             }
    1019             :         }
    1020          10 :         break;
    1021             :     }
    1022             : 
    1023          10 :     if( pAppLocalData != pLocalData )
    1024           0 :         delete pLocalData;
    1025             : 
    1026          20 :     return aStr;
    1027             : }
    1028             : 
    1029             : // document info field
    1030             : 
    1031           6 : SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, sal_uInt32 nFmt) :
    1032           6 :     SwValueField(pTyp, nFmt), nSubType(nSub)
    1033             : {
    1034           6 :     aName = rName;
    1035           6 :     aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, nFmt, GetLanguage(), aName);
    1036           6 : }
    1037             : 
    1038           0 : SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, const String& rValue, sal_uInt32 nFmt) :
    1039           0 :     SwValueField(pTyp, nFmt), nSubType(nSub)
    1040             : {
    1041           0 :     aName = rName;
    1042           0 :     aContent = rValue;
    1043           0 : }
    1044             : 
    1045             : template<class T>
    1046           0 : static double lcl_TimeToDouble( const T& rTime )
    1047             : {
    1048           0 :     const double fNanoSecondsPerDay = 86400000000000.0;
    1049           0 :     return ((rTime.Hours*3600000)+(rTime.Minutes*60000)+(rTime.Seconds*1000)+(rTime.NanoSeconds)) / fNanoSecondsPerDay;
    1050             : }
    1051             : 
    1052             : template<class D>
    1053           0 : static double lcl_DateToDouble( const D& rDate, const Date& rNullDate )
    1054             : {
    1055           0 :     long nDate = Date::DateToDays( rDate.Day, rDate.Month, rDate.Year );
    1056           0 :     long nNullDate = Date::DateToDays( rNullDate.GetDay(), rNullDate.GetMonth(), rNullDate.GetYear() );
    1057           0 :     return double( nDate - nNullDate );
    1058             : }
    1059             : 
    1060           4 : String SwDocInfoField::Expand() const
    1061             : {
    1062           4 :     if ( ( nSubType & 0xFF ) == DI_CUSTOM )
    1063             :     {
    1064             :         // custom properties currently need special treatment
    1065             :         // We don't have a secure way to detect "real" custom properties in Word import of text
    1066             :         // fields, so we treat *every* unknown property as a custom property, even the "built-in"
    1067             :         // section in Word's document summary information stream as these properties have not been
    1068             :         // inserted when the document summary information was imported, we do it here.
    1069             :         // This approach is still a lot better than the old one to import such fields as
    1070             :         // "user fields" and simple text
    1071           0 :         SwDocShell* pDocShell = GetDoc()->GetDocShell();
    1072           0 :         if( !pDocShell )
    1073           0 :             return aContent;
    1074             :         try
    1075             :         {
    1076           0 :             uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW);
    1077           0 :             uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties());
    1078           0 :             uno::Reference < beans::XPropertySet > xSet( xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
    1079           0 :             uno::Reference < beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo();
    1080             : 
    1081           0 :             uno::Any aAny;
    1082           0 :             if( xSetInfo->hasPropertyByName( aName ) )
    1083           0 :                 aAny = xSet->getPropertyValue( aName );
    1084           0 :             if ( aAny.getValueType() != ::getVoidCppuType() )
    1085             :             {
    1086             :                 // "void" type means that the property has not been inserted until now
    1087           0 :                 if ( !IsFixed() )
    1088             :                 {
    1089             :                     // if the field is "fixed" we don't update it from the property
    1090           0 :                     OUString sVal;
    1091           0 :                     uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(comphelper::getProcessComponentContext()) );
    1092           0 :                     util::Date aDate;
    1093           0 :                     util::DateTime aDateTime;
    1094           0 :                     util::Duration aDuration;
    1095           0 :                     if( aAny >>= aDate)
    1096             :                     {
    1097           0 :                         SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter();
    1098           0 :                         Date* pNullDate = pFormatter->GetNullDate();
    1099           0 :                         sVal = ExpandValue( lcl_DateToDouble<util::Date>( aDate, *pNullDate ), GetFormat(), GetLanguage());
    1100             :                     }
    1101           0 :                     else if( aAny >>= aDateTime )
    1102             :                     {
    1103           0 :                         double fDateTime = lcl_TimeToDouble<util::DateTime>( aDateTime );
    1104           0 :                         SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter();
    1105           0 :                         Date* pNullDate = pFormatter->GetNullDate();
    1106           0 :                         fDateTime += lcl_DateToDouble<util::DateTime>( aDateTime, *pNullDate );
    1107           0 :                         sVal = ExpandValue( fDateTime, GetFormat(), GetLanguage());
    1108             :                     }
    1109           0 :                     else if( aAny >>= aDuration )
    1110             :                     {
    1111           0 :                         String sText = aDuration.Negative ? OUString('-') : OUString('+');
    1112           0 :                         sText += ViewShell::GetShellRes()->sDurationFormat;
    1113           0 :                         sText.SearchAndReplace(OUString("%1"), OUString::number( aDuration.Years ) );
    1114           0 :                         sText.SearchAndReplace(OUString("%2"), OUString::number( aDuration.Months ) );
    1115           0 :                         sText.SearchAndReplace(OUString("%3"), OUString::number( aDuration.Days   ) );
    1116           0 :                         sText.SearchAndReplace(OUString("%4"), OUString::number( aDuration.Hours  ) );
    1117           0 :                         sText.SearchAndReplace(OUString("%5"), OUString::number( aDuration.Minutes) );
    1118           0 :                         sText.SearchAndReplace(OUString("%6"), OUString::number( aDuration.Seconds) );
    1119           0 :                         sVal = sText;
    1120             :                     }
    1121             :                     else
    1122             :                     {
    1123           0 :                         uno::Any aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING );
    1124           0 :                         aNew >>= sVal;
    1125             :                     }
    1126           0 :                     ((SwDocInfoField*)this)->aContent = sVal;
    1127             :                 }
    1128           0 :             }
    1129             :         }
    1130           0 :         catch (uno::Exception&) {}
    1131             :     }
    1132           4 :     else if ( !IsFixed() )
    1133           4 :         ((SwDocInfoField*)this)->aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, GetFormat(), GetLanguage(), aName);
    1134             : 
    1135           4 :     return aContent;
    1136             : }
    1137             : 
    1138           0 : String SwDocInfoField::GetFieldName() const
    1139             : {
    1140           0 :     String aStr(SwFieldType::GetTypeStr(GetTypeId()));
    1141           0 :     aStr += ':';
    1142             : 
    1143           0 :     sal_uInt16 const nSub = nSubType & 0xff;
    1144             : 
    1145           0 :     switch (nSub)
    1146             :     {
    1147             :         case DI_CUSTOM:
    1148           0 :             aStr += aName;
    1149           0 :             break;
    1150             : 
    1151             :         default:
    1152           0 :             aStr += ViewShell::GetShellRes()
    1153           0 :                      ->aDocInfoLst[ nSub - DI_SUBTYPE_BEGIN ];
    1154           0 :             break;
    1155             :     }
    1156           0 :     if (IsFixed())
    1157             :     {
    1158           0 :         aStr += ' ';
    1159           0 :         aStr += ViewShell::GetShellRes()->aFixedStr;
    1160             :     }
    1161           0 :     return aStr;
    1162             : }
    1163             : 
    1164           5 : SwField* SwDocInfoField::Copy() const
    1165             : {
    1166           5 :     SwDocInfoField* pFld = new SwDocInfoField((SwDocInfoFieldType*)GetTyp(), nSubType, aName, GetFormat());
    1167           5 :     pFld->SetAutomaticLanguage(IsAutomaticLanguage());
    1168           5 :     pFld->aContent = aContent;
    1169             : 
    1170           5 :     return pFld;
    1171             : }
    1172             : 
    1173           4 : sal_uInt16 SwDocInfoField::GetSubType() const
    1174             : {
    1175           4 :     return nSubType;
    1176             : }
    1177             : 
    1178           0 : void SwDocInfoField::SetSubType(sal_uInt16 nSub)
    1179             : {
    1180           0 :     nSubType = nSub;
    1181           0 : }
    1182             : 
    1183           1 : void SwDocInfoField::SetLanguage(sal_uInt16 nLng)
    1184             : {
    1185           1 :     if (!GetFormat())
    1186           0 :         SwField::SetLanguage(nLng);
    1187             :     else
    1188           1 :         SwValueField::SetLanguage(nLng);
    1189           1 : }
    1190             : 
    1191           0 : bool SwDocInfoField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    1192             : {
    1193           0 :     switch( nWhichId )
    1194             :     {
    1195             :     case FIELD_PROP_PAR1:
    1196           0 :         rAny <<= OUString(aContent);
    1197           0 :         break;
    1198             : 
    1199             :     case FIELD_PROP_PAR4:
    1200           0 :         rAny <<= OUString(aName);
    1201           0 :         break;
    1202             : 
    1203             :     case FIELD_PROP_USHORT1:
    1204           0 :         rAny  <<= (sal_Int16)aContent.ToInt32();
    1205           0 :         break;
    1206             : 
    1207             :     case FIELD_PROP_BOOL1:
    1208             :         {
    1209           0 :             sal_Bool bVal = 0 != (nSubType & DI_SUB_FIXED);
    1210           0 :             rAny.setValue(&bVal, ::getBooleanCppuType());
    1211             :         }
    1212           0 :         break;
    1213             :     case FIELD_PROP_FORMAT:
    1214           0 :         rAny  <<= (sal_Int32)GetFormat();
    1215           0 :         break;
    1216             : 
    1217             :     case FIELD_PROP_DOUBLE:
    1218             :         {
    1219           0 :             double fVal = GetValue();
    1220           0 :             rAny.setValue(&fVal, ::getCppuType(&fVal));
    1221             :         }
    1222           0 :         break;
    1223             :     case FIELD_PROP_PAR3:
    1224           0 :         rAny <<= OUString(Expand());
    1225           0 :         break;
    1226             :     case FIELD_PROP_BOOL2:
    1227             :         {
    1228           0 :             sal_uInt16 nExtSub = (nSubType & 0xff00) & ~DI_SUB_FIXED;
    1229           0 :             sal_Bool bVal = (nExtSub == DI_SUB_DATE);
    1230           0 :             rAny.setValue(&bVal, ::getBooleanCppuType());
    1231             :         }
    1232           0 :         break;
    1233             :     default:
    1234           0 :         return SwField::QueryValue(rAny, nWhichId);
    1235             :     }
    1236           0 :     return true;
    1237             : }
    1238             : 
    1239           0 : bool SwDocInfoField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    1240             : {
    1241           0 :     sal_Int32 nValue = 0;
    1242           0 :     switch( nWhichId )
    1243             :     {
    1244             :     case FIELD_PROP_PAR1:
    1245           0 :         if( nSubType & DI_SUB_FIXED )
    1246           0 :             ::GetString( rAny, aContent );
    1247           0 :         break;
    1248             : 
    1249             :     case FIELD_PROP_USHORT1:
    1250           0 :         if( nSubType & DI_SUB_FIXED )
    1251             :         {
    1252           0 :             rAny >>= nValue;
    1253           0 :             aContent = OUString::number(nValue);
    1254             :         }
    1255           0 :         break;
    1256             : 
    1257             :     case FIELD_PROP_BOOL1:
    1258           0 :         if(*(sal_Bool*)rAny.getValue())
    1259           0 :             nSubType |= DI_SUB_FIXED;
    1260             :         else
    1261           0 :             nSubType &= ~DI_SUB_FIXED;
    1262           0 :         break;
    1263             :     case FIELD_PROP_FORMAT:
    1264             :         {
    1265           0 :             rAny >>= nValue;
    1266           0 :             if( nValue >= 0)
    1267           0 :                 SetFormat(nValue);
    1268             :         }
    1269           0 :         break;
    1270             : 
    1271             :     case FIELD_PROP_PAR3:
    1272           0 :         ::GetString( rAny, aContent );
    1273           0 :         break;
    1274             :     case FIELD_PROP_BOOL2:
    1275           0 :         nSubType &= 0xf0ff;
    1276           0 :         if(*(sal_Bool*)rAny.getValue())
    1277           0 :             nSubType |= DI_SUB_DATE;
    1278             :         else
    1279           0 :             nSubType |= DI_SUB_TIME;
    1280           0 :         break;
    1281             :     default:
    1282           0 :         return SwField::PutValue(rAny, nWhichId);
    1283             :     }
    1284           0 :     return true;
    1285             : }
    1286             : 
    1287             : // SwHiddenTxtFieldType
    1288             : 
    1289         898 : SwHiddenTxtFieldType::SwHiddenTxtFieldType( sal_Bool bSetHidden )
    1290         898 :     : SwFieldType( RES_HIDDENTXTFLD ), bHidden( bSetHidden )
    1291             : {
    1292         898 : }
    1293             : 
    1294           0 : SwFieldType* SwHiddenTxtFieldType::Copy() const
    1295             : {
    1296           0 :     return new SwHiddenTxtFieldType( bHidden );
    1297             : }
    1298             : 
    1299         811 : void SwHiddenTxtFieldType::SetHiddenFlag( sal_Bool bSetHidden )
    1300             : {
    1301         811 :     if( bHidden != bSetHidden )
    1302             :     {
    1303           3 :         bHidden = bSetHidden;
    1304           3 :         UpdateFlds();       // notify all HiddenTexts
    1305             :     }
    1306         811 : }
    1307             : 
    1308           0 : SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
    1309             :                                     sal_Bool    bConditional,
    1310             :                                     const   String& rCond,
    1311             :                                     const   String& rStr,
    1312             :                                     sal_Bool    bHidden,
    1313             :                                     sal_uInt16  nSub) :
    1314             :     SwField( pFldType ), aCond(rCond), nSubType(nSub),
    1315           0 :     bCanToggle(bConditional), bIsHidden(bHidden), bValid(sal_False)
    1316             : {
    1317           0 :     if(nSubType == TYP_CONDTXTFLD)
    1318             :     {
    1319           0 :         sal_Int32 nPos = 0;
    1320           0 :         aTRUETxt = rStr.GetToken(0, '|', nPos);
    1321             : 
    1322           0 :         if(nPos != -1)
    1323             :         {
    1324           0 :             aFALSETxt = rStr.GetToken(0, '|', nPos);
    1325           0 :             if(nPos != -1)
    1326             :             {
    1327           0 :                 aContent = rStr.GetToken(0, '|', nPos);
    1328           0 :                 bValid = sal_True;
    1329             :             }
    1330             :         }
    1331             :     }
    1332             :     else
    1333           0 :         aTRUETxt = rStr;
    1334           0 : }
    1335             : 
    1336           0 : SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType,
    1337             :                                     const String& rCond,
    1338             :                                     const String& rTrue,
    1339             :                                     const String& rFalse,
    1340             :                                     sal_uInt16 nSub)
    1341             :     : SwField( pFldType ), aTRUETxt(rTrue), aFALSETxt(rFalse), aCond(rCond), nSubType(nSub),
    1342           0 :       bIsHidden(sal_True), bValid(sal_False)
    1343             : {
    1344           0 :     bCanToggle  = aCond.getLength() > 0;
    1345           0 : }
    1346             : 
    1347           0 : String SwHiddenTxtField::Expand() const
    1348             : {
    1349             :     // Type: !Hidden  -> show always
    1350             :     //        Hide    -> evaluate condition
    1351             : 
    1352           0 :     if( TYP_CONDTXTFLD == nSubType )
    1353             :     {
    1354           0 :         if( bValid )
    1355           0 :             return aContent;
    1356             : 
    1357           0 :         if( bCanToggle && !bIsHidden )
    1358           0 :             return aTRUETxt;
    1359             :     }
    1360           0 :     else if( !((SwHiddenTxtFieldType*)GetTyp())->GetHiddenFlag() ||
    1361           0 :         ( bCanToggle && bIsHidden ))
    1362           0 :         return aTRUETxt;
    1363             : 
    1364           0 :     return aFALSETxt;
    1365             : }
    1366             : 
    1367             : /// get current field value and cache it
    1368           0 : void SwHiddenTxtField::Evaluate(SwDoc* pDoc)
    1369             : {
    1370             :     OSL_ENSURE(pDoc, "Wo ist das Dokument Seniore");
    1371             : 
    1372           0 :     if( TYP_CONDTXTFLD == nSubType )
    1373             :     {
    1374           0 :         SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
    1375             : 
    1376           0 :         bValid = sal_False;
    1377           0 :         String sTmpName;
    1378             : 
    1379           0 :         if (bCanToggle && !bIsHidden)
    1380           0 :             sTmpName = aTRUETxt;
    1381             :         else
    1382           0 :             sTmpName = aFALSETxt;
    1383             : 
    1384             :         // Database expressions need to be differnt from normal text. Therefore, normal text is set
    1385             :         // in quotes. If the latter exist they will be removed. If not, check if potential DB name.
    1386             :         // Only if there are two or more dots and no quotes, we assume a database.
    1387           0 :         if(sTmpName.Len() > 1 && sTmpName.GetChar(0) == '\"' &&
    1388           0 :             sTmpName.GetChar((sTmpName.Len() - 1))== '\"')
    1389             :         {
    1390           0 :             aContent = sTmpName.Copy(1, sTmpName.Len() - 2);
    1391           0 :             bValid = sal_True;
    1392             :         }
    1393           0 :         else if(sTmpName.Search('\"') == STRING_NOTFOUND &&
    1394           0 :             comphelper::string::getTokenCount(sTmpName, '.') > 2)
    1395             :         {
    1396           0 :             ::ReplacePoint(sTmpName);
    1397           0 :             if(sTmpName.GetChar(0) == '[' && sTmpName.GetChar(sTmpName.Len()-1) == ']')
    1398             :             {   // remove brackets
    1399           0 :                 sTmpName.Erase(0, 1);
    1400           0 :                 sTmpName.Erase(sTmpName.Len()-1, 1);
    1401             :             }
    1402             : 
    1403           0 :             if( pMgr)
    1404             :             {
    1405           0 :                 String sDBName( GetDBName( sTmpName, pDoc ));
    1406           0 :                 String sDataSource(sDBName.GetToken(0, DB_DELIM));
    1407           0 :                 String sDataTableOrQuery(sDBName.GetToken(1, DB_DELIM));
    1408           0 :                 if( pMgr->IsInMerge() && sDBName.Len() &&
    1409             :                     pMgr->IsDataSourceOpen( sDataSource,
    1410           0 :                                                 sDataTableOrQuery, sal_False))
    1411             :                 {
    1412             :                     double fNumber;
    1413             :                     sal_uInt32 nTmpFormat;
    1414             :                     pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ),
    1415           0 :                         GetLanguage(), aContent, &fNumber, &nTmpFormat );
    1416           0 :                     bValid = sal_True;
    1417             :                 }
    1418           0 :                 else if( sDBName.Len() && sDataSource.Len() &&
    1419           0 :                          sDataTableOrQuery.Len() )
    1420           0 :                     bValid = sal_True;
    1421             :             }
    1422           0 :         }
    1423             :     }
    1424           0 : }
    1425             : 
    1426           0 : String SwHiddenTxtField::GetFieldName() const
    1427             : {
    1428           0 :     String aStr(SwFieldType::GetTypeStr(nSubType));
    1429           0 :     aStr += ' ';
    1430           0 :     aStr += aCond;
    1431           0 :     aStr += ' ';
    1432           0 :     aStr += aTRUETxt;
    1433             : 
    1434           0 :     if (nSubType == TYP_CONDTXTFLD)
    1435             :     {
    1436           0 :         aStr.AppendAscii(" : ");
    1437           0 :         aStr += aFALSETxt;
    1438             :     }
    1439           0 :     return aStr;
    1440             : }
    1441             : 
    1442           0 : SwField* SwHiddenTxtField::Copy() const
    1443             : {
    1444             :     SwHiddenTxtField* pFld =
    1445           0 :         new SwHiddenTxtField((SwHiddenTxtFieldType*)GetTyp(), aCond,
    1446           0 :                               aTRUETxt, aFALSETxt);
    1447           0 :     pFld->bIsHidden = bIsHidden;
    1448           0 :     pFld->bValid    = bValid;
    1449           0 :     pFld->aContent  = aContent;
    1450           0 :     pFld->SetFormat(GetFormat());
    1451           0 :     pFld->nSubType  = nSubType;
    1452           0 :     return pFld;
    1453             : }
    1454             : 
    1455             : /// set condition
    1456           0 : void SwHiddenTxtField::SetPar1(const OUString& rStr)
    1457             : {
    1458           0 :     aCond = rStr;
    1459           0 :     bCanToggle = aCond.getLength() > 0;
    1460           0 : }
    1461             : 
    1462           0 : const OUString& SwHiddenTxtField::GetPar1() const
    1463             : {
    1464           0 :     return aCond;
    1465             : }
    1466             : 
    1467             : /// set True/False text
    1468           0 : void SwHiddenTxtField::SetPar2(const OUString& rStr)
    1469             : {
    1470           0 :     if (nSubType == TYP_CONDTXTFLD)
    1471             :     {
    1472           0 :         sal_Int32 nPos = rStr.indexOf('|');
    1473           0 :         if (nPos == -1)
    1474           0 :             aTRUETxt = rStr;
    1475             :         else
    1476             :         {
    1477           0 :             aTRUETxt = rStr.copy(0, nPos);
    1478           0 :             aFALSETxt = rStr.copy(nPos + 1);
    1479             :         }
    1480             :     }
    1481             :     else
    1482           0 :         aTRUETxt = rStr;
    1483           0 : }
    1484             : 
    1485             : /// get True/False text
    1486           0 : OUString SwHiddenTxtField::GetPar2() const
    1487             : {
    1488           0 :     String aRet(aTRUETxt);
    1489           0 :     if(nSubType == TYP_CONDTXTFLD)
    1490             :     {
    1491           0 :         aRet += '|';
    1492           0 :         aRet += aFALSETxt;
    1493             :     }
    1494           0 :     return aRet;
    1495             : }
    1496             : 
    1497           0 : sal_uInt16 SwHiddenTxtField::GetSubType() const
    1498             : {
    1499           0 :     return nSubType;
    1500             : }
    1501             : 
    1502           0 : bool SwHiddenTxtField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    1503             : {
    1504           0 :     const OUString* pOut = 0;
    1505           0 :     switch( nWhichId )
    1506             :     {
    1507             :     case FIELD_PROP_PAR1:
    1508           0 :         pOut = &aCond;
    1509           0 :         break;
    1510             :     case FIELD_PROP_PAR2:
    1511           0 :         pOut = &aTRUETxt;
    1512           0 :         break;
    1513             :     case FIELD_PROP_PAR3:
    1514           0 :         pOut = &aFALSETxt;
    1515           0 :         break;
    1516             :     case FIELD_PROP_PAR4 :
    1517           0 :         pOut = &aContent;
    1518           0 :     break;
    1519             :     case FIELD_PROP_BOOL1:
    1520             :         {
    1521           0 :             sal_Bool bHidden = bIsHidden;
    1522           0 :             rAny.setValue(&bHidden, ::getBooleanCppuType());
    1523             :         }
    1524           0 :         break;
    1525             :     default:
    1526             :         OSL_FAIL("illegal property");
    1527             :     }
    1528           0 :     if( pOut )
    1529           0 :         rAny <<= *pOut;
    1530           0 :     return true;
    1531             : }
    1532             : 
    1533           0 : bool SwHiddenTxtField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    1534             : {
    1535           0 :     switch( nWhichId )
    1536             :     {
    1537             :     case FIELD_PROP_PAR1:
    1538             :         {
    1539           0 :             OUString sVal;
    1540           0 :             rAny >>= sVal;
    1541           0 :             SetPar1(sVal);
    1542             :         }
    1543           0 :         break;
    1544             :     case FIELD_PROP_PAR2:
    1545           0 :         rAny >>= aTRUETxt;
    1546           0 :         break;
    1547             :     case FIELD_PROP_PAR3:
    1548           0 :         rAny >>= aFALSETxt;
    1549           0 :         break;
    1550             :     case FIELD_PROP_BOOL1:
    1551           0 :         bIsHidden = *(sal_Bool*)rAny.getValue();
    1552           0 :         break;
    1553             :     case FIELD_PROP_PAR4:
    1554           0 :         rAny >>= aContent;
    1555           0 :         bValid = sal_True;
    1556           0 :     break;
    1557             :     default:
    1558             :         OSL_FAIL("illegal property");
    1559             :     }
    1560           0 :     return true;
    1561             : }
    1562             : 
    1563           0 : String SwHiddenTxtField::GetColumnName(const String& rName)
    1564             : {
    1565           0 :     sal_uInt16 nPos = rName.Search(DB_DELIM);
    1566           0 :     if( STRING_NOTFOUND != nPos )
    1567             :     {
    1568           0 :         nPos = rName.Search(DB_DELIM, nPos + 1);
    1569             : 
    1570           0 :         if( STRING_NOTFOUND != nPos )
    1571           0 :             return rName.Copy(nPos + 1);
    1572             :     }
    1573           0 :     return rName;
    1574             : }
    1575             : 
    1576           0 : String SwHiddenTxtField::GetDBName(const String& rName, SwDoc *pDoc)
    1577             : {
    1578           0 :     sal_uInt16 nPos = rName.Search(DB_DELIM);
    1579           0 :     if( STRING_NOTFOUND != nPos )
    1580             :     {
    1581           0 :         nPos = rName.Search(DB_DELIM, nPos + 1);
    1582             : 
    1583           0 :         if( STRING_NOTFOUND != nPos )
    1584           0 :             return rName.Copy( 0, nPos );
    1585             :     }
    1586           0 :     SwDBData aData = pDoc->GetDBData();
    1587           0 :     String sRet = aData.sDataSource;
    1588           0 :     sRet += DB_DELIM;
    1589           0 :     sRet += String(aData.sCommand);
    1590           0 :     return sRet;
    1591             : }
    1592             : 
    1593             : // field type for line height 0
    1594             : 
    1595         898 : SwHiddenParaFieldType::SwHiddenParaFieldType()
    1596         898 :     : SwFieldType( RES_HIDDENPARAFLD )
    1597             : {
    1598         898 : }
    1599             : 
    1600           0 : SwFieldType* SwHiddenParaFieldType::Copy() const
    1601             : {
    1602           0 :     SwHiddenParaFieldType* pTyp = new SwHiddenParaFieldType();
    1603           0 :     return pTyp;
    1604             : }
    1605             : 
    1606             : // field for line height 0
    1607             : 
    1608           0 : SwHiddenParaField::SwHiddenParaField(SwHiddenParaFieldType* pTyp, const String& rStr)
    1609           0 :     : SwField(pTyp), aCond(rStr)
    1610             : {
    1611           0 :     bIsHidden = sal_False;
    1612           0 : }
    1613             : 
    1614           0 : String SwHiddenParaField::Expand() const
    1615             : {
    1616           0 :     return aEmptyStr;
    1617             : }
    1618             : 
    1619           0 : SwField* SwHiddenParaField::Copy() const
    1620             : {
    1621           0 :     SwHiddenParaField* pFld = new SwHiddenParaField((SwHiddenParaFieldType*)GetTyp(), aCond);
    1622           0 :     pFld->bIsHidden = bIsHidden;
    1623             : 
    1624           0 :     return pFld;
    1625             : }
    1626             : 
    1627           0 : bool SwHiddenParaField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    1628             : {
    1629           0 :     switch ( nWhichId )
    1630             :     {
    1631             :     case FIELD_PROP_PAR1:
    1632           0 :         rAny <<= OUString(aCond);
    1633           0 :         break;
    1634             :     case  FIELD_PROP_BOOL1:
    1635             :         {
    1636           0 :             sal_Bool bHidden = bIsHidden;
    1637           0 :             rAny.setValue(&bHidden, ::getBooleanCppuType());
    1638             :         }
    1639           0 :         break;
    1640             : 
    1641             :     default:
    1642             :         OSL_FAIL("illegal property");
    1643             :     }
    1644           0 :     return true;
    1645             : }
    1646             : 
    1647           0 : bool SwHiddenParaField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    1648             : {
    1649           0 :     switch ( nWhichId )
    1650             :     {
    1651             :     case FIELD_PROP_PAR1:
    1652           0 :         rAny >>= aCond;
    1653           0 :         break;
    1654             :     case FIELD_PROP_BOOL1:
    1655           0 :         bIsHidden = *(sal_Bool*)rAny.getValue();
    1656           0 :         break;
    1657             : 
    1658             :     default:
    1659             :         OSL_FAIL("illegal property");
    1660             :     }
    1661           0 :     return true;
    1662             : }
    1663             : 
    1664             : /// set condition
    1665           0 : void SwHiddenParaField::SetPar1(const OUString& rStr)
    1666             : {
    1667           0 :     aCond = rStr;
    1668           0 : }
    1669             : 
    1670           0 : const OUString& SwHiddenParaField::GetPar1() const
    1671             : {
    1672           0 :     return aCond;
    1673             : }
    1674             : 
    1675             : // PostIt field type
    1676             : 
    1677         898 : SwPostItFieldType::SwPostItFieldType(SwDoc *pDoc)
    1678         898 :     : SwFieldType( RES_POSTITFLD ),mpDoc(pDoc)
    1679         898 : {}
    1680             : 
    1681           0 : SwFieldType* SwPostItFieldType::Copy() const
    1682             : {
    1683           0 :     return new SwPostItFieldType(mpDoc);
    1684             : }
    1685             : 
    1686             : // PostIt field
    1687             : 
    1688          70 : SwPostItField::SwPostItField( SwPostItFieldType* pT,
    1689             :         const String& rAuthor, const String& rTxt, const String& rInitials, const String& rName, const DateTime& rDateTime )
    1690          70 :     : SwField( pT ), sTxt( rTxt ), sAuthor( rAuthor ), sInitials( rInitials ), sName( rName ), aDateTime( rDateTime ), mpText(0), m_pTextObject(0)
    1691             : {
    1692          70 : }
    1693             : 
    1694         208 : SwPostItField::~SwPostItField()
    1695             : {
    1696          70 :     if ( m_pTextObject )
    1697             :     {
    1698           4 :         m_pTextObject->DisposeEditSource();
    1699           4 :         m_pTextObject->release();
    1700             :     }
    1701             : 
    1702          70 :     delete mpText;
    1703         138 : }
    1704             : 
    1705          11 : const SwFmtFld* SwPostItField::GetByName(SwDoc* pDoc, const OUString& rName)
    1706             : {
    1707          11 :     const SwFldTypes* pFldTypes = pDoc->GetFldTypes();
    1708          11 :     sal_uInt16 nCount = pFldTypes->size();
    1709         133 :     for (sal_uInt16 nType = 0; nType < nCount; ++nType)
    1710             :     {
    1711         132 :         const SwFieldType *pCurType = (*pFldTypes)[nType];
    1712         132 :         SwIterator<SwFmtFld, SwFieldType> aIter(*pCurType);
    1713         133 :         for (const SwFmtFld* pCurFldFmt = aIter.First(); pCurFldFmt; pCurFldFmt = aIter.Next())
    1714             :         {
    1715             :             // Ignore the field if it's not an annotation or it doesn't have an anchor.
    1716          11 :             if (pCurFldFmt->GetFld()->GetTyp()->Which() != RES_POSTITFLD || !pCurFldFmt->GetTxtFld())
    1717           0 :                 continue;
    1718             : 
    1719          11 :             const SwPostItField* pField = dynamic_cast<const SwPostItField*>(pCurFldFmt->GetFld());
    1720          11 :             if (pField->GetName() == rName)
    1721          10 :                 return pCurFldFmt;
    1722             :         }
    1723         122 :     }
    1724           1 :     return 0;
    1725             : }
    1726             : 
    1727          15 : String SwPostItField::Expand() const
    1728             : {
    1729          15 :     return aEmptyStr;
    1730             : }
    1731             : 
    1732             : 
    1733           0 : String SwPostItField::GetDescription() const
    1734             : {
    1735           0 :     return SW_RES(STR_NOTE);
    1736             : }
    1737             : 
    1738          56 : SwField* SwPostItField::Copy() const
    1739             : {
    1740          56 :     SwPostItField* pRet = new SwPostItField( (SwPostItFieldType*)GetTyp(), sAuthor, sTxt, sInitials, sName,
    1741          56 :                                 aDateTime);
    1742          56 :     if (mpText)
    1743          36 :         pRet->SetTextObject( new OutlinerParaObject(*mpText) );
    1744          56 :     return pRet;
    1745             : }
    1746             : 
    1747             : /// set author
    1748           0 : void SwPostItField::SetPar1(const OUString& rStr)
    1749             : {
    1750           0 :     sAuthor = rStr;
    1751           0 : }
    1752             : 
    1753             : /// get author
    1754          29 : const OUString& SwPostItField::GetPar1() const
    1755             : {
    1756          29 :     return sAuthor;
    1757             : }
    1758             : 
    1759             : /// set the PostIt's text
    1760           8 : void SwPostItField::SetPar2(const OUString& rStr)
    1761             : {
    1762           8 :     sTxt = rStr;
    1763           8 : }
    1764             : 
    1765             : /// get the PostIt's text
    1766           9 : OUString SwPostItField::GetPar2() const
    1767             : {
    1768           9 :     return sTxt;
    1769             : }
    1770             : 
    1771           2 : const OUString& SwPostItField::GetInitials() const
    1772             : {
    1773           2 :     return sInitials;
    1774             : }
    1775             : 
    1776           4 : void SwPostItField::SetName(const OUString& rName)
    1777             : {
    1778           4 :     sName = rName;
    1779           4 : }
    1780             : 
    1781          33 : const OUString& SwPostItField::GetName() const
    1782             : {
    1783          33 :     return sName;
    1784             : }
    1785             : 
    1786          16 : const OutlinerParaObject* SwPostItField::GetTextObject() const
    1787             : {
    1788          16 :     return mpText;
    1789             : }
    1790             : 
    1791          45 : void SwPostItField::SetTextObject( OutlinerParaObject* pText )
    1792             : {
    1793          45 :     delete mpText;
    1794          45 :     mpText = pText;
    1795          45 : }
    1796             : 
    1797           2 : sal_Int32 SwPostItField::GetNumberOfParagraphs() const
    1798             : {
    1799           2 :     return (mpText) ? mpText->Count() : 1;
    1800             : }
    1801             : 
    1802          48 : bool SwPostItField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    1803             : {
    1804          48 :     switch( nWhichId )
    1805             :     {
    1806             :     case FIELD_PROP_PAR1:
    1807           6 :         rAny <<= OUString(sAuthor);
    1808           6 :         break;
    1809             :     case FIELD_PROP_PAR2:
    1810             :         {
    1811           4 :         rAny <<= OUString(sTxt);
    1812           4 :         break;
    1813             :         }
    1814             :     case FIELD_PROP_PAR3:
    1815          13 :         rAny <<= OUString(sInitials);
    1816          13 :         break;
    1817             :     case FIELD_PROP_PAR4:
    1818          13 :         rAny <<= OUString(sName);
    1819          13 :         break;
    1820             :     case FIELD_PROP_TEXT:
    1821             :         {
    1822           6 :             if ( !m_pTextObject )
    1823             :             {
    1824           4 :                 SwPostItFieldType* pGetType = (SwPostItFieldType*)GetTyp();
    1825           4 :                 SwDoc* pDoc = pGetType->GetDoc();
    1826           4 :                 SwTextAPIEditSource* pObj = new SwTextAPIEditSource( pDoc );
    1827           4 :                 const_cast <SwPostItField*> (this)->m_pTextObject = new SwTextAPIObject( pObj );
    1828           4 :                 m_pTextObject->acquire();
    1829             :             }
    1830             : 
    1831           6 :             if ( mpText )
    1832           2 :                 m_pTextObject->SetText( *mpText );
    1833             :             else
    1834           4 :                 m_pTextObject->SetString( sTxt );
    1835             : 
    1836           6 :             uno::Reference < text::XText > xText( m_pTextObject );
    1837           6 :             rAny <<= xText;
    1838           6 :             break;
    1839             :         }
    1840             :     case FIELD_PROP_DATE:
    1841             :         {
    1842           0 :             util::Date aSetDate;
    1843           0 :             aSetDate.Day = aDateTime.GetDay();
    1844           0 :             aSetDate.Month = aDateTime.GetMonth();
    1845           0 :             aSetDate.Year = aDateTime.GetYear();
    1846           0 :             rAny.setValue(&aSetDate, ::getCppuType((util::Date*)0));
    1847             :         }
    1848           0 :         break;
    1849             :     case FIELD_PROP_DATE_TIME:
    1850             :         {
    1851           6 :                 util::DateTime DateTimeValue;
    1852           6 :                 DateTimeValue.NanoSeconds = aDateTime.GetNanoSec();
    1853           6 :                 DateTimeValue.Seconds = aDateTime.GetSec();
    1854           6 :                 DateTimeValue.Minutes = aDateTime.GetMin();
    1855           6 :                 DateTimeValue.Hours = aDateTime.GetHour();
    1856           6 :                 DateTimeValue.Day = aDateTime.GetDay();
    1857           6 :                 DateTimeValue.Month = aDateTime.GetMonth();
    1858           6 :                 DateTimeValue.Year = aDateTime.GetYear();
    1859           6 :                 rAny <<= DateTimeValue;
    1860             :         }
    1861           6 :         break;
    1862             :     default:
    1863             :         OSL_FAIL("illegal property");
    1864             :     }
    1865          48 :     return true;
    1866             : }
    1867             : 
    1868           0 : bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    1869             : {
    1870           0 :     switch( nWhichId )
    1871             :     {
    1872             :     case FIELD_PROP_PAR1:
    1873           0 :         rAny >>= sAuthor;
    1874           0 :         break;
    1875             :     case FIELD_PROP_PAR2:
    1876           0 :         rAny >>= sTxt;
    1877             :         //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string
    1878           0 :         if (mpText)
    1879             :         {
    1880           0 :             delete mpText;
    1881           0 :             mpText = 0;
    1882             :         }
    1883           0 :         break;
    1884             :     case FIELD_PROP_PAR3:
    1885           0 :         rAny >>= sInitials;
    1886           0 :         break;
    1887             :     case FIELD_PROP_PAR4:
    1888           0 :         rAny >>= sName;
    1889           0 :         break;
    1890             :     case FIELD_PROP_TEXT:
    1891             :         OSL_FAIL("Not implemented!");
    1892           0 :         break;
    1893             :     case FIELD_PROP_DATE:
    1894           0 :         if( rAny.getValueType() == ::getCppuType((util::Date*)0) )
    1895             :         {
    1896           0 :             util::Date aSetDate = *(util::Date*)rAny.getValue();
    1897           0 :             aDateTime = Date(aSetDate.Day, aSetDate.Month, aSetDate.Year);
    1898             :         }
    1899           0 :         break;
    1900             :     case FIELD_PROP_DATE_TIME:
    1901             :     {
    1902           0 :         util::DateTime aDateTimeValue;
    1903           0 :         if(!(rAny >>= aDateTimeValue))
    1904           0 :             return sal_False;
    1905           0 :         aDateTime.SetNanoSec(aDateTimeValue.NanoSeconds);
    1906           0 :         aDateTime.SetSec(aDateTimeValue.Seconds);
    1907           0 :         aDateTime.SetMin(aDateTimeValue.Minutes);
    1908           0 :         aDateTime.SetHour(aDateTimeValue.Hours);
    1909           0 :         aDateTime.SetDay(aDateTimeValue.Day);
    1910           0 :         aDateTime.SetMonth(aDateTimeValue.Month);
    1911           0 :         aDateTime.SetYear(aDateTimeValue.Year);
    1912             :     }
    1913           0 :     break;
    1914             :     default:
    1915             :         OSL_FAIL("illegal property");
    1916             :     }
    1917           0 :     return true;
    1918             : }
    1919             : 
    1920             : // extended user information field type
    1921             : 
    1922         898 : SwExtUserFieldType::SwExtUserFieldType()
    1923         898 :     : SwFieldType( RES_EXTUSERFLD )
    1924             : {
    1925         898 : }
    1926             : 
    1927           0 : SwFieldType* SwExtUserFieldType::Copy() const
    1928             : {
    1929           0 :     SwExtUserFieldType* pTyp = new SwExtUserFieldType;
    1930           0 :     return pTyp;
    1931             : }
    1932             : 
    1933           0 : String SwExtUserFieldType::Expand(sal_uInt16 nSub, sal_uInt32 ) const
    1934             : {
    1935           0 :     String aRet;
    1936           0 :     sal_uInt16 nRet = USHRT_MAX;
    1937           0 :     switch(nSub)
    1938             :     {
    1939           0 :     case EU_FIRSTNAME:      nRet = USER_OPT_FIRSTNAME; break;
    1940           0 :     case EU_NAME:           nRet = USER_OPT_LASTNAME;  break;
    1941           0 :     case EU_SHORTCUT:       nRet = USER_OPT_ID; break;
    1942             : 
    1943           0 :     case EU_COMPANY:        nRet = USER_OPT_COMPANY;        break;
    1944           0 :     case EU_STREET:         nRet = USER_OPT_STREET;         break;
    1945           0 :     case EU_TITLE:          nRet = USER_OPT_TITLE;          break;
    1946           0 :     case EU_POSITION:       nRet = USER_OPT_POSITION;       break;
    1947           0 :     case EU_PHONE_PRIVATE:  nRet = USER_OPT_TELEPHONEHOME;    break;
    1948           0 :     case EU_PHONE_COMPANY:  nRet = USER_OPT_TELEPHONEWORK;    break;
    1949           0 :     case EU_FAX:            nRet = USER_OPT_FAX;            break;
    1950           0 :     case EU_EMAIL:          nRet = USER_OPT_EMAIL;          break;
    1951           0 :     case EU_COUNTRY:        nRet = USER_OPT_COUNTRY;        break;
    1952           0 :     case EU_ZIP:            nRet = USER_OPT_ZIP;            break;
    1953           0 :     case EU_CITY:           nRet = USER_OPT_CITY;           break;
    1954           0 :     case EU_STATE:          nRet = USER_OPT_STATE;          break;
    1955           0 :     case EU_FATHERSNAME:    nRet = USER_OPT_FATHERSNAME;    break;
    1956           0 :     case EU_APARTMENT:      nRet = USER_OPT_APARTMENT;      break;
    1957             :     default:             OSL_ENSURE( !this, "Field unknown");
    1958             :     }
    1959           0 :     if( USHRT_MAX != nRet )
    1960             :     {
    1961           0 :         SvtUserOptions&  rUserOpt = SW_MOD()->GetUserOptions();
    1962           0 :         aRet = rUserOpt.GetToken( nRet );
    1963             :     }
    1964           0 :     return aRet;
    1965             : }
    1966             : 
    1967             : // extended user information field
    1968             : 
    1969           0 : SwExtUserField::SwExtUserField(SwExtUserFieldType* pTyp, sal_uInt16 nSubTyp, sal_uInt32 nFmt) :
    1970           0 :     SwField(pTyp, nFmt), nType(nSubTyp)
    1971             : {
    1972           0 :     aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
    1973           0 : }
    1974             : 
    1975           0 : String SwExtUserField::Expand() const
    1976             : {
    1977           0 :     if (!IsFixed())
    1978           0 :         ((SwExtUserField*)this)->aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat());
    1979             : 
    1980           0 :     return aContent;
    1981             : }
    1982             : 
    1983           0 : SwField* SwExtUserField::Copy() const
    1984             : {
    1985           0 :     SwExtUserField* pFld = new SwExtUserField((SwExtUserFieldType*)GetTyp(), nType, GetFormat());
    1986           0 :     pFld->SetExpansion(aContent);
    1987             : 
    1988           0 :     return pFld;
    1989             : }
    1990             : 
    1991           0 : sal_uInt16 SwExtUserField::GetSubType() const
    1992             : {
    1993           0 :     return nType;
    1994             : }
    1995             : 
    1996           0 : void SwExtUserField::SetSubType(sal_uInt16 nSub)
    1997             : {
    1998           0 :     nType = nSub;
    1999           0 : }
    2000             : 
    2001           0 : bool SwExtUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    2002             : {
    2003           0 :     switch( nWhichId )
    2004             :     {
    2005             :     case FIELD_PROP_PAR1:
    2006           0 :         rAny <<= OUString(aContent);
    2007           0 :         break;
    2008             : 
    2009             :     case FIELD_PROP_USHORT1:
    2010             :         {
    2011           0 :             sal_Int16 nTmp = nType;
    2012           0 :             rAny <<= nTmp;
    2013             :         }
    2014           0 :         break;
    2015             :     case FIELD_PROP_BOOL1:
    2016             :         {
    2017           0 :             sal_Bool bTmp = IsFixed();
    2018           0 :             rAny.setValue(&bTmp, ::getBooleanCppuType());
    2019             :         }
    2020           0 :         break;
    2021             :     default:
    2022             :         OSL_FAIL("illegal property");
    2023             :     }
    2024           0 :     return true;
    2025             : }
    2026             : 
    2027           0 : bool SwExtUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    2028             : {
    2029           0 :     switch( nWhichId )
    2030             :     {
    2031             :     case FIELD_PROP_PAR1:
    2032           0 :         ::GetString( rAny, aContent );
    2033           0 :         break;
    2034             : 
    2035             :     case FIELD_PROP_USHORT1:
    2036             :         {
    2037           0 :             sal_Int16 nTmp = 0;
    2038           0 :             rAny >>= nTmp;
    2039           0 :             nType = nTmp;
    2040             :         }
    2041           0 :         break;
    2042             :     case FIELD_PROP_BOOL1:
    2043           0 :         if( *(sal_Bool*)rAny.getValue() )
    2044           0 :             SetFormat(GetFormat() | AF_FIXED);
    2045             :         else
    2046           0 :             SetFormat(GetFormat() & ~AF_FIXED);
    2047           0 :         break;
    2048             :     default:
    2049             :         OSL_FAIL("illegal property");
    2050             :     }
    2051           0 :     return true;
    2052             : }
    2053             : 
    2054             : // field type for relative page numbers
    2055             : 
    2056         898 : SwRefPageSetFieldType::SwRefPageSetFieldType()
    2057         898 :     : SwFieldType( RES_REFPAGESETFLD )
    2058             : {
    2059         898 : }
    2060             : 
    2061           0 : SwFieldType* SwRefPageSetFieldType::Copy() const
    2062             : {
    2063           0 :     return new SwRefPageSetFieldType;
    2064             : }
    2065             : 
    2066             : // overridden since there is nothing to update
    2067           0 : void SwRefPageSetFieldType::Modify( const SfxPoolItem*, const SfxPoolItem * )
    2068             : {
    2069           0 : }
    2070             : 
    2071             : // field for relative page numbers
    2072             : 
    2073           0 : SwRefPageSetField::SwRefPageSetField( SwRefPageSetFieldType* pTyp,
    2074             :                     short nOff, sal_Bool bFlag )
    2075           0 :     : SwField( pTyp ), nOffset( nOff ), bOn( bFlag )
    2076             : {
    2077           0 : }
    2078             : 
    2079           0 : String SwRefPageSetField::Expand() const
    2080             : {
    2081           0 :     return aEmptyStr;
    2082             : }
    2083             : 
    2084           0 : SwField* SwRefPageSetField::Copy() const
    2085             : {
    2086           0 :     return new SwRefPageSetField( (SwRefPageSetFieldType*)GetTyp(), nOffset, bOn );
    2087             : }
    2088             : 
    2089           0 : OUString SwRefPageSetField::GetPar2() const
    2090             : {
    2091           0 :     return OUString::number(GetOffset());
    2092             : }
    2093             : 
    2094           0 : void SwRefPageSetField::SetPar2(const OUString& rStr)
    2095             : {
    2096           0 :     SetOffset( (short) rStr.toInt32() );
    2097           0 : }
    2098             : 
    2099           0 : bool SwRefPageSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    2100             : {
    2101           0 :     switch( nWhichId )
    2102             :     {
    2103             :     case FIELD_PROP_BOOL1:
    2104           0 :         rAny.setValue(&bOn, ::getBooleanCppuType());
    2105           0 :         break;
    2106             :     case FIELD_PROP_USHORT1:
    2107           0 :         rAny <<= (sal_Int16)nOffset;
    2108           0 :         break;
    2109             :     default:
    2110             :         OSL_FAIL("illegal property");
    2111             :     }
    2112           0 :     return true;
    2113             : }
    2114             : 
    2115           0 : bool SwRefPageSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    2116             : {
    2117           0 :     switch( nWhichId )
    2118             :     {
    2119             :     case FIELD_PROP_BOOL1:
    2120           0 :         bOn = *(sal_Bool*)rAny.getValue();
    2121           0 :         break;
    2122             :     case FIELD_PROP_USHORT1:
    2123           0 :         rAny >>=nOffset;
    2124           0 :         break;
    2125             :     default:
    2126             :         OSL_FAIL("illegal property");
    2127             :     }
    2128           0 :     return true;
    2129             : }
    2130             : 
    2131             : // relative page numbers - query field
    2132             : 
    2133         898 : SwRefPageGetFieldType::SwRefPageGetFieldType( SwDoc* pDc )
    2134         898 :     : SwFieldType( RES_REFPAGEGETFLD ), pDoc( pDc ), nNumberingType( SVX_NUM_ARABIC )
    2135             : {
    2136         898 : }
    2137             : 
    2138           0 : SwFieldType* SwRefPageGetFieldType::Copy() const
    2139             : {
    2140           0 :     SwRefPageGetFieldType* pNew = new SwRefPageGetFieldType( pDoc );
    2141           0 :     pNew->nNumberingType = nNumberingType;
    2142           0 :     return pNew;
    2143             : }
    2144             : 
    2145         969 : void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
    2146             : {
    2147             :     // update all GetReference fields
    2148         969 :     if( !pNew && !pOld && GetDepends() )
    2149             :     {
    2150             :         // first collect all SetPageRefFields
    2151           0 :         _SetGetExpFlds aTmpLst;
    2152           0 :         if( MakeSetList( aTmpLst ) )
    2153             :         {
    2154           0 :             SwIterator<SwFmtFld,SwFieldType> aIter( *this );
    2155           0 :             for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
    2156             :                     // update only the GetRef fields
    2157           0 :                     if( pFmtFld->GetTxtFld() )
    2158           0 :                         UpdateField( pFmtFld->GetTxtFld(), aTmpLst );
    2159           0 :         }
    2160             :     }
    2161             : 
    2162             :     // forward to text fields, they "expand" the text
    2163         969 :     NotifyClients( pOld, pNew );
    2164         969 : }
    2165             : 
    2166           0 : sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst )
    2167             : {
    2168           0 :     SwIterator<SwFmtFld,SwFieldType> aIter(*pDoc->GetSysFldType( RES_REFPAGESETFLD));
    2169           0 :     for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
    2170             :     {
    2171             :             // update only the GetRef fields
    2172           0 :             const SwTxtFld* pTFld = pFmtFld->GetTxtFld();
    2173           0 :             if( pTFld )
    2174             :             {
    2175           0 :                 const SwTxtNode& rTxtNd = pTFld->GetTxtNode();
    2176             : 
    2177             :                 // Always the first! (in Tab-Headline, header/footer )
    2178           0 :                 Point aPt;
    2179           0 :                 const SwCntntFrm* pFrm = rTxtNd.getLayoutFrm( rTxtNd.GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
    2180             : 
    2181             :                 _SetGetExpFld* pNew;
    2182             : 
    2183           0 :                 if( !pFrm ||
    2184           0 :                      pFrm->IsInDocBody() ||
    2185             :                     // #i31868#
    2186             :                     // Check if pFrm is not yet connected to the layout.
    2187           0 :                     !pFrm->FindPageFrm() )
    2188             :                 {
    2189             :                     //  create index for determination of the TextNode
    2190           0 :                     SwNodeIndex aIdx( rTxtNd );
    2191           0 :                     pNew = new _SetGetExpFld( aIdx, pTFld );
    2192             :                 }
    2193             :                 else
    2194             :                 {
    2195             :                     //  create index for determination of the TextNode
    2196           0 :                     SwPosition aPos( pDoc->GetNodes().GetEndOfPostIts() );
    2197           0 :                     bool const bResult = GetBodyTxtNode( *pDoc, aPos, *pFrm );
    2198             :                     OSL_ENSURE(bResult, "where is the Field?");
    2199             :                     (void) bResult; // unused in non-debug
    2200             :                     pNew = new _SetGetExpFld( aPos.nNode, pTFld,
    2201           0 :                                                 &aPos.nContent );
    2202             :                 }
    2203             : 
    2204           0 :                 if( !rTmpLst.insert( pNew ).second)
    2205           0 :                     delete pNew;
    2206             :             }
    2207             :     }
    2208             : 
    2209           0 :     return rTmpLst.size();
    2210             : }
    2211             : 
    2212           0 : void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld,
    2213             :                                         _SetGetExpFlds& rSetList )
    2214             : {
    2215           0 :     SwRefPageGetField* pGetFld = (SwRefPageGetField*)pTxtFld->GetFld().GetFld();
    2216           0 :     pGetFld->SetText( aEmptyStr );
    2217             : 
    2218             :     // then search the correct RefPageSet field
    2219           0 :     SwTxtNode* pTxtNode = (SwTxtNode*)&pTxtFld->GetTxtNode();
    2220           0 :     if( pTxtNode->StartOfSectionIndex() >
    2221           0 :         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
    2222             :     {
    2223           0 :         SwNodeIndex aIdx( *pTxtNode );
    2224           0 :         _SetGetExpFld aEndFld( aIdx, pTxtFld );
    2225             : 
    2226           0 :         _SetGetExpFlds::const_iterator itLast = rSetList.lower_bound( &aEndFld );
    2227             : 
    2228           0 :         if( itLast != rSetList.begin() )
    2229             :         {
    2230           0 :             --itLast;
    2231           0 :             const SwTxtFld* pRefTxtFld = (*itLast)->GetFld();
    2232             :             const SwRefPageSetField* pSetFld =
    2233           0 :                         (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld();
    2234           0 :             if( pSetFld->IsOn() )
    2235             :             {
    2236             :                 // determine the correct offset
    2237           0 :                 Point aPt;
    2238           0 :                 const SwCntntFrm* pFrm = pTxtNode->getLayoutFrm( pTxtNode->GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
    2239           0 :                 const SwCntntFrm* pRefFrm = pRefTxtFld->GetTxtNode().getLayoutFrm( pRefTxtFld->GetTxtNode().GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False );
    2240           0 :                 const SwPageFrm* pPgFrm = 0;
    2241           0 :                 sal_uInt16 nDiff = ( pFrm && pRefFrm )
    2242           0 :                         ?   (pPgFrm = pFrm->FindPageFrm())->GetPhyPageNum() -
    2243           0 :                             pRefFrm->FindPageFrm()->GetPhyPageNum() + 1
    2244           0 :                         : 1;
    2245             : 
    2246           0 :                 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
    2247             :                         ? ( !pPgFrm
    2248             :                                 ? (sal_uInt32)SVX_NUM_ARABIC
    2249           0 :                                 : pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() )
    2250           0 :                         : pGetFld->GetFormat();
    2251           0 :                 short nPageNum = static_cast<short>(std::max(0, pSetFld->GetOffset() + (short)nDiff));
    2252           0 :                 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
    2253             :             }
    2254           0 :         }
    2255             :     }
    2256             :     // start formatting
    2257           0 :     ((SwFmtFld&)pTxtFld->GetFld()).ModifyNotification( 0, 0 );
    2258           0 : }
    2259             : 
    2260             : // queries for relative page numbering
    2261             : 
    2262           0 : SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp,
    2263             :                                     sal_uInt32 nFmt )
    2264           0 :     : SwField( pTyp, nFmt )
    2265             : {
    2266           0 : }
    2267             : 
    2268           0 : String SwRefPageGetField::Expand() const
    2269             : {
    2270           0 :     return sTxt;
    2271             : }
    2272             : 
    2273           0 : SwField* SwRefPageGetField::Copy() const
    2274             : {
    2275             :     SwRefPageGetField* pCpy = new SwRefPageGetField(
    2276           0 :                         (SwRefPageGetFieldType*)GetTyp(), GetFormat() );
    2277           0 :     pCpy->SetText( sTxt );
    2278           0 :     return pCpy;
    2279             : }
    2280             : 
    2281           0 : void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm,
    2282             :                                         const SwTxtFld* pFld )
    2283             : {
    2284             :     // only fields in Footer, Header, FootNote, Flys
    2285           0 :     SwTxtNode* pTxtNode = (SwTxtNode*)&pFld->GetTxtNode();
    2286           0 :     SwRefPageGetFieldType* pGetType = (SwRefPageGetFieldType*)GetTyp();
    2287           0 :     SwDoc* pDoc = pGetType->GetDoc();
    2288           0 :     if( pFld->GetTxtNode().StartOfSectionIndex() >
    2289           0 :         pDoc->GetNodes().GetEndOfExtras().GetIndex() )
    2290           0 :         return;
    2291             : 
    2292           0 :     sTxt.Erase();
    2293             : 
    2294             :     OSL_ENSURE( !pFrm->IsInDocBody(), "Flag incorrect, frame is in DocBody" );
    2295             : 
    2296             :     // collect all SetPageRefFields
    2297           0 :     _SetGetExpFlds aTmpLst;
    2298           0 :     if( !pGetType->MakeSetList( aTmpLst ) )
    2299           0 :         return ;
    2300             : 
    2301             :     //  create index for determination of the TextNode
    2302           0 :     SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) );
    2303           0 :     pTxtNode = (SwTxtNode*) GetBodyTxtNode( *pDoc, aPos, *pFrm );
    2304             : 
    2305             :     // If no layout exists, ChangeExpansion is called for header and
    2306             :     // footer lines via layout formatting without existing TxtNode.
    2307           0 :     if(!pTxtNode)
    2308           0 :         return;
    2309             : 
    2310           0 :     _SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent );
    2311             : 
    2312           0 :     _SetGetExpFlds::const_iterator itLast = aTmpLst.lower_bound( &aEndFld );
    2313             : 
    2314           0 :     if( itLast == aTmpLst.begin() )
    2315           0 :         return;        // there is no corresponding set-field in front
    2316           0 :     --itLast;
    2317             : 
    2318           0 :     const SwTxtFld* pRefTxtFld = (*itLast)->GetFld();
    2319             :     const SwRefPageSetField* pSetFld =
    2320           0 :                         (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld();
    2321           0 :     Point aPt;
    2322           0 :     const SwCntntFrm* pRefFrm = pRefTxtFld ? pRefTxtFld->GetTxtNode().getLayoutFrm( pFrm->getRootFrm(), &aPt, 0, sal_False ) : 0;
    2323           0 :     if( pSetFld->IsOn() && pRefFrm )
    2324             :     {
    2325             :         // determine the correct offset
    2326           0 :         const SwPageFrm* pPgFrm = pFrm->FindPageFrm();
    2327           0 :         sal_uInt16 nDiff = pPgFrm->GetPhyPageNum() -
    2328           0 :                             pRefFrm->FindPageFrm()->GetPhyPageNum() + 1;
    2329             : 
    2330           0 :         SwRefPageGetField* pGetFld = (SwRefPageGetField*)pFld->GetFld().GetFld();
    2331           0 :         sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat()
    2332           0 :                             ? pPgFrm->GetPageDesc()->GetNumType().GetNumberingType()
    2333           0 :                             : pGetFld->GetFormat();
    2334           0 :         short nPageNum = static_cast<short>(std::max(0, pSetFld->GetOffset() + (short)nDiff ));
    2335           0 :         pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) );
    2336           0 :     }
    2337             : }
    2338             : 
    2339           0 : bool SwRefPageGetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    2340             : {
    2341           0 :     switch( nWhichId )
    2342             :     {
    2343             :         case FIELD_PROP_USHORT1:
    2344           0 :             rAny <<= (sal_Int16)GetFormat();
    2345           0 :         break;
    2346             :         case FIELD_PROP_PAR1:
    2347           0 :             rAny <<= OUString(sTxt);
    2348           0 :         break;
    2349             :         default:
    2350             :             OSL_FAIL("illegal property");
    2351             :     }
    2352           0 :     return true;
    2353             : }
    2354             : 
    2355           0 : bool SwRefPageGetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    2356             : {
    2357           0 :     switch( nWhichId )
    2358             :     {
    2359             :         case FIELD_PROP_USHORT1:
    2360             :         {
    2361           0 :             sal_Int16 nSet = 0;
    2362           0 :             rAny >>= nSet;
    2363           0 :             if(nSet <= SVX_NUM_PAGEDESC )
    2364           0 :                 SetFormat(nSet);
    2365             :             else {
    2366             :             }
    2367             :         }
    2368           0 :         break;
    2369             :         case FIELD_PROP_PAR1:
    2370             :         {
    2371           0 :             OUString sTmp;
    2372           0 :             rAny >>= sTmp;
    2373           0 :             sTxt = sTmp;
    2374             :         }
    2375           0 :         break;
    2376             :     default:
    2377             :         OSL_FAIL("illegal property");
    2378             :     }
    2379           0 :     return true;
    2380             : }
    2381             : 
    2382             : // field type to jump to and edit
    2383             : 
    2384         898 : SwJumpEditFieldType::SwJumpEditFieldType( SwDoc* pD )
    2385         898 :     : SwFieldType( RES_JUMPEDITFLD ), pDoc( pD ), aDep( this, 0 )
    2386             : {
    2387         898 : }
    2388             : 
    2389           0 : SwFieldType* SwJumpEditFieldType::Copy() const
    2390             : {
    2391           0 :     return new SwJumpEditFieldType( pDoc );
    2392             : }
    2393             : 
    2394           8 : SwCharFmt* SwJumpEditFieldType::GetCharFmt()
    2395             : {
    2396           8 :     SwCharFmt* pFmt = pDoc->GetCharFmtFromPool( RES_POOLCHR_JUMPEDIT );
    2397             : 
    2398             :     // not registered yet?
    2399           8 :     if( !aDep.GetRegisteredIn() )
    2400           2 :         pFmt->Add( &aDep );     // register
    2401             : 
    2402           8 :     return pFmt;
    2403             : }
    2404             : 
    2405          83 : SwJumpEditField::SwJumpEditField( SwJumpEditFieldType* pTyp, sal_uInt32 nForm,
    2406             :                                 const String& rTxt, const String& rHelp )
    2407          83 :     : SwField( pTyp, nForm ), sTxt( rTxt ), sHelp( rHelp )
    2408             : {
    2409          83 : }
    2410             : 
    2411          23 : String SwJumpEditField::Expand() const
    2412             : {
    2413          46 :     return OUStringBuffer().append('<').
    2414          69 :         append(sTxt).append('>').makeStringAndClear();
    2415             : }
    2416             : 
    2417          68 : SwField* SwJumpEditField::Copy() const
    2418             : {
    2419         136 :     return new SwJumpEditField( (SwJumpEditFieldType*)GetTyp(), GetFormat(),
    2420         136 :                                 sTxt, sHelp );
    2421             : }
    2422             : 
    2423             : /// get place holder text
    2424           1 : const OUString& SwJumpEditField::GetPar1() const
    2425             : {
    2426           1 :     return sTxt;
    2427             : }
    2428             : 
    2429             : /// set place holder text
    2430           0 : void SwJumpEditField::SetPar1(const OUString& rStr)
    2431             : {
    2432           0 :     sTxt = rStr;
    2433           0 : }
    2434             : 
    2435             : /// get hint text
    2436           0 : OUString SwJumpEditField::GetPar2() const
    2437             : {
    2438           0 :     return sHelp;
    2439             : }
    2440             : 
    2441             : /// set hint text
    2442           0 : void SwJumpEditField::SetPar2(const OUString& rStr)
    2443             : {
    2444           0 :     sHelp = rStr;
    2445           0 : }
    2446             : 
    2447           0 : bool SwJumpEditField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    2448             : {
    2449           0 :     switch( nWhichId )
    2450             :     {
    2451             :     case FIELD_PROP_USHORT1:
    2452             :         {
    2453             :             sal_Int16 nRet;
    2454           0 :             switch( GetFormat() )
    2455             :             {
    2456           0 :             case JE_FMT_TABLE:  nRet = text::PlaceholderType::TABLE; break;
    2457           0 :             case JE_FMT_FRAME:  nRet = text::PlaceholderType::TEXTFRAME; break;
    2458           0 :             case JE_FMT_GRAPHIC:nRet = text::PlaceholderType::GRAPHIC; break;
    2459           0 :             case JE_FMT_OLE:    nRet = text::PlaceholderType::OBJECT; break;
    2460             :             default:
    2461           0 :                 nRet = text::PlaceholderType::TEXT; break;
    2462             :             }
    2463           0 :             rAny <<= nRet;
    2464             :         }
    2465           0 :         break;
    2466             :     case FIELD_PROP_PAR1 :
    2467           0 :         rAny <<= OUString(sHelp);
    2468           0 :         break;
    2469             :     case FIELD_PROP_PAR2 :
    2470           0 :          rAny <<= OUString(sTxt);
    2471           0 :          break;
    2472             :     default:
    2473             :         OSL_FAIL("illegal property");
    2474             :     }
    2475           0 :     return true;
    2476             : }
    2477             : 
    2478           0 : bool SwJumpEditField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    2479             : {
    2480           0 :     switch( nWhichId )
    2481             :     {
    2482             :     case FIELD_PROP_USHORT1:
    2483             :         {
    2484             :             //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is
    2485             :             //              called with a int32 value! But normally we need
    2486             :             //              here only a int16
    2487           0 :             sal_Int32 nSet = 0;
    2488           0 :             rAny >>= nSet;
    2489           0 :             switch( nSet )
    2490             :             {
    2491           0 :                 case text::PlaceholderType::TEXT     : SetFormat(JE_FMT_TEXT); break;
    2492           0 :                 case text::PlaceholderType::TABLE    : SetFormat(JE_FMT_TABLE); break;
    2493           0 :                 case text::PlaceholderType::TEXTFRAME: SetFormat(JE_FMT_FRAME); break;
    2494           0 :                 case text::PlaceholderType::GRAPHIC  : SetFormat(JE_FMT_GRAPHIC); break;
    2495           0 :                 case text::PlaceholderType::OBJECT   : SetFormat(JE_FMT_OLE); break;
    2496             :             }
    2497             :         }
    2498           0 :         break;
    2499             :     case FIELD_PROP_PAR1 :
    2500           0 :         rAny >>= sHelp;
    2501           0 :         break;
    2502             :     case FIELD_PROP_PAR2 :
    2503           0 :          rAny >>= sTxt;
    2504           0 :          break;
    2505             :     default:
    2506             :         OSL_FAIL("illegal property");
    2507             :     }
    2508           0 :     return true;
    2509             : }
    2510             : 
    2511             : // combined character field type
    2512             : 
    2513         898 : SwCombinedCharFieldType::SwCombinedCharFieldType()
    2514         898 :     : SwFieldType( RES_COMBINED_CHARS )
    2515             : {
    2516         898 : }
    2517             : 
    2518           0 : SwFieldType* SwCombinedCharFieldType::Copy() const
    2519             : {
    2520           0 :     return new SwCombinedCharFieldType;
    2521             : }
    2522             : 
    2523             : // combined character field
    2524             : 
    2525           0 : SwCombinedCharField::SwCombinedCharField( SwCombinedCharFieldType* pFTyp,
    2526             :                                             const String& rChars )
    2527             :     : SwField( pFTyp, 0 ),
    2528           0 :     sCharacters( rChars.Copy( 0, MAX_COMBINED_CHARACTERS ))
    2529             : {
    2530           0 : }
    2531             : 
    2532           0 : String  SwCombinedCharField::Expand() const
    2533             : {
    2534           0 :     return sCharacters;
    2535             : }
    2536             : 
    2537           0 : SwField* SwCombinedCharField::Copy() const
    2538             : {
    2539           0 :     return new SwCombinedCharField( (SwCombinedCharFieldType*)GetTyp(),
    2540           0 :                                         sCharacters );
    2541             : }
    2542             : 
    2543           0 : const OUString& SwCombinedCharField::GetPar1() const
    2544             : {
    2545           0 :     return sCharacters;
    2546             : }
    2547             : 
    2548           0 : void SwCombinedCharField::SetPar1(const OUString& rStr)
    2549             : {
    2550           0 :     sCharacters = rStr.copy(0, std::min<sal_Int32>(rStr.getLength(), MAX_COMBINED_CHARACTERS));
    2551           0 : }
    2552             : 
    2553           0 : bool SwCombinedCharField::QueryValue( uno::Any& rAny,
    2554             :                                         sal_uInt16 nWhichId ) const
    2555             : {
    2556           0 :     switch( nWhichId )
    2557             :     {
    2558             :     case FIELD_PROP_PAR1:
    2559           0 :         rAny <<= OUString( sCharacters );
    2560           0 :         break;
    2561             :     default:
    2562             :         OSL_FAIL("illegal property");
    2563             :     }
    2564           0 :     return true;
    2565             : }
    2566             : 
    2567           0 : bool SwCombinedCharField::PutValue( const uno::Any& rAny,
    2568             :                                         sal_uInt16 nWhichId )
    2569             : {
    2570           0 :     switch( nWhichId )
    2571             :     {
    2572             :         case FIELD_PROP_PAR1:
    2573             :         {
    2574           0 :             OUString sTmp;
    2575           0 :             rAny >>= sTmp;
    2576           0 :             SetPar1(sTmp);
    2577             :         }
    2578           0 :         break;
    2579             :         default:
    2580             :             OSL_FAIL("illegal property");
    2581             :     }
    2582           0 :     return true;
    2583          99 : }
    2584             : 
    2585             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10