LCOV - code coverage report
Current view: top level - sw/source/core/fields - expfld.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 260 659 39.5 %
Date: 2014-04-11 Functions: 40 74 54.1 %
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 <hintids.hxx>
      21             : #include <unotools/collatorwrapper.hxx>
      22             : #include <unotools/charclass.hxx>
      23             : #include <editeng/unolingu.hxx>
      24             : #include <svx/pageitem.hxx>
      25             : #include <editeng/langitem.hxx>
      26             : #include <editeng/fontitem.hxx>
      27             : #include <com/sun/star/text/SetVariableType.hpp>
      28             : #include <unofield.hxx>
      29             : #include <frmfmt.hxx>
      30             : #include <fmtfld.hxx>
      31             : #include <txtfld.hxx>
      32             : #include <fmtanchr.hxx>
      33             : #include <txtftn.hxx>
      34             : #include <doc.hxx>
      35             : #include <layfrm.hxx>
      36             : #include <pagefrm.hxx>
      37             : #include <cntfrm.hxx>
      38             : #include <rootfrm.hxx>
      39             : #include <tabfrm.hxx>
      40             : #include <flyfrm.hxx>
      41             : #include <ftnfrm.hxx>
      42             : #include <rowfrm.hxx>
      43             : #include <expfld.hxx>
      44             : #include <usrfld.hxx>
      45             : #include <ndtxt.hxx>
      46             : #include <calc.hxx>
      47             : #include <pam.hxx>
      48             : #include <docfld.hxx>
      49             : #include <swcache.hxx>
      50             : #include <swtable.hxx>
      51             : #include <breakit.hxx>
      52             : #include <SwStyleNameMapper.hxx>
      53             : #include <unofldmid.h>
      54             : #include <numrule.hxx>
      55             : #include <switerator.hxx>
      56             : 
      57             : using namespace ::com::sun::star;
      58             : using namespace ::com::sun::star::text;
      59             : 
      60         543 : static sal_Int16 lcl_SubTypeToAPI(sal_uInt16 nSubType)
      61             : {
      62         543 :         sal_Int16 nRet = 0;
      63         543 :         switch(nSubType)
      64             :         {
      65             :             case nsSwGetSetExpType::GSE_EXPR:
      66           6 :                 nRet = SetVariableType::VAR;      // 0
      67           6 :                 break;
      68             :             case nsSwGetSetExpType::GSE_SEQ:
      69         534 :                 nRet = SetVariableType::SEQUENCE; // 1
      70         534 :                 break;
      71             :             case nsSwGetSetExpType::GSE_FORMULA:
      72           0 :                 nRet = SetVariableType::FORMULA;  // 2
      73           0 :                 break;
      74             :             case nsSwGetSetExpType::GSE_STRING:
      75           3 :                 nRet = SetVariableType::STRING;   // 3
      76           3 :                 break;
      77             :         }
      78         543 :         return nRet;
      79             : }
      80             : 
      81          29 : static sal_Int32 lcl_APIToSubType(const uno::Any& rAny)
      82             : {
      83          29 :         sal_Int16 nVal = 0;
      84          29 :         rAny >>= nVal;
      85          29 :         sal_Int32 nSet = 0;
      86          29 :         switch(nVal)
      87             :         {
      88           1 :             case SetVariableType::VAR:      nSet = nsSwGetSetExpType::GSE_EXPR;  break;
      89          25 :             case SetVariableType::SEQUENCE: nSet = nsSwGetSetExpType::GSE_SEQ;  break;
      90           0 :             case SetVariableType::FORMULA:  nSet = nsSwGetSetExpType::GSE_FORMULA; break;
      91           3 :             case SetVariableType::STRING:   nSet = nsSwGetSetExpType::GSE_STRING;   break;
      92             :             default:
      93             :                 OSL_FAIL("wrong value");
      94           0 :                 nSet = -1;
      95             :         }
      96          29 :         return nSet;
      97             : }
      98             : 
      99           8 : OUString ReplacePoint( const OUString& rTmpName, bool bWithCommandType )
     100             : {
     101             :     // replace first and last (if bWithCommandType: last two) dot
     102             :     // since table names may contain dots
     103             : 
     104           8 :     sal_Int32 nIndex = rTmpName.lastIndexOf('.');
     105           8 :     if (nIndex<0)
     106             :     {
     107           8 :         return rTmpName;
     108             :     }
     109             : 
     110           0 :     OUString sRes = rTmpName.replaceAt(nIndex, 1, OUString(DB_DELIM));
     111             : 
     112           0 :     if (bWithCommandType)
     113             :     {
     114           0 :         nIndex = sRes.lastIndexOf('.', nIndex);
     115           0 :         if (nIndex<0)
     116             :         {
     117           0 :             return sRes;
     118             :         }
     119           0 :         sRes = sRes.replaceAt(nIndex, 1, OUString(DB_DELIM));
     120             :     }
     121             : 
     122           0 :     nIndex = sRes.indexOf('.');
     123           0 :     if (nIndex>=0)
     124             :     {
     125           0 :         sRes = sRes.replaceAt(nIndex, 1, OUString(DB_DELIM));
     126             :     }
     127           0 :     return sRes;
     128             : }
     129             : 
     130           0 : SwTxtNode* GetFirstTxtNode( const SwDoc& rDoc, SwPosition& rPos,
     131             :                             const SwCntntFrm *pCFrm, Point &rPt )
     132             : {
     133           0 :     SwTxtNode* pTxtNode = 0;
     134           0 :     if ( !pCFrm )
     135             :     {
     136           0 :         const SwNodes& rNodes = rDoc.GetNodes();
     137           0 :         rPos.nNode = *rNodes.GetEndOfContent().StartOfSectionNode();
     138             :         SwCntntNode* pCNd;
     139           0 :         while( 0 != (pCNd = rNodes.GoNext( &rPos.nNode ) ) &&
     140           0 :                 0 == ( pTxtNode = pCNd->GetTxtNode() ) )
     141             :                         ;
     142             :         OSL_ENSURE( pTxtNode, "Where is the 1.TextNode" );
     143           0 :         rPos.nContent.Assign( pTxtNode, 0 );
     144             :     }
     145           0 :     else if ( !pCFrm->IsValid() )
     146             :     {
     147           0 :         pTxtNode = (SwTxtNode*)pCFrm->GetNode();
     148           0 :         rPos.nNode = *pTxtNode;
     149           0 :         rPos.nContent.Assign( pTxtNode, 0 );
     150             :     }
     151             :     else
     152             :     {
     153           0 :         pCFrm->GetCrsrOfst( &rPos, rPt );
     154           0 :         pTxtNode = rPos.nNode.GetNode().GetTxtNode();
     155             :     }
     156           0 :     return pTxtNode;
     157             : }
     158             : 
     159           0 : const SwTxtNode* GetBodyTxtNode( const SwDoc& rDoc, SwPosition& rPos,
     160             :                                 const SwFrm& rFrm )
     161             : {
     162           0 :     const SwLayoutFrm* pLayout = (SwLayoutFrm*)rFrm.GetUpper();
     163           0 :     const SwTxtNode* pTxtNode = 0;
     164             : 
     165           0 :     while( pLayout )
     166             :     {
     167           0 :         if( pLayout->IsFlyFrm() )
     168             :         {
     169             :             // hole das FlyFormat
     170           0 :             SwFrmFmt* pFlyFmt = ((SwFlyFrm*)pLayout)->GetFmt();
     171             :             OSL_ENSURE( pFlyFmt, "kein FlyFormat gefunden, wo steht das Feld" );
     172             : 
     173           0 :             const SwFmtAnchor &rAnchor = pFlyFmt->GetAnchor();
     174             : 
     175           0 :             if( FLY_AT_FLY == rAnchor.GetAnchorId() )
     176             :             {
     177             :                 // the fly needs to be attached somewhere, so ask it
     178           0 :                 pLayout = (SwLayoutFrm*)((SwFlyFrm*)pLayout)->GetAnchorFrm();
     179           0 :                 continue;
     180             :             }
     181           0 :             else if ((FLY_AT_PARA == rAnchor.GetAnchorId()) ||
     182           0 :                      (FLY_AT_CHAR == rAnchor.GetAnchorId()) ||
     183           0 :                      (FLY_AS_CHAR == rAnchor.GetAnchorId()))
     184             :             {
     185             :                 OSL_ENSURE( rAnchor.GetCntntAnchor(), "no valid position" );
     186           0 :                 rPos = *rAnchor.GetCntntAnchor();
     187           0 :                 pTxtNode = rPos.nNode.GetNode().GetTxtNode();
     188           0 :                 if ( FLY_AT_PARA == rAnchor.GetAnchorId() )
     189             :                 {
     190             :                     const_cast<SwTxtNode*>(pTxtNode)->MakeStartIndex(
     191           0 :                             &rPos.nContent );
     192             :                 }
     193             : 
     194             :                 // do not break yet, might be as well in Header/Footer/Footnote/Fly
     195           0 :                 pLayout = ((SwFlyFrm*)pLayout)->GetAnchorFrm()
     196           0 :                             ? ((SwFlyFrm*)pLayout)->GetAnchorFrm()->GetUpper() : 0;
     197           0 :                 continue;
     198             :             }
     199             :             else
     200             :             {
     201             :                 pLayout->FindPageFrm()->GetCntntPosition(
     202           0 :                                                 pLayout->Frm().Pos(), rPos );
     203           0 :                 pTxtNode = rPos.nNode.GetNode().GetTxtNode();
     204             :             }
     205             :         }
     206           0 :         else if( pLayout->IsFtnFrm() )
     207             :         {
     208             :             // get the anchor's node
     209           0 :             const SwTxtFtn* pFtn = ((SwFtnFrm*)pLayout)->GetAttr();
     210           0 :             pTxtNode = &pFtn->GetTxtNode();
     211           0 :             rPos.nNode = *pTxtNode;
     212           0 :             rPos.nContent = *pFtn->GetStart();
     213             :         }
     214           0 :         else if( pLayout->IsHeaderFrm() || pLayout->IsFooterFrm() )
     215             :         {
     216             :             const SwCntntFrm* pCntFrm;
     217           0 :             const SwPageFrm* pPgFrm = pLayout->FindPageFrm();
     218           0 :             if( pLayout->IsHeaderFrm() )
     219             :             {
     220             :                 const SwTabFrm *pTab;
     221           0 :                 if( 0 != ( pCntFrm = pPgFrm->FindFirstBodyCntnt()) &&
     222           0 :                     0 != (pTab = pCntFrm->FindTabFrm()) && pTab->IsFollow() &&
     223           0 :                     pTab->GetTable()->GetRowsToRepeat() > 0 &&
     224           0 :                     pTab->IsInHeadline( *pCntFrm ) )
     225             :                 {
     226             :                     // take the next line
     227           0 :                     const SwLayoutFrm* pRow = pTab->GetFirstNonHeadlineRow();
     228           0 :                     pCntFrm = pRow->ContainsCntnt();
     229             :                 }
     230             :             }
     231             :             else
     232           0 :                 pCntFrm = pPgFrm->FindLastBodyCntnt();
     233             : 
     234           0 :             if( pCntFrm )
     235             :             {
     236           0 :                 pTxtNode = pCntFrm->GetNode()->GetTxtNode();
     237           0 :                 rPos.nNode = *pTxtNode;
     238           0 :                 ((SwTxtNode*)pTxtNode)->MakeEndIndex( &rPos.nContent );
     239             :             }
     240             :             else
     241             :             {
     242           0 :                 Point aPt( pLayout->Frm().Pos() );
     243           0 :                 aPt.Y()++;      // aus dem Header raus
     244           0 :                 pCntFrm = pPgFrm->GetCntntPos( aPt, sal_False, sal_True, sal_False );
     245           0 :                 pTxtNode = GetFirstTxtNode( rDoc, rPos, pCntFrm, aPt );
     246             :             }
     247             :         }
     248             :         else
     249             :         {
     250           0 :             pLayout = pLayout->GetUpper();
     251           0 :             continue;
     252             :         }
     253           0 :         break; // found, so finish loop
     254             :     }
     255           0 :     return pTxtNode;
     256             : }
     257             : 
     258        1852 : SwGetExpFieldType::SwGetExpFieldType(SwDoc* pDc)
     259        1852 :     : SwValueFieldType( pDc, RES_GETEXPFLD )
     260             : {
     261        1852 : }
     262             : 
     263           0 : SwFieldType* SwGetExpFieldType::Copy() const
     264             : {
     265           0 :     return new SwGetExpFieldType(GetDoc());
     266             : }
     267             : 
     268        2356 : void SwGetExpFieldType::Modify( const SfxPoolItem*, const SfxPoolItem* pNew )
     269             : {
     270        2356 :     if( pNew && RES_DOCPOS_UPDATE == pNew->Which() )
     271        2356 :         NotifyClients( 0, pNew );
     272             :     // do not expand anything else
     273        2356 : }
     274             : 
     275           5 : SwGetExpField::SwGetExpField(SwGetExpFieldType* pTyp, const OUString& rFormel,
     276             :                             sal_uInt16 nSub, sal_uLong nFmt)
     277             :     : SwFormulaField( pTyp, nFmt, 0.0 ),
     278             :     bIsInBodyTxt( true ),
     279             :     nSubType(nSub),
     280           5 :     bLateInitialization( false )
     281             : {
     282           5 :     SetFormula( rFormel );
     283           5 : }
     284             : 
     285           2 : OUString SwGetExpField::Expand() const
     286             : {
     287           2 :     if(nSubType & nsSwExtendedSubType::SUB_CMD)
     288           0 :         return GetFormula();
     289             : 
     290           2 :     return sExpand;
     291             : }
     292             : 
     293           0 : OUString SwGetExpField::GetFieldName() const
     294             : {
     295             :     const sal_uInt16 nType = static_cast<sal_uInt16>(
     296           0 :         (nsSwGetSetExpType::GSE_FORMULA & nSubType)
     297             :         ? TYP_FORMELFLD
     298           0 :         : TYP_GETFLD);
     299             : 
     300           0 :     return SwFieldType::GetTypeStr(nType) + " " + GetFormula();
     301             : }
     302             : 
     303           4 : SwField* SwGetExpField::Copy() const
     304             : {
     305           4 :     SwGetExpField *pTmp = new SwGetExpField((SwGetExpFieldType*)GetTyp(),
     306           4 :                                             GetFormula(), nSubType, GetFormat());
     307           4 :     pTmp->SetLanguage(GetLanguage());
     308           4 :     pTmp->SwValueField::SetValue(GetValue());
     309           4 :     pTmp->sExpand       = sExpand;
     310           4 :     pTmp->bIsInBodyTxt  = bIsInBodyTxt;
     311           4 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
     312           4 :     if( bLateInitialization )
     313           0 :         pTmp->SetLateInitialization();
     314             : 
     315           4 :     return pTmp;
     316             : }
     317             : 
     318           0 : void SwGetExpField::ChangeExpansion( const SwFrm& rFrm, const SwTxtFld& rFld )
     319             : {
     320           0 :     if( bIsInBodyTxt ) // only fields in Footer, Header, FootNote, Flys
     321           0 :         return;
     322             : 
     323             :     OSL_ENSURE( !rFrm.IsInDocBody(), "Flag incorrect, frame is in DocBody" );
     324             : 
     325             :     // determine document (or is there an easier way?)
     326           0 :     const SwTxtNode* pTxtNode = &rFld.GetTxtNode();
     327           0 :     SwDoc& rDoc = *(SwDoc*)pTxtNode->GetDoc();
     328             : 
     329             :     // create index for determination of the TextNode
     330           0 :     SwPosition aPos( SwNodeIndex( rDoc.GetNodes() ) );
     331           0 :     pTxtNode = GetBodyTxtNode( rDoc, aPos, rFrm );
     332             : 
     333             :     // If no layout exists, ChangeExpansion is called for header and
     334             :     // footer lines via layout formatting without existing TxtNode.
     335           0 :     if(!pTxtNode)
     336           0 :         return;
     337             :     // #i82544#
     338           0 :     if( bLateInitialization )
     339             :     {
     340           0 :         SwFieldType* pSetExpFld = rDoc.GetFldType(RES_SETEXPFLD, GetFormula(), false);
     341           0 :         if( pSetExpFld )
     342             :         {
     343           0 :             bLateInitialization = false;
     344           0 :             if( !(GetSubType() & nsSwGetSetExpType::GSE_STRING) &&
     345           0 :                 static_cast< SwSetExpFieldType* >(pSetExpFld)->GetType() == nsSwGetSetExpType::GSE_STRING )
     346           0 :             SetSubType( nsSwGetSetExpType::GSE_STRING );
     347             :         }
     348             :     }
     349             : 
     350           0 :     _SetGetExpFld aEndFld( aPos.nNode, &rFld, &aPos.nContent );
     351           0 :     if(GetSubType() & nsSwGetSetExpType::GSE_STRING)
     352             :     {
     353             :         SwHash** ppHashTbl;
     354             :         sal_uInt16 nSize;
     355           0 :         rDoc.FldsToExpand( ppHashTbl, nSize, aEndFld );
     356           0 :         sExpand = LookString( ppHashTbl, nSize, GetFormula() );
     357           0 :         ::DeleteHashTable( ppHashTbl, nSize );
     358             :     }
     359             :     else
     360             :     {
     361             :         // fill calculator with values
     362           0 :         SwCalc aCalc( rDoc );
     363           0 :         rDoc.FldsToCalc(aCalc, aEndFld);
     364             : 
     365             :         // calculate value
     366           0 :         SetValue(aCalc.Calculate(GetFormula()).GetDouble());
     367             : 
     368             :         // analyse based on format
     369           0 :         sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue(
     370           0 :                                 GetValue(), GetFormat(), GetLanguage());
     371           0 :     }
     372             : }
     373             : 
     374           0 : OUString SwGetExpField::GetPar2() const
     375             : {
     376           0 :     return GetFormula();
     377             : }
     378             : 
     379           0 : void SwGetExpField::SetPar2(const OUString& rStr)
     380             : {
     381           0 :     SetFormula(rStr);
     382           0 : }
     383             : 
     384           3 : sal_uInt16 SwGetExpField::GetSubType() const
     385             : {
     386           3 :     return nSubType;
     387             : }
     388             : 
     389           0 : void SwGetExpField::SetSubType(sal_uInt16 nType)
     390             : {
     391           0 :     nSubType = nType;
     392           0 : }
     393             : 
     394           5 : void SwGetExpField::SetLanguage(sal_uInt16 nLng)
     395             : {
     396           5 :     if (nSubType & nsSwExtendedSubType::SUB_CMD)
     397           0 :         SwField::SetLanguage(nLng);
     398             :     else
     399           5 :         SwValueField::SetLanguage(nLng);
     400           5 : }
     401             : 
     402           3 : bool SwGetExpField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     403             : {
     404           3 :     switch( nWhichId )
     405             :     {
     406             :     case FIELD_PROP_DOUBLE:
     407           0 :         rAny <<= GetValue();
     408           0 :         break;
     409             :     case FIELD_PROP_FORMAT:
     410           0 :         rAny <<= (sal_Int32)GetFormat();
     411           0 :         break;
     412             :     case FIELD_PROP_USHORT1:
     413           0 :          rAny <<= (sal_Int16)nSubType;
     414           0 :         break;
     415             :     case FIELD_PROP_PAR1:
     416           1 :          rAny <<= GetFormula();
     417           1 :         break;
     418             :     case FIELD_PROP_SUBTYPE:
     419             :         {
     420           1 :             sal_Int16 nRet = lcl_SubTypeToAPI(GetSubType() & 0xff);
     421           1 :             rAny <<= nRet;
     422             :         }
     423           1 :         break;
     424             :     case FIELD_PROP_BOOL2:
     425             :         {
     426           0 :             sal_Bool bTmp = 0 != (nSubType & nsSwExtendedSubType::SUB_CMD);
     427           0 :             rAny.setValue(&bTmp, ::getBooleanCppuType());
     428             :         }
     429           0 :         break;
     430             :     case FIELD_PROP_PAR4:
     431           1 :         rAny <<= GetExpStr();
     432           1 :         break;
     433             :     default:
     434           0 :         return SwField::QueryValue(rAny, nWhichId);
     435             :     }
     436           3 :     return true;
     437             : }
     438             : 
     439           0 : bool SwGetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     440             : {
     441           0 :     sal_Int32 nTmp = 0;
     442           0 :     switch( nWhichId )
     443             :     {
     444             :     case FIELD_PROP_DOUBLE:
     445           0 :         SwValueField::SetValue(*(double*) rAny.getValue());
     446           0 :         break;
     447             :     case FIELD_PROP_FORMAT:
     448           0 :         rAny >>= nTmp;
     449           0 :         SetFormat(nTmp);
     450           0 :         break;
     451             :     case FIELD_PROP_USHORT1:
     452           0 :          rAny >>= nTmp;
     453           0 :          nSubType = static_cast<sal_uInt16>(nTmp);
     454           0 :         break;
     455             :     case FIELD_PROP_PAR1:
     456             :     {
     457           0 :         OUString sTmp;
     458           0 :         rAny >>= sTmp;
     459           0 :         SetFormula(sTmp);
     460           0 :         break;
     461             :     }
     462             :     case FIELD_PROP_SUBTYPE:
     463           0 :         nTmp = lcl_APIToSubType(rAny);
     464           0 :         if( nTmp >=0 )
     465           0 :             SetSubType( static_cast<sal_uInt16>((GetSubType() & 0xff00) | nTmp));
     466           0 :         break;
     467             :     case FIELD_PROP_BOOL2:
     468           0 :         if(*(sal_Bool*) rAny.getValue())
     469           0 :             nSubType |= nsSwExtendedSubType::SUB_CMD;
     470             :         else
     471           0 :             nSubType &= (~nsSwExtendedSubType::SUB_CMD);
     472           0 :         break;
     473             :     case FIELD_PROP_PAR4:
     474             :     {
     475           0 :         OUString sTmp;
     476           0 :         rAny >>= sTmp;
     477           0 :         ChgExpStr(sTmp);
     478           0 :         break;
     479             :     }
     480             :     default:
     481           0 :         return SwField::PutValue(rAny, nWhichId);
     482             :     }
     483           0 :     return true;
     484             : }
     485             : 
     486        7438 : SwSetExpFieldType::SwSetExpFieldType( SwDoc* pDc, const OUString& rName, sal_uInt16 nTyp )
     487             :     : SwValueFieldType( pDc, RES_SETEXPFLD ),
     488             :     sName( rName ),
     489             :     pOutlChgNd( 0 ),
     490             :     sDelim( "." ),
     491             :     nType(nTyp), nLevel( UCHAR_MAX ),
     492        7438 :     bDeleted( sal_False )
     493             : {
     494        7438 :     if( ( nsSwGetSetExpType::GSE_SEQ | nsSwGetSetExpType::GSE_STRING ) & nType )
     495        7408 :         EnableFormat(sal_False);    // do not use Numberformatter
     496        7438 : }
     497             : 
     498          15 : SwFieldType* SwSetExpFieldType::Copy() const
     499             : {
     500          15 :     SwSetExpFieldType* pNew = new SwSetExpFieldType(GetDoc(), sName, nType);
     501          15 :     pNew->bDeleted = bDeleted;
     502          15 :     pNew->sDelim = sDelim;
     503          15 :     pNew->nLevel = nLevel;
     504             : 
     505          15 :     return pNew;
     506             : }
     507             : 
     508        3833 : OUString SwSetExpFieldType::GetName() const
     509             : {
     510        3833 :     return sName;
     511             : }
     512             : 
     513           0 : void SwSetExpFieldType::Modify( const SfxPoolItem*, const SfxPoolItem* )
     514             : {
     515           0 :     return;     // do not expand further
     516             : }
     517             : 
     518           0 : void SwSetExpFieldType::SetSeqFormat(sal_uLong nFmt)
     519             : {
     520           0 :     SwIterator<SwFmtFld,SwFieldType> aIter(*this);
     521           0 :     for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
     522           0 :         pFmtFld->GetField()->ChangeFormat( nFmt );
     523           0 : }
     524             : 
     525           0 : sal_uLong SwSetExpFieldType::GetSeqFormat()
     526             : {
     527           0 :     if( !GetDepends() )
     528           0 :         return SVX_NUM_ARABIC;
     529             : 
     530           0 :     SwField *pFld = ((SwFmtFld*)GetDepends())->GetField();
     531           0 :     return pFld->GetFormat();
     532             : }
     533             : 
     534          41 : sal_uInt16 SwSetExpFieldType::SetSeqRefNo( SwSetExpField& rFld )
     535             : {
     536          41 :     if( !GetDepends() || !(nsSwGetSetExpType::GSE_SEQ & nType) )
     537           0 :         return USHRT_MAX;
     538             : 
     539             : extern void InsertSort( std::vector<sal_uInt16>& rArr, sal_uInt16 nIdx, sal_uInt16* pInsPos = 0 );
     540          41 :     std::vector<sal_uInt16> aArr;
     541             : 
     542             :     sal_uInt16 n;
     543             : 
     544             :     // check if number is already used and if a new one needs to be created
     545          82 :     SwIterator<SwFmtFld,SwFieldType> aIter( *this );
     546             :     const SwTxtNode* pNd;
     547         291 :     for( SwFmtFld* pF = aIter.First(); pF; pF = aIter.Next() )
     548         795 :         if( pF->GetField() != &rFld && pF->GetTxtFld() &&
     549         422 :             0 != ( pNd = pF->GetTxtFld()->GetpTxtNode() ) &&
     550          86 :             pNd->GetNodes().IsDocNodes() )
     551          86 :             InsertSort( aArr, ((SwSetExpField*)pF->GetField())->GetSeqNumber() );
     552             : 
     553             :     // check first if number already exists
     554          41 :     sal_uInt16 nNum = rFld.GetSeqNumber();
     555          41 :     if( USHRT_MAX != nNum )
     556             :     {
     557          41 :         for( n = 0; n < aArr.size(); ++n )
     558          22 :             if( aArr[ n ] > nNum )
     559           0 :                 return nNum;            // no -> use it
     560          22 :             else if( aArr[ n ] == nNum )
     561          22 :                 break;                  // yes -> create new
     562             : 
     563          41 :         if( n == aArr.size() )
     564          19 :             return nNum;            // no -> use it
     565             :     }
     566             : 
     567             :     // flagged all numbers, so determine the right number
     568         108 :     for( n = 0; n < aArr.size(); ++n )
     569          86 :         if( n != aArr[ n ] )
     570           0 :             break;
     571             : 
     572          22 :     rFld.SetSeqNumber( n );
     573          63 :     return n;
     574             : }
     575             : 
     576           0 : sal_uInt16 SwSetExpFieldType::GetSeqFldList( SwSeqFldList& rList )
     577             : {
     578           0 :     rList.Clear();
     579             : 
     580           0 :     SwIterator<SwFmtFld,SwFieldType> aIter( *this );
     581             :     const SwTxtNode* pNd;
     582           0 :     for( SwFmtFld* pF = aIter.First(); pF; pF = aIter.Next() )
     583           0 :         if( pF->GetTxtFld() &&
     584           0 :             0 != ( pNd = pF->GetTxtFld()->GetpTxtNode() ) &&
     585           0 :             pNd->GetNodes().IsDocNodes() )
     586             :         {
     587             :             _SeqFldLstElem* pNew = new _SeqFldLstElem(
     588             :                     pNd->GetExpandTxt( 0, -1 ),
     589           0 :                     ((SwSetExpField*)pF->GetField())->GetSeqNumber() );
     590           0 :             rList.InsertSort( pNew );
     591             :         }
     592             : 
     593           0 :     return rList.Count();
     594             : }
     595             : 
     596           0 : void SwSetExpFieldType::SetChapter( SwSetExpField& rFld, const SwNode& rNd )
     597             : {
     598           0 :     const SwTxtNode* pTxtNd = rNd.FindOutlineNodeOfLevel( nLevel );
     599           0 :     if( pTxtNd )
     600             :     {
     601           0 :         SwNumRule * pRule = pTxtNd->GetNumRule();
     602             : 
     603           0 :         if (pRule)
     604             :         {
     605             :             // --> OD 2005-11-02 #i51089 - TUNING#
     606           0 :             if ( pTxtNd->GetNum() )
     607             :             {
     608           0 :                 const SwNodeNum & aNum = *(pTxtNd->GetNum());
     609             : 
     610             :                 // only get the number, without pre-/post-fixstrings
     611           0 :                 OUString sNumber( pRule->MakeNumString(aNum, sal_False ));
     612             : 
     613           0 :                 if( !sNumber.isEmpty() )
     614           0 :                     rFld.ChgExpStr( sNumber + sDelim + rFld.GetExpStr() );
     615             :             }
     616             :             else
     617             :             {
     618             :                 OSL_FAIL( "<SwSetExpFieldType::SetChapter(..)> - text node with numbering rule, but without number. This is a serious defect -> inform OD" );
     619             :             }
     620             :         }
     621             :     }
     622           0 : }
     623             : 
     624         621 : bool SwSetExpFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     625             : {
     626         621 :     switch( nWhichId )
     627             :     {
     628             :     case FIELD_PROP_SUBTYPE:
     629             :         {
     630         537 :             sal_Int16 nRet = lcl_SubTypeToAPI(GetType());
     631         537 :             rAny <<= nRet;
     632             :         }
     633         537 :         break;
     634             :     case FIELD_PROP_PAR2:
     635           0 :         rAny <<= GetDelimiter();
     636           0 :         break;
     637             :     case FIELD_PROP_SHORT1:
     638             :         {
     639          84 :             sal_Int8 nRet = nLevel < MAXLEVEL? nLevel : -1;
     640          84 :             rAny <<= nRet;
     641             :         }
     642          84 :         break;
     643             :     default:
     644             :         OSL_FAIL("illegal property");
     645             :     }
     646         621 :     return true;
     647             : }
     648             : 
     649         477 : bool SwSetExpFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     650             : {
     651         477 :     switch( nWhichId )
     652             :     {
     653             :     case FIELD_PROP_SUBTYPE:
     654             :         {
     655          28 :             sal_Int32 nSet = lcl_APIToSubType(rAny);
     656          28 :             if(nSet >=0)
     657          28 :                 SetType(static_cast<sal_uInt16>(nSet));
     658             :         }
     659          28 :         break;
     660             :     case FIELD_PROP_PAR2:
     661             :         {
     662           0 :             OUString sTmp;
     663           0 :             rAny >>= sTmp;
     664           0 :             if( !sTmp.isEmpty() )
     665           0 :                 SetDelimiter( sTmp );
     666             :             else
     667           0 :                 SetDelimiter( " " );
     668             :         }
     669           0 :         break;
     670             :     case FIELD_PROP_SHORT1:
     671             :         {
     672         449 :             sal_Int8 nLvl = 0;
     673         449 :             rAny >>= nLvl;
     674         449 :             if(nLvl < 0 || nLvl >= MAXLEVEL)
     675         449 :                 SetOutlineLvl(UCHAR_MAX);
     676             :             else
     677           0 :                 SetOutlineLvl(nLvl);
     678             :         }
     679         449 :         break;
     680             :     default:
     681             :         OSL_FAIL("illegal property");
     682             :     }
     683         477 :     return true;
     684             : }
     685             : 
     686           0 : bool SwSeqFldList::InsertSort( _SeqFldLstElem* pNew )
     687             : {
     688           0 :     OUStringBuffer aBuf(pNew->sDlgEntry);
     689           0 :     const sal_Int32 nLen = aBuf.getLength();
     690           0 :     for (sal_Int32 i = 0; i < nLen; ++i)
     691             :     {
     692           0 :         if (aBuf[i]<' ')
     693             :         {
     694           0 :             aBuf[i]=' ';
     695             :         }
     696             :     }
     697           0 :     pNew->sDlgEntry = aBuf.makeStringAndClear();
     698             : 
     699             :     sal_uInt16 nPos;
     700           0 :     bool bRet = SeekEntry( *pNew, &nPos );
     701           0 :     if( !bRet )
     702           0 :         maData.insert( maData.begin() + nPos, pNew );
     703           0 :     return bRet;
     704             : }
     705             : 
     706           0 : bool SwSeqFldList::SeekEntry( const _SeqFldLstElem& rNew, sal_uInt16* pP ) const
     707             : {
     708           0 :     sal_uInt16 nO = maData.size(), nM, nU = 0;
     709           0 :     if( nO > 0 )
     710             :     {
     711           0 :         CollatorWrapper & rCaseColl = ::GetAppCaseCollator(),
     712           0 :                         & rColl = ::GetAppCollator();
     713           0 :         const CharClass& rCC = GetAppCharClass();
     714             : 
     715             :         //#59900# Sorting should sort number correctly (e.g. "10" after "9" not after "1")
     716           0 :         const OUString rTmp2 = rNew.sDlgEntry;
     717           0 :         sal_Int32 nFndPos2 = 0;
     718           0 :         const OUString sNum2( rTmp2.getToken( 0, ' ', nFndPos2 ));
     719           0 :         sal_Bool bIsNum2IsNumeric = rCC.isAsciiNumeric( sNum2 );
     720           0 :         sal_Int32 nNum2 = bIsNum2IsNumeric ? sNum2.toInt32() : 0;
     721             : 
     722           0 :         nO--;
     723           0 :         while( nU <= nO )
     724             :         {
     725           0 :             nM = nU + ( nO - nU ) / 2;
     726             : 
     727             :             //#59900# Sorting should sort number correctly (e.g. "10" after "9" not after "1")
     728           0 :             const OUString rTmp1 = maData[nM]->sDlgEntry;
     729           0 :             sal_Int32 nFndPos1 = 0;
     730           0 :             const OUString sNum1( rTmp1.getToken( 0, ' ', nFndPos1 ));
     731             :             sal_Int32 nCmp;
     732             : 
     733           0 :             if( bIsNum2IsNumeric && rCC.isNumeric( sNum1 ) )
     734             :             {
     735           0 :                 sal_Int32 nNum1 = sNum1.toInt32();
     736           0 :                 nCmp = nNum2 - nNum1;
     737           0 :                 if( 0 == nCmp )
     738             :                     nCmp = rCaseColl.compareString( rTmp2.copy( nFndPos2 ),
     739           0 :                                                     rTmp1.copy( nFndPos1 ));
     740             :             }
     741             :             else
     742           0 :                 nCmp = rColl.compareString( rTmp2, rTmp1 );
     743             : 
     744           0 :             if( 0 == nCmp )
     745             :             {
     746           0 :                 if( pP ) *pP = nM;
     747           0 :                 return true;
     748             :             }
     749           0 :             else if( 0 < nCmp )
     750           0 :                 nU = nM + 1;
     751           0 :             else if( nM == 0 )
     752           0 :                 break;
     753             :             else
     754           0 :                 nO = nM - 1;
     755           0 :         }
     756             :     }
     757           0 :     if( pP ) *pP = nU;
     758           0 :     return false;
     759             : }
     760             : 
     761         231 : SwSetExpField::SwSetExpField(SwSetExpFieldType* pTyp, const OUString& rFormel,
     762             :                                         sal_uLong nFmt)
     763             :     : SwFormulaField( pTyp, nFmt, 0.0 ), nSeqNo( USHRT_MAX ),
     764         231 :     nSubType(0)
     765             : {
     766         231 :     SetFormula(rFormel);
     767             :     // ignore SubType
     768         231 :     bInput = sal_False;
     769         231 :     if( IsSequenceFld() )
     770             :     {
     771         214 :         SwValueField::SetValue(1.0);
     772         214 :         if( rFormel.isEmpty() )
     773             :         {
     774           2 :             SetFormula(pTyp->GetName() + "+1");
     775             :         }
     776             :     }
     777         231 : }
     778             : 
     779          91 : OUString SwSetExpField::Expand() const
     780             : {
     781          91 :     if (nSubType & nsSwExtendedSubType::SUB_CMD)
     782             :     {   // we need the CommandString
     783           0 :         return GetTyp()->GetName() + " = " + GetFormula();
     784             :     }
     785          91 :     if(!(nSubType & nsSwExtendedSubType::SUB_INVISIBLE))
     786             :     {   // value is visible
     787          89 :         return sExpand;
     788             :     }
     789           2 :     return OUString();
     790             : }
     791             : 
     792             : /// @return the field name
     793           0 : OUString SwSetExpField::GetFieldName() const
     794             : {
     795           0 :     SwFldTypesEnum const nStrType( (IsSequenceFld())
     796             :                             ? TYP_SEQFLD
     797             :                             : (bInput)
     798             :                                 ? TYP_SETINPFLD
     799           0 :                                 : TYP_SETFLD   );
     800             : 
     801             :     OUString aStr(
     802             :         SwFieldType::GetTypeStr( static_cast<sal_uInt16>(nStrType) )
     803           0 :         + " "
     804           0 :         + GetTyp()->GetName() );
     805             : 
     806             :     // Sequence: without formula
     807           0 :     if (TYP_SEQFLD != nStrType)
     808             :     {
     809           0 :         aStr += " = " + GetFormula();
     810             :     }
     811           0 :     return aStr;
     812             : }
     813             : 
     814         187 : SwField* SwSetExpField::Copy() const
     815             : {
     816         187 :     SwSetExpField *pTmp = new SwSetExpField((SwSetExpFieldType*)GetTyp(),
     817         187 :                                             GetFormula(), GetFormat());
     818         187 :     pTmp->SwValueField::SetValue(GetValue());
     819         187 :     pTmp->sExpand       = sExpand;
     820         187 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
     821         187 :     pTmp->SetLanguage(GetLanguage());
     822         187 :     pTmp->aPText        = aPText;
     823         187 :     pTmp->bInput        = bInput;
     824         187 :     pTmp->nSeqNo        = nSeqNo;
     825         187 :     pTmp->SetSubType(GetSubType());
     826             : 
     827         187 :     return pTmp;
     828             : }
     829             : 
     830         232 : void SwSetExpField::SetSubType(sal_uInt16 nSub)
     831             : {
     832         232 :     ((SwSetExpFieldType*)GetTyp())->SetType(nSub & 0xff);
     833         232 :     nSubType = nSub & 0xff00;
     834             : 
     835             :     OSL_ENSURE( (nSub & 0xff) != 3, "SubType ist illegal!" );
     836         232 : }
     837             : 
     838         359 : sal_uInt16 SwSetExpField::GetSubType() const
     839             : {
     840         359 :     return ((SwSetExpFieldType*)GetTyp())->GetType() | nSubType;
     841             : }
     842             : 
     843           3 : void SwSetExpField::SetValue( const double& rAny )
     844             : {
     845           3 :     SwValueField::SetValue(rAny);
     846             : 
     847           3 :     if( IsSequenceFld() )
     848           0 :         sExpand = FormatNumber( (sal_uInt32)GetValue(), GetFormat() );
     849             :     else
     850           6 :         sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue( rAny,
     851           6 :                                                 GetFormat(), GetLanguage());
     852           3 : }
     853             : 
     854           0 : void SwGetExpField::SetValue( const double& rAny )
     855             : {
     856           0 :     SwValueField::SetValue(rAny);
     857           0 :     sExpand = ((SwValueFieldType*)GetTyp())->ExpandValue( rAny, GetFormat(),
     858           0 :                                                             GetLanguage());
     859           0 : }
     860             : 
     861             : /** Find the index of the reference text following the current field
     862             :  *
     863             :  * @param rFmt
     864             :  * @param rDoc
     865             :  * @param nHint search starting position after the current field (or 0 if default)
     866             :  * @return
     867             :  */
     868           0 : sal_Int32 SwGetExpField::GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc, sal_Int32 nHint)
     869             : {
     870             : 
     871           0 :     const SwTxtFld* pTxtFld = rFmt.GetTxtFld();
     872           0 :     const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
     873             : 
     874           0 :     sal_Int32 nRet = nHint ? nHint : *pTxtFld->GetStart() + 1;
     875           0 :     OUString sNodeText = rTxtNode.GetTxt();
     876             : 
     877           0 :     if(nRet<sNodeText.getLength())
     878             :     {
     879           0 :         sNodeText = sNodeText.copy(nRet);
     880             : 
     881             :         // now check if sNodeText starts with a non-alphanumeric character plus blanks
     882           0 :         sal_uInt16 nSrcpt = g_pBreakIt->GetRealScriptOfText( sNodeText, 0 );
     883             : 
     884             :         static const sal_uInt16 nIds[] =
     885             :         {
     886             :             RES_CHRATR_LANGUAGE, RES_CHRATR_LANGUAGE,
     887             :             RES_CHRATR_FONT, RES_CHRATR_FONT,
     888             :             RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CJK_LANGUAGE,
     889             :             RES_CHRATR_CJK_FONT, RES_CHRATR_CJK_FONT,
     890             :             RES_CHRATR_CTL_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
     891             :             RES_CHRATR_CTL_FONT, RES_CHRATR_CTL_FONT,
     892             :             0, 0
     893             :         };
     894           0 :         SwAttrSet aSet(rDoc.GetAttrPool(), nIds);
     895           0 :         rTxtNode.GetAttr(aSet, nRet, nRet+1);
     896             : 
     897           0 :         if( RTL_TEXTENCODING_SYMBOL != ((SvxFontItem&)aSet.Get(
     898           0 :                 GetWhichOfScript( RES_CHRATR_FONT, nSrcpt )) ).GetCharSet() )
     899             :         {
     900             :             LanguageType eLang = ((SvxLanguageItem&)aSet.Get(
     901           0 :                 GetWhichOfScript( RES_CHRATR_LANGUAGE, nSrcpt )) ).GetLanguage();
     902           0 :             LanguageTag aLanguageTag( eLang);
     903           0 :             CharClass aCC( aLanguageTag);
     904           0 :             sal_Unicode c0 = sNodeText[0];
     905           0 :             sal_Bool bIsAlphaNum = aCC.isAlphaNumeric( sNodeText, 0 );
     906           0 :             if( !bIsAlphaNum ||
     907           0 :                 (c0 == ' ' || c0 == '\t'))
     908             :             {
     909             :                 // ignoring blanks
     910           0 :                 nRet++;
     911           0 :                 const sal_Int32 nLen = sNodeText.getLength();
     912           0 :                 for (sal_Int32 i = 1;
     913           0 :                      i<nLen && (sNodeText[i]==' ' || sNodeText[i]=='\t');
     914             :                      ++i
     915             :                 )
     916           0 :                     ++nRet;
     917           0 :             }
     918           0 :         }
     919             :     }
     920           0 :     return nRet;
     921             : }
     922             : 
     923           1 : OUString SwSetExpField::GetPar1() const
     924             : {
     925           1 :     return ((const SwSetExpFieldType*)GetTyp())->GetName();
     926             : }
     927             : 
     928           0 : OUString SwSetExpField::GetPar2() const
     929             : {
     930           0 :     sal_uInt16 nType = ((SwSetExpFieldType*)GetTyp())->GetType();
     931             : 
     932           0 :     if (nType & nsSwGetSetExpType::GSE_STRING)
     933           0 :         return GetFormula();
     934           0 :     return GetExpandedFormula();
     935             : }
     936             : 
     937           0 : void SwSetExpField::SetPar2(const OUString& rStr)
     938             : {
     939           0 :     sal_uInt16 nType = ((SwSetExpFieldType*)GetTyp())->GetType();
     940             : 
     941           0 :     if( !(nType & nsSwGetSetExpType::GSE_SEQ) || !rStr.isEmpty() )
     942             :     {
     943           0 :         if (nType & nsSwGetSetExpType::GSE_STRING)
     944           0 :             SetFormula(rStr);
     945             :         else
     946           0 :             SetExpandedFormula(rStr);
     947             :     }
     948           0 : }
     949             : 
     950          16 : bool SwSetExpField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     951             : {
     952          16 :     sal_Int32 nTmp32 = 0;
     953          16 :     sal_Int16 nTmp16 = 0;
     954          16 :     switch( nWhichId )
     955             :     {
     956             :     case FIELD_PROP_BOOL2:
     957           0 :         if(*(sal_Bool*)rAny.getValue())
     958           0 :             nSubType &= ~nsSwExtendedSubType::SUB_INVISIBLE;
     959             :         else
     960           0 :             nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
     961           0 :         break;
     962             :     case FIELD_PROP_FORMAT:
     963           2 :         rAny >>= nTmp32;
     964           2 :         SetFormat(nTmp32);
     965           2 :         break;
     966             :     case FIELD_PROP_USHORT2:
     967             :         {
     968           0 :             rAny >>= nTmp16;
     969           0 :             if(nTmp16 <= SVX_NUMBER_NONE )
     970           0 :                 SetFormat(nTmp16);
     971             :             else {
     972             :                 //exception(wrong_value)
     973             :                 ;
     974             :             }
     975             :         }
     976           0 :         break;
     977             :     case FIELD_PROP_USHORT1:
     978           0 :         rAny >>= nTmp16;
     979           0 :         nSeqNo = nTmp16;
     980           0 :         break;
     981             :     case FIELD_PROP_PAR1:
     982             :         {
     983           0 :             OUString sTmp;
     984           0 :             rAny >>= sTmp;
     985           0 :             SetPar1( SwStyleNameMapper::GetUIName( sTmp, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ) );
     986             :         }
     987           0 :         break;
     988             :     case FIELD_PROP_PAR2:
     989             :         {
     990           6 :             OUString uTmp;
     991           6 :             rAny >>= uTmp;
     992             :             //I18N - if the formula contains only "TypeName+1"
     993             :             //and it's one of the initially created sequence fields
     994             :             //then the localized names has to be replaced by a programmatic name
     995          12 :             OUString sMyFormula = SwXFieldMaster::LocalizeFormula(*this, uTmp, sal_False);
     996          12 :             SetFormula( sMyFormula );
     997             :         }
     998           6 :         break;
     999             :     case FIELD_PROP_DOUBLE:
    1000             :         {
    1001           1 :             double fVal = 0.0;
    1002           1 :             rAny >>= fVal;
    1003           1 :             SetValue(fVal);
    1004             :         }
    1005           1 :         break;
    1006             :     case FIELD_PROP_SUBTYPE:
    1007           1 :         nTmp32 = lcl_APIToSubType(rAny);
    1008           1 :         if(nTmp32 >= 0)
    1009           1 :             SetSubType(static_cast<sal_uInt16>((GetSubType() & 0xff00) | nTmp32));
    1010           1 :         break;
    1011             :     case FIELD_PROP_PAR3:
    1012           0 :         rAny >>= aPText;
    1013           0 :         break;
    1014             :     case FIELD_PROP_BOOL3:
    1015           3 :         if(*(sal_Bool*) rAny.getValue())
    1016           0 :             nSubType |= nsSwExtendedSubType::SUB_CMD;
    1017             :         else
    1018           3 :             nSubType &= (~nsSwExtendedSubType::SUB_CMD);
    1019           3 :         break;
    1020             :     case FIELD_PROP_BOOL1:
    1021           0 :         SetInputFlag(*(sal_Bool*) rAny.getValue());
    1022           0 :         break;
    1023             :     case FIELD_PROP_PAR4:
    1024             :         {
    1025           3 :             OUString sTmp;
    1026           3 :             rAny >>= sTmp;
    1027           3 :             ChgExpStr( sTmp );
    1028             :         }
    1029           3 :         break;
    1030             :     default:
    1031           0 :         return SwField::PutValue(rAny, nWhichId);
    1032             :     }
    1033          16 :     return true;
    1034             : }
    1035             : 
    1036          27 : bool SwSetExpField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    1037             : {
    1038          27 :     switch( nWhichId )
    1039             :     {
    1040             :     case FIELD_PROP_BOOL2:
    1041             :         {
    1042           1 :             sal_Bool bVal = 0 == (nSubType & nsSwExtendedSubType::SUB_INVISIBLE);
    1043           1 :             rAny.setValue(&bVal, ::getBooleanCppuType());
    1044             :         }
    1045           1 :         break;
    1046             :     case FIELD_PROP_FORMAT:
    1047           3 :         rAny <<= (sal_Int32)GetFormat();
    1048           3 :         break;
    1049             :     case FIELD_PROP_USHORT2:
    1050           0 :         rAny <<= (sal_Int16)GetFormat();
    1051           0 :         break;
    1052             :     case FIELD_PROP_USHORT1:
    1053           2 :         rAny <<= (sal_Int16)nSeqNo;
    1054           2 :         break;
    1055             :     case FIELD_PROP_PAR1:
    1056           1 :         rAny <<= OUString ( SwStyleNameMapper::GetProgName(GetPar1(), nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL ) );
    1057           1 :         break;
    1058             :     case FIELD_PROP_PAR2:
    1059             :         {
    1060             :             //I18N - if the formula contains only "TypeName+1"
    1061             :             //and it's one of the initially created sequence fields
    1062             :             //then the localized names has to be replaced by a programmatic name
    1063           7 :             OUString sMyFormula = SwXFieldMaster::LocalizeFormula(*this, GetFormula(), sal_True);
    1064           7 :             rAny <<= OUString( sMyFormula );
    1065             :         }
    1066           7 :         break;
    1067             :     case FIELD_PROP_DOUBLE:
    1068           4 :         rAny <<= (double)GetValue();
    1069           4 :         break;
    1070             :     case FIELD_PROP_SUBTYPE:
    1071             :         {
    1072           5 :             sal_Int16 nRet = 0;
    1073           5 :                 nRet = lcl_SubTypeToAPI(GetSubType() & 0xff);
    1074           5 :             rAny <<= nRet;
    1075             :         }
    1076           5 :         break;
    1077             :     case FIELD_PROP_PAR3:
    1078           0 :         rAny <<= OUString( aPText );
    1079           0 :         break;
    1080             :     case FIELD_PROP_BOOL3:
    1081             :         {
    1082           0 :             sal_Bool bTmp = 0 != (nSubType & nsSwExtendedSubType::SUB_CMD);
    1083           0 :             rAny.setValue(&bTmp, ::getBooleanCppuType());
    1084             :         }
    1085           0 :         break;
    1086             :     case FIELD_PROP_BOOL1:
    1087             :         {
    1088           2 :             sal_Bool bTmp = GetInputFlag();
    1089           2 :             rAny.setValue(&bTmp, ::getBooleanCppuType());
    1090             :         }
    1091           2 :         break;
    1092             :     case FIELD_PROP_PAR4:
    1093           0 :         rAny <<= rtl::OUString(GetExpStr());
    1094           0 :         break;
    1095             :     default:
    1096           2 :         return SwField::QueryValue(rAny, nWhichId);
    1097             :     }
    1098          25 :     return true;
    1099             : }
    1100             : 
    1101        1852 : SwInputFieldType::SwInputFieldType( SwDoc* pD )
    1102             :     : SwFieldType( RES_INPUTFLD )
    1103        1852 :     , pDoc( pD )
    1104             : {
    1105        1852 : }
    1106             : 
    1107           0 : SwFieldType* SwInputFieldType::Copy() const
    1108             : {
    1109           0 :     SwInputFieldType* pType = new SwInputFieldType( pDoc );
    1110           0 :     return pType;
    1111             : }
    1112             : 
    1113          14 : SwInputField::SwInputField( SwInputFieldType* pFieldType,
    1114             :                             const OUString& rContent,
    1115             :                             const OUString& rPrompt,
    1116             :                             sal_uInt16 nSub,
    1117             :                             sal_uLong nFmt,
    1118             :                             bool bIsFormField )
    1119             :     : SwField( pFieldType, nFmt, LANGUAGE_SYSTEM, false )
    1120             :     , aContent(rContent)
    1121             :     , aPText(rPrompt)
    1122             :     , nSubType(nSub)
    1123             :     , mbIsFormField( bIsFormField )
    1124          14 :     , mpFmtFld( NULL )
    1125             : {
    1126          14 : }
    1127             : 
    1128          27 : SwInputField::~SwInputField()
    1129             : {
    1130          27 : }
    1131             : 
    1132          12 : void SwInputField::SetFmtFld( SwFmtFld& rFmtFld )
    1133             : {
    1134          12 :     mpFmtFld = &rFmtFld;
    1135          12 : }
    1136             : 
    1137           0 : SwFmtFld* SwInputField::GetFmtFld()
    1138             : {
    1139           0 :     return mpFmtFld;
    1140             : }
    1141             : 
    1142          19 : const OUString& SwInputField::getContent() const
    1143             : {
    1144          19 :     return aContent;
    1145             : }
    1146             : 
    1147           0 : void SwInputField::LockNotifyContentChange()
    1148             : {
    1149           0 :     if ( GetFmtFld() != NULL )
    1150             :     {
    1151           0 :         SwTxtInputFld* pTxtInputFld = dynamic_cast< SwTxtInputFld* >(GetFmtFld()->GetTxtFld());
    1152           0 :         if ( pTxtInputFld != NULL )
    1153             :         {
    1154           0 :             pTxtInputFld->LockNotifyContentChange();
    1155             :         }
    1156             :     }
    1157           0 : }
    1158             : 
    1159           0 : void SwInputField::UnlockNotifyContentChange()
    1160             : {
    1161           0 :     if ( GetFmtFld() != NULL )
    1162             :     {
    1163           0 :         SwTxtInputFld* pTxtInputFld = dynamic_cast< SwTxtInputFld* >(GetFmtFld()->GetTxtFld());
    1164           0 :         if ( pTxtInputFld != NULL )
    1165             :         {
    1166           0 :             pTxtInputFld->UnlockNotifyContentChange();
    1167             :         }
    1168             :     }
    1169           0 : }
    1170             : 
    1171           2 : void SwInputField::applyFieldContent( const OUString& rNewFieldContent )
    1172             : {
    1173           2 :     if ( (nSubType & 0x00ff) == INP_TXT )
    1174             :     {
    1175           2 :         aContent = rNewFieldContent;
    1176             :     }
    1177           0 :     else if( (nSubType & 0x00ff) == INP_USR )
    1178             :     {
    1179             :         SwUserFieldType* pUserTyp = static_cast<SwUserFieldType*>(
    1180           0 :             static_cast<SwInputFieldType*>(GetTyp())->GetDoc()->GetFldType( RES_USERFLD, getContent(), false ) );
    1181           0 :         if( pUserTyp )
    1182             :         {
    1183           0 :             pUserTyp->SetContent( rNewFieldContent );
    1184             : 
    1185             :             // trigger update of the corresponding User Fields and other related Input Fields
    1186             :             {
    1187           0 :                 LockNotifyContentChange();
    1188           0 :                 pUserTyp->UpdateFlds();
    1189           0 :                 UnlockNotifyContentChange();
    1190             :             }
    1191             :         }
    1192             :     }
    1193           2 : }
    1194             : 
    1195           0 : OUString SwInputField::GetFieldName() const
    1196             : {
    1197           0 :     OUString aStr(SwField::GetFieldName());
    1198           0 :     if ((nSubType & 0x00ff) == INP_USR)
    1199             :     {
    1200           0 :         aStr += GetTyp()->GetName() + " " + getContent();
    1201             :     }
    1202           0 :     return aStr;
    1203             : }
    1204             : 
    1205          12 : SwField* SwInputField::Copy() const
    1206             : {
    1207             :     SwInputField* pFld =
    1208             :         new SwInputField(
    1209          12 :             static_cast<SwInputFieldType*>(GetTyp()),
    1210             :             getContent(),
    1211             :             aPText,
    1212          12 :             GetSubType(),
    1213          12 :             GetFormat(),
    1214          36 :             mbIsFormField );
    1215             : 
    1216          12 :     pFld->SetHelp( aHelp );
    1217          12 :     pFld->SetToolTip( aToolTip );
    1218             : 
    1219          12 :     pFld->SetAutomaticLanguage(IsAutomaticLanguage());
    1220          12 :     return pFld;
    1221             : }
    1222             : 
    1223           6 : OUString SwInputField::Expand() const
    1224             : {
    1225           6 :     if((nSubType & 0x00ff) == INP_TXT)
    1226             :     {
    1227           4 :         return getContent();
    1228             :     }
    1229             : 
    1230           2 :     if( (nSubType & 0x00ff) == INP_USR )
    1231             :     {
    1232             :         SwUserFieldType* pUserTyp = static_cast<SwUserFieldType*>(
    1233           0 :             static_cast<SwInputFieldType*>(GetTyp())->GetDoc()->GetFldType( RES_USERFLD, getContent(), false ) );
    1234           0 :         if( pUserTyp )
    1235           0 :             return pUserTyp->GetContent();
    1236             :     }
    1237             : 
    1238           2 :     return OUString();
    1239             : }
    1240             : 
    1241           0 : bool SwInputField::isFormField() const
    1242             : {
    1243             :     return mbIsFormField
    1244           0 :            || !aHelp.isEmpty()
    1245           0 :            || !aToolTip.isEmpty();
    1246             : }
    1247             : 
    1248           3 : bool SwInputField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
    1249             : {
    1250           3 :     switch( nWhichId )
    1251             :     {
    1252             :     case FIELD_PROP_PAR1:
    1253           3 :         rAny <<= getContent();
    1254           3 :         break;
    1255             :     case FIELD_PROP_PAR2:
    1256           0 :         rAny <<= aPText;
    1257           0 :         break;
    1258             :     case FIELD_PROP_PAR3:
    1259           0 :         rAny <<= aHelp;
    1260           0 :         break;
    1261             :     case FIELD_PROP_PAR4:
    1262           0 :         rAny <<= aToolTip;
    1263           0 :         break;
    1264             :     default:
    1265             :         OSL_FAIL("illegal property");
    1266             :     }
    1267           3 :     return true;
    1268             : }
    1269             : 
    1270           1 : bool SwInputField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
    1271             : {
    1272           1 :     switch( nWhichId )
    1273             :     {
    1274             :     case FIELD_PROP_PAR1:
    1275           1 :         rAny >>= aContent;
    1276           1 :         break;
    1277             :     case FIELD_PROP_PAR2:
    1278           0 :         rAny >>= aPText;
    1279           0 :         break;
    1280             :     case FIELD_PROP_PAR3:
    1281           0 :         rAny >>= aHelp;
    1282           0 :         break;
    1283             :     case FIELD_PROP_PAR4:
    1284           0 :         rAny >>= aToolTip;
    1285           0 :         break;
    1286             :     default:
    1287             :         OSL_FAIL("illegal property");
    1288             :     }
    1289           1 :     return true;
    1290             : }
    1291             : 
    1292             : /// set condition
    1293           0 : void SwInputField::SetPar1(const OUString& rStr)
    1294             : {
    1295           0 :     aContent = rStr;
    1296           0 : }
    1297             : 
    1298           0 : OUString SwInputField::GetPar1() const
    1299             : {
    1300           0 :     return getContent();
    1301             : }
    1302             : 
    1303           0 : void SwInputField::SetPar2(const OUString& rStr)
    1304             : {
    1305           0 :     aPText = rStr;
    1306           0 : }
    1307             : 
    1308           0 : OUString SwInputField::GetPar2() const
    1309             : {
    1310           0 :     return aPText;
    1311             : }
    1312             : 
    1313          13 : void SwInputField::SetHelp(const OUString & rStr)
    1314             : {
    1315          13 :     aHelp = rStr;
    1316          13 : }
    1317             : 
    1318           0 : OUString SwInputField::GetHelp() const
    1319             : {
    1320           0 :     return aHelp;
    1321             : }
    1322             : 
    1323          13 : void SwInputField::SetToolTip(const OUString & rStr)
    1324             : {
    1325          13 :     aToolTip = rStr;
    1326          13 : }
    1327             : 
    1328           0 : OUString SwInputField::GetToolTip() const
    1329             : {
    1330           0 :     return aToolTip;
    1331             : }
    1332             : 
    1333          12 : sal_uInt16 SwInputField::GetSubType() const
    1334             : {
    1335          12 :     return nSubType;
    1336             : }
    1337             : 
    1338           0 : void SwInputField::SetSubType(sal_uInt16 nSub)
    1339             : {
    1340           0 :     nSubType = nSub;
    1341           0 : }
    1342             : 
    1343             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10