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

Generated by: LCOV version 1.10