LCOV - code coverage report
Current view: top level - sw/source/core/fields - authfld.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 173 341 50.7 %
Date: 2014-04-11 Functions: 20 36 55.6 %
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 <comphelper/string.hxx>
      22             : #include <editeng/unolingu.hxx>
      23             : #include <editeng/langitem.hxx>
      24             : #include <swtypes.hxx>
      25             : #include <tools/resid.hxx>
      26             : #include <comcore.hrc>
      27             : #include <authfld.hxx>
      28             : #include <expfld.hxx>
      29             : #include <pam.hxx>
      30             : #include <cntfrm.hxx>
      31             : #include <tox.hxx>
      32             : #include <txmsrt.hxx>
      33             : #include <doctxm.hxx>
      34             : #include <fmtfld.hxx>
      35             : #include <txtfld.hxx>
      36             : #include <ndtxt.hxx>
      37             : #include <doc.hxx>
      38             : #include <unofldmid.h>
      39             : #include <unoprnms.hxx>
      40             : #include <switerator.hxx>
      41             : #include <unomid.h>
      42             : 
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star::beans;
      45             : using namespace ::com::sun::star::lang;
      46             : 
      47           0 : SwAuthEntry::SwAuthEntry(const SwAuthEntry& rCopy)
      48           0 :     : nRefCount(0)
      49             : {
      50           0 :     for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
      51           0 :         aAuthFields[i] = rCopy.aAuthFields[i];
      52           0 : }
      53             : 
      54           9 : sal_Bool    SwAuthEntry::operator==(const SwAuthEntry& rComp)
      55             : {
      56           9 :     for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
      57           9 :         if(aAuthFields[i] != rComp.aAuthFields[i])
      58           9 :             return sal_False;
      59           0 :     return sal_True;
      60             : }
      61             : 
      62          37 : SwAuthorityFieldType::SwAuthorityFieldType(SwDoc* pDoc)
      63             :     : SwFieldType( RES_AUTHORITY ),
      64             :     m_pDoc(pDoc),
      65             :     m_DataArr(),
      66             :     m_SortKeyArr(3),
      67             :     m_cPrefix('['),
      68             :     m_cSuffix(']'),
      69             :     m_bIsSequence(sal_False),
      70             :     m_bSortByDocument(sal_True),
      71          37 :     m_eLanguage(::GetAppLanguage())
      72             : {
      73          37 : }
      74             : 
      75          54 : SwAuthorityFieldType::~SwAuthorityFieldType()
      76             : {
      77          54 : }
      78             : 
      79          17 : SwFieldType*    SwAuthorityFieldType::Copy()  const
      80             : {
      81          17 :     return new SwAuthorityFieldType(m_pDoc);
      82             : }
      83             : 
      84         136 : void    SwAuthorityFieldType::RemoveField(sal_IntPtr nHandle)
      85             : {
      86             : #if OSL_DEBUG_LEVEL > 0
      87             :     bool bRemoved = false;
      88             : #endif
      89         158 :     for(sal_uInt16 j = 0; j < m_DataArr.size(); j++)
      90             :     {
      91         158 :         SwAuthEntry* pTemp = &m_DataArr[j];
      92         158 :         sal_IntPtr nRet = (sal_IntPtr)(void*)pTemp;
      93         158 :         if(nRet == nHandle)
      94             :         {
      95             : #if OSL_DEBUG_LEVEL > 0
      96             :             bRemoved = true;
      97             : #endif
      98         136 :             pTemp->RemoveRef();
      99         136 :             if(!pTemp->GetRefCount())
     100             :             {
     101          52 :                 m_DataArr.erase(m_DataArr.begin() + j);
     102             :                 //re-generate positions of the fields
     103          52 :                 DelSequenceArray();
     104             :             }
     105         136 :             break;
     106             :         }
     107             :     }
     108             : #if OSL_DEBUG_LEVEL > 0
     109             :     OSL_ENSURE(bRemoved, "Field unknown" );
     110             : #endif
     111         136 : }
     112             : 
     113          52 : sal_IntPtr SwAuthorityFieldType::AddField(const OUString& rFieldContents)
     114             : {
     115          52 :     sal_IntPtr nRet = 0;
     116          52 :     SwAuthEntry* pEntry = new SwAuthEntry;
     117        1664 :     for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i )
     118             :         pEntry->SetAuthorField( (ToxAuthorityField)i,
     119        1612 :                         rFieldContents.getToken( i, TOX_STYLE_DELIMITER ));
     120             : 
     121          61 :     for(sal_uInt16 j = 0; j < m_DataArr.size() && pEntry; j++)
     122             :     {
     123           9 :         SwAuthEntry* pTemp = &m_DataArr[j];
     124           9 :         if(*pTemp == *pEntry)
     125             :         {
     126           0 :             DELETEZ(pEntry);
     127           0 :             nRet = (sal_IntPtr)(void*)pTemp;
     128           0 :             pTemp->AddRef();
     129             :         }
     130             :     }
     131             :     //if it is a new Entry - insert
     132          52 :     if(pEntry)
     133             :     {
     134          52 :         nRet = (sal_IntPtr)(void*)pEntry;
     135          52 :         pEntry->AddRef();
     136          52 :         m_DataArr.push_back(pEntry);
     137             :         //re-generate positions of the fields
     138          52 :         DelSequenceArray();
     139             :     }
     140          52 :     return nRet;
     141             : }
     142             : 
     143          84 : sal_Bool SwAuthorityFieldType::AddField(sal_IntPtr nHandle)
     144             : {
     145          84 :     sal_Bool bRet = sal_False;
     146          97 :     for( sal_uInt16 j = 0; j < m_DataArr.size(); j++ )
     147             :     {
     148          97 :         SwAuthEntry* pTemp = &m_DataArr[j];
     149          97 :         sal_IntPtr nTmp = (sal_IntPtr)(void*)pTemp;
     150          97 :         if( nTmp == nHandle )
     151             :         {
     152          84 :             bRet = sal_True;
     153          84 :             pTemp->AddRef();
     154             :             //re-generate positions of the fields
     155          84 :             DelSequenceArray();
     156          84 :             break;
     157             :         }
     158             :     }
     159             :     OSL_ENSURE(bRet, "::AddField(sal_IntPtr) failed");
     160          84 :     return bRet;
     161             : }
     162             : 
     163         112 : const SwAuthEntry*  SwAuthorityFieldType::GetEntryByHandle(sal_IntPtr nHandle) const
     164             : {
     165         112 :     const SwAuthEntry* pRet = 0;
     166         131 :     for(sal_uInt16 j = 0; j < m_DataArr.size(); j++)
     167             :     {
     168         131 :         const SwAuthEntry* pTemp = &m_DataArr[j];
     169         131 :         sal_IntPtr nTmp = (sal_IntPtr)(void*)pTemp;
     170         131 :         if( nTmp == nHandle )
     171             :         {
     172         112 :             pRet = pTemp;
     173         112 :             break;
     174             :         }
     175             :     }
     176             :     OSL_ENSURE( pRet, "invalid Handle" );
     177         112 :     return pRet;
     178             : }
     179             : 
     180           0 : void SwAuthorityFieldType::GetAllEntryIdentifiers(
     181             :     std::vector<OUString>& rToFill )const
     182             : {
     183           0 :     for(sal_uInt16 j = 0; j < m_DataArr.size(); j++)
     184             :     {
     185           0 :         const SwAuthEntry* pTemp = &m_DataArr[j];
     186           0 :         rToFill.push_back(pTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER));
     187             :     }
     188           0 : }
     189             : 
     190           0 : const SwAuthEntry*  SwAuthorityFieldType::GetEntryByIdentifier(
     191             :                                 const OUString& rIdentifier)const
     192             : {
     193           0 :     const SwAuthEntry* pRet = 0;
     194           0 :     for( sal_uInt16 j = 0; j < m_DataArr.size(); ++j )
     195             :     {
     196           0 :         const SwAuthEntry* pTemp = &m_DataArr[j];
     197           0 :         if( rIdentifier == pTemp->GetAuthorField( AUTH_FIELD_IDENTIFIER ))
     198             :         {
     199           0 :             pRet = pTemp;
     200           0 :             break;
     201             :         }
     202             :     }
     203           0 :     return pRet;
     204             : }
     205             : 
     206           0 : bool SwAuthorityFieldType::ChangeEntryContent(const SwAuthEntry* pNewEntry)
     207             : {
     208           0 :     bool bChanged = false;
     209           0 :     for( sal_uInt16 j = 0; j < m_DataArr.size(); ++j )
     210             :     {
     211           0 :         SwAuthEntry* pTemp = &m_DataArr[j];
     212           0 :         if(pTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER) ==
     213             :                     pNewEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER))
     214             :         {
     215           0 :             for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
     216             :                 pTemp->SetAuthorField((ToxAuthorityField) i,
     217           0 :                     pNewEntry->GetAuthorField((ToxAuthorityField)i));
     218           0 :             bChanged = true;
     219           0 :             break;
     220             :         }
     221             :     }
     222           0 :     return bChanged;
     223             : }
     224             : 
     225             : /// appends a new entry (if new) and returns the array position
     226           0 : sal_uInt16  SwAuthorityFieldType::AppendField( const SwAuthEntry& rInsert )
     227             : {
     228           0 :     sal_uInt16 nRet = 0;
     229           0 :     for( nRet = 0; nRet < m_DataArr.size(); ++nRet )
     230             :     {
     231           0 :         SwAuthEntry* pTemp = &m_DataArr[ nRet ];
     232           0 :         if( *pTemp == rInsert )
     233             :         {
     234           0 :             break;
     235             :             //ref count unchanged
     236             :         }
     237             :     }
     238             : 
     239             :     //if it is a new Entry - insert
     240           0 :     if( nRet == m_DataArr.size() )
     241           0 :         m_DataArr.push_back( new SwAuthEntry( rInsert ) );
     242             : 
     243           0 :     return nRet;
     244             : }
     245             : 
     246           0 : sal_IntPtr SwAuthorityFieldType::GetHandle(sal_uInt16 nPos)
     247             : {
     248           0 :     sal_IntPtr nRet = 0;
     249           0 :     if( nPos < m_DataArr.size() )
     250             :     {
     251           0 :         SwAuthEntry* pTemp = &m_DataArr[nPos];
     252           0 :         nRet = (sal_IntPtr)(void*)pTemp;
     253             :     }
     254           0 :     return nRet;
     255             : }
     256             : 
     257           0 : sal_uInt16  SwAuthorityFieldType::GetSequencePos(sal_IntPtr nHandle)
     258             : {
     259             :     //find the field in a sorted array of handles,
     260             : #if OSL_DEBUG_LEVEL > 0
     261             :     bool bCurrentFieldWithoutTextNode = false;
     262             : #endif
     263           0 :     if(!m_SequArr.empty() && m_SequArr.size() != m_DataArr.size())
     264           0 :         DelSequenceArray();
     265           0 :     if(m_SequArr.empty())
     266             :     {
     267           0 :         SwTOXSortTabBases aSortArr;
     268           0 :         SwIterator<SwFmtFld,SwFieldType> aIter( *this );
     269             : 
     270           0 :         SwTOXInternational aIntl(m_eLanguage, 0, m_sSortAlgorithm);
     271             : 
     272           0 :         for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() )
     273             :         {
     274           0 :             const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
     275           0 :             if(!pTxtFld || !pTxtFld->GetpTxtNode())
     276             :             {
     277             : #if OSL_DEBUG_LEVEL > 0
     278             :                 if(nHandle == ((SwAuthorityField*)pFmtFld->GetField())->GetHandle())
     279             :                     bCurrentFieldWithoutTextNode = true;
     280             : #endif
     281           0 :                 continue;
     282             :             }
     283           0 :             const SwTxtNode& rFldTxtNode = pTxtFld->GetTxtNode();
     284           0 :             SwPosition aFldPos(rFldTxtNode);
     285           0 :             SwDoc& rDoc = *(SwDoc*)rFldTxtNode.GetDoc();
     286           0 :             SwCntntFrm *pFrm = rFldTxtNode.getLayoutFrm( rDoc.GetCurrentLayout() );
     287           0 :             const SwTxtNode* pTxtNode = 0;
     288           0 :             if(pFrm && !pFrm->IsInDocBody())
     289           0 :                 pTxtNode = GetBodyTxtNode( rDoc, aFldPos, *pFrm );
     290             :             //if no text node could be found or the field is in the document
     291             :             //body the directly available text node will be used
     292           0 :             if(!pTxtNode)
     293           0 :                 pTxtNode = &rFldTxtNode;
     294           0 :             if (!pTxtNode->GetTxt().isEmpty() &&
     295           0 :                 pTxtNode->getLayoutFrm( rDoc.GetCurrentLayout() ) &&
     296           0 :                 pTxtNode->GetNodes().IsDocNodes() )
     297             :             {
     298             :                 SwTOXAuthority* pNew = new SwTOXAuthority( *pTxtNode,
     299           0 :                                                             *pFmtFld, aIntl );
     300             : 
     301           0 :                 for(short i = 0; i < (short)aSortArr.size(); ++i)
     302             :                 {
     303           0 :                     SwTOXSortTabBase* pOld = aSortArr[i];
     304           0 :                     if(*pOld == *pNew)
     305             :                     {
     306             :                         //only the first occurrence in the document
     307             :                         //has to be in the array
     308           0 :                         if(*pOld < *pNew)
     309           0 :                             DELETEZ(pNew);
     310             :                         else // remove the old content
     311             :                         {
     312           0 :                             aSortArr.erase(aSortArr.begin() + i);
     313           0 :                             delete pOld;
     314             :                         }
     315           0 :                         break;
     316             :                     }
     317             :                 }
     318             :                 //if it still exists - insert at the correct position
     319           0 :                 if(pNew)
     320             :                 {
     321             :                     short j;
     322             : 
     323           0 :                     for( j = 0; j < (short)aSortArr.size(); ++j)
     324             :                     {
     325           0 :                         SwTOXSortTabBase* pOld = aSortArr[j];
     326           0 :                         if(*pNew < *pOld)
     327           0 :                             break;
     328             :                     }
     329           0 :                     aSortArr.insert(aSortArr.begin() + j, pNew);
     330             :                 }
     331             :             }
     332           0 :         }
     333             : 
     334           0 :         for(sal_uInt16 i = 0; i < aSortArr.size(); i++)
     335             :         {
     336           0 :             const SwTOXSortTabBase& rBase = *aSortArr[i];
     337           0 :             SwFmtFld& rFmtFld = ((SwTOXAuthority&)rBase).GetFldFmt();
     338           0 :             SwAuthorityField* pAFld = (SwAuthorityField*)rFmtFld.GetField();
     339           0 :             m_SequArr.push_back(pAFld->GetHandle());
     340             :         }
     341           0 :         for (SwTOXSortTabBases::const_iterator it = aSortArr.begin(); it != aSortArr.end(); ++it)
     342           0 :             delete *it;
     343           0 :         aSortArr.clear();
     344             :     }
     345             :     //find nHandle
     346           0 :     sal_uInt16 nRet = 0;
     347           0 :     for(sal_uInt16 i = 0; i < m_SequArr.size(); ++i)
     348             :     {
     349           0 :         if(m_SequArr[i] == nHandle)
     350             :         {
     351           0 :             nRet = i + 1;
     352           0 :             break;
     353             :         }
     354             :     }
     355             : #if OSL_DEBUG_LEVEL > 0
     356             :     OSL_ENSURE(bCurrentFieldWithoutTextNode || nRet, "Handle not found");
     357             : #endif
     358           0 :     return nRet;
     359             : }
     360             : 
     361           7 : bool SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const
     362             : {
     363           7 :     switch( nWhichId )
     364             :     {
     365             :     case FIELD_PROP_PAR1:
     366             :     case FIELD_PROP_PAR2:
     367             :         {
     368           2 :             OUString sVal;
     369           2 :             sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix;
     370           2 :             if(uRet)
     371           2 :                 sVal = OUString(uRet);
     372           2 :             rVal <<= sVal;
     373             :         }
     374           2 :         break;
     375             :     case FIELD_PROP_PAR3:
     376           1 :         rVal <<= GetSortAlgorithm();
     377           1 :         break;
     378             : 
     379             :     case FIELD_PROP_BOOL1:
     380             :     case FIELD_PROP_BOOL2:
     381             :         {
     382           2 :             sal_Bool bVal = FIELD_PROP_BOOL1 == nWhichId ? m_bIsSequence: m_bSortByDocument;
     383           2 :             rVal.setValue(&bVal, ::getBooleanCppuType());
     384             :         }
     385           2 :         break;
     386             : 
     387             :     case FIELD_PROP_LOCALE:
     388           1 :         rVal <<= LanguageTag(GetLanguage()).getLocale();
     389           1 :         break;
     390             : 
     391             :     case FIELD_PROP_PROP_SEQ:
     392             :         {
     393           1 :             Sequence<PropertyValues> aRet(m_SortKeyArr.size());
     394           1 :             PropertyValues* pValues = aRet.getArray();
     395           1 :             for(sal_uInt16 i = 0; i < m_SortKeyArr.size(); i++)
     396             :             {
     397           0 :                 const SwTOXSortKey* pKey = &m_SortKeyArr[i];
     398           0 :                 pValues[i].realloc(2);
     399           0 :                 PropertyValue* pValue = pValues[i].getArray();
     400           0 :                 pValue[0].Name = UNO_NAME_SORT_KEY;
     401           0 :                 pValue[0].Value <<= sal_Int16(pKey->eField);
     402           0 :                 pValue[1].Name = UNO_NAME_IS_SORT_ASCENDING;
     403           0 :                 pValue[1].Value.setValue(&pKey->bSortAscending, ::getBooleanCppuType());
     404             :             }
     405           1 :             rVal <<= aRet;
     406             :         }
     407           1 :         break;
     408             :     default:
     409             :         OSL_FAIL("illegal property");
     410             :     }
     411           7 :     return true;
     412             : }
     413             : 
     414          14 : bool    SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId )
     415             : {
     416          14 :     bool bRet = true;
     417          14 :     switch( nWhichId )
     418             :     {
     419             :     case FIELD_PROP_PAR1:
     420             :     case FIELD_PROP_PAR2:
     421             :     {
     422           4 :         OUString sTmp;
     423           4 :         rAny >>= sTmp;
     424           4 :         const sal_Unicode uSet = !sTmp.isEmpty() ? sTmp[0] : 0;
     425           4 :         if( FIELD_PROP_PAR1 == nWhichId )
     426           2 :             m_cPrefix = uSet;
     427             :         else
     428           2 :             m_cSuffix = uSet;
     429             :     }
     430           4 :     break;
     431             :     case FIELD_PROP_PAR3:
     432             :     {
     433           2 :         OUString sTmp;
     434           2 :         rAny >>= sTmp;
     435           2 :         SetSortAlgorithm(sTmp);
     436           2 :         break;
     437             :     }
     438             :     case FIELD_PROP_BOOL1:
     439           2 :         m_bIsSequence = *(sal_Bool*)rAny.getValue();
     440           2 :         break;
     441             :     case FIELD_PROP_BOOL2:
     442           2 :         m_bSortByDocument = *(sal_Bool*)rAny.getValue();
     443           2 :         break;
     444             : 
     445             :     case FIELD_PROP_LOCALE:
     446             :         {
     447           2 :             com::sun::star::lang::Locale aLocale;
     448           2 :             if( (bRet = rAny >>= aLocale ))
     449           2 :                 SetLanguage( LanguageTag::convertToLanguageType( aLocale ));
     450             :         }
     451           2 :         break;
     452             : 
     453             :     case FIELD_PROP_PROP_SEQ:
     454             :         {
     455           2 :             Sequence<PropertyValues> aSeq;
     456           2 :             if( (bRet = rAny >>= aSeq) )
     457             :             {
     458           2 :                 m_SortKeyArr.clear();
     459           2 :                 const PropertyValues* pValues = aSeq.getConstArray();
     460           2 :                 for(sal_Int32 i = 0; i < aSeq.getLength() && i < USHRT_MAX / 4; i++)
     461             :                 {
     462           0 :                     const PropertyValue* pValue = pValues[i].getConstArray();
     463           0 :                     SwTOXSortKey* pSortKey = new SwTOXSortKey;
     464           0 :                     for(sal_Int32 j = 0; j < pValues[i].getLength(); j++)
     465             :                     {
     466           0 :                         if(pValue[j].Name == UNO_NAME_SORT_KEY)
     467             :                         {
     468           0 :                             sal_Int16 nVal = -1; pValue[j].Value >>= nVal;
     469           0 :                             if(nVal >= 0 && nVal < AUTH_FIELD_END)
     470           0 :                                 pSortKey->eField = (ToxAuthorityField) nVal;
     471             :                             else
     472           0 :                                 bRet = false;
     473             :                         }
     474           0 :                         else if(pValue[j].Name == UNO_NAME_IS_SORT_ASCENDING)
     475             :                         {
     476           0 :                             pSortKey->bSortAscending = *(sal_Bool*)pValue[j].Value.getValue();
     477             :                         }
     478             :                     }
     479           0 :                     m_SortKeyArr.push_back(pSortKey);
     480             :                 }
     481           2 :             }
     482             :         }
     483           2 :         break;
     484             :     default:
     485             :         OSL_FAIL("illegal property");
     486             :     }
     487          14 :     return bRet;
     488             : }
     489             : 
     490           0 : void SwAuthorityFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
     491             : {
     492             :     //re-generate positions of the fields
     493           0 :     DelSequenceArray();
     494           0 :     NotifyClients( pOld, pNew );
     495           0 : }
     496             : 
     497           0 : sal_uInt16 SwAuthorityFieldType::GetSortKeyCount() const
     498             : {
     499           0 :     return m_SortKeyArr.size();
     500             : }
     501             : 
     502           0 : const SwTOXSortKey*  SwAuthorityFieldType::GetSortKey(sal_uInt16 nIdx) const
     503             : {
     504           0 :     const SwTOXSortKey* pRet = 0;
     505           0 :     if(m_SortKeyArr.size() > nIdx)
     506           0 :         pRet = &m_SortKeyArr[nIdx];
     507             :     OSL_ENSURE(pRet, "Sort key not found");
     508           0 :     return pRet;
     509             : }
     510             : 
     511           0 : void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey aKeys[])
     512             : {
     513           0 :     m_SortKeyArr.clear();
     514           0 :     for(sal_uInt16 i = 0; i < nKeyCount; i++)
     515           0 :         if(aKeys[i].eField < AUTH_FIELD_END)
     516           0 :             m_SortKeyArr.push_back(new SwTOXSortKey(aKeys[i]));
     517           0 : }
     518             : 
     519          18 : SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
     520             :                                     const OUString& rFieldContents )
     521             :     : SwField(pInitType),
     522          18 :     m_nTempSequencePos( -1 )
     523             : {
     524          18 :     m_nHandle = pInitType->AddField( rFieldContents );
     525          18 : }
     526             : 
     527          84 : SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
     528             :                                                 sal_IntPtr nSetHandle )
     529             :     : SwField( pInitType ),
     530             :     m_nHandle( nSetHandle ),
     531          84 :     m_nTempSequencePos( -1 )
     532             : {
     533          84 :     pInitType->AddField( m_nHandle );
     534          84 : }
     535             : 
     536         306 : SwAuthorityField::~SwAuthorityField()
     537             : {
     538         102 :     ((SwAuthorityFieldType* )GetTyp())->RemoveField(m_nHandle);
     539         204 : }
     540             : 
     541           0 : OUString SwAuthorityField::Expand() const
     542             : {
     543           0 :     return ConditionalExpand(AUTH_FIELD_IDENTIFIER);
     544             : }
     545             : 
     546          60 : OUString SwAuthorityField::ConditionalExpand(ToxAuthorityField eField) const
     547             : {
     548          60 :     SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
     549          60 :     OUString sRet;
     550          60 :     if(pAuthType->GetPrefix() && eField != AUTH_FIELD_TITLE)
     551          54 :         sRet = OUString(pAuthType->GetPrefix());
     552             : 
     553          60 :     if( pAuthType->IsSequence() )
     554             :     {
     555           0 :        if(!pAuthType->GetDoc()->IsExpFldsLocked())
     556           0 :            m_nTempSequencePos = pAuthType->GetSequencePos( m_nHandle );
     557           0 :        if( m_nTempSequencePos >= 0 )
     558           0 :            sRet += OUString::number( m_nTempSequencePos );
     559             :     }
     560             :     else
     561             :     {
     562          60 :         const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle(m_nHandle);
     563             :         //TODO: Expand to: identifier, number sequence, ...
     564          60 :         if(pEntry)
     565          60 :             sRet += pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER);
     566             :     }
     567          60 :     if(pAuthType->GetSuffix())
     568          60 :         sRet += OUString(pAuthType->GetSuffix());
     569          60 :     return sRet;
     570             : }
     571             : 
     572          84 : SwField* SwAuthorityField::Copy() const
     573             : {
     574          84 :     SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
     575          84 :     return new SwAuthorityField(pAuthType, m_nHandle);
     576             : }
     577             : 
     578           0 : OUString SwAuthorityField::GetFieldText(ToxAuthorityField eField) const
     579             : {
     580           0 :     SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
     581           0 :     const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle( m_nHandle );
     582           0 :     return pEntry->GetAuthorField( eField );
     583             : }
     584             : 
     585           0 : void    SwAuthorityField::SetPar1(const OUString& rStr)
     586             : {
     587           0 :     SwAuthorityFieldType* pInitType = (SwAuthorityFieldType* )GetTyp();
     588           0 :     pInitType->RemoveField(m_nHandle);
     589           0 :     m_nHandle = pInitType->AddField(rStr);
     590           0 : }
     591             : 
     592           0 : OUString SwAuthorityField::GetDescription() const
     593             : {
     594           0 :     return SW_RES(STR_AUTHORITY_ENTRY);
     595             : }
     596             : 
     597             : const char* aFieldNames[] =
     598             : {
     599             :     "Identifier",
     600             :     "BibiliographicType",
     601             :     "Address",
     602             :     "Annote",
     603             :     "Author",
     604             :     "Booktitle",
     605             :     "Chapter",
     606             :     "Edition",
     607             :     "Editor",
     608             :     "Howpublished",
     609             :     "Institution",
     610             :     "Journal",
     611             :     "Month",
     612             :     "Note",
     613             :     "Number",
     614             :     "Organizations",
     615             :     "Pages",
     616             :     "Publisher",
     617             :     "School",
     618             :     "Series",
     619             :     "Title",
     620             :     "Report_Type",
     621             :     "Volume",
     622             :     "Year",
     623             :     "URL",
     624             :     "Custom1",
     625             :     "Custom2",
     626             :     "Custom3",
     627             :     "Custom4",
     628             :     "Custom5",
     629             :     "ISBN"
     630             : };
     631             : 
     632          18 : bool    SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const
     633             : {
     634          18 :     if(!GetTyp())
     635           0 :         return false;
     636          18 :     const SwAuthEntry* pAuthEntry = ((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle);
     637          18 :     if(!pAuthEntry)
     638           0 :         return false;
     639          18 :     Sequence <PropertyValue> aRet(AUTH_FIELD_END);
     640          18 :     PropertyValue* pValues = aRet.getArray();
     641         576 :     for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++)
     642             :     {
     643         558 :         pValues[i].Name = OUString::createFromAscii(aFieldNames[i]);
     644         558 :         const OUString sField = pAuthEntry->GetAuthorField((ToxAuthorityField) i);
     645         558 :         if(i == AUTH_FIELD_AUTHORITY_TYPE)
     646          18 :             pValues[i].Value <<= sal_Int16(sField.toInt32());
     647             :         else
     648         540 :             pValues[i].Value <<= sField;
     649         558 :     }
     650          18 :     rAny <<= aRet;
     651             :     /* FIXME: it is weird that we always return false here */
     652          18 :     return false;
     653             : }
     654             : 
     655         574 : static sal_Int16 lcl_Find(const OUString& rFieldName)
     656             : {
     657        8944 :     for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++)
     658        8944 :         if(rFieldName.equalsAscii(aFieldNames[i]))
     659         574 :             return i;
     660           0 :     return -1;
     661             : }
     662             : 
     663          34 : bool    SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
     664             : {
     665          34 :     if(!GetTyp() || !((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle))
     666           0 :         return false;
     667             : 
     668          34 :     Sequence <PropertyValue> aParam;
     669          34 :     if(!(rAny >>= aParam))
     670           0 :         return false;
     671             : 
     672          68 :     OUStringBuffer sBuf;
     673          34 :     comphelper::string::padToLength(sBuf, AUTH_FIELD_ISBN, TOX_STYLE_DELIMITER);
     674          68 :     OUString sToSet(sBuf.makeStringAndClear());
     675          34 :     const PropertyValue* pParam = aParam.getConstArray();
     676         608 :     for(sal_Int32 i = 0; i < aParam.getLength(); i++)
     677             :     {
     678         574 :         sal_Int16 nFound = lcl_Find(pParam[i].Name);
     679         574 :         if(nFound >= 0)
     680             :         {
     681         574 :             OUString sContent;
     682         574 :             if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
     683             :             {
     684          18 :                 sal_Int16 nVal = 0;
     685          18 :                 pParam[i].Value >>= nVal;
     686          18 :                 sContent = OUString::number(nVal);
     687             :             }
     688             :             else
     689         556 :                 pParam[i].Value >>= sContent;
     690         574 :             sToSet = comphelper::string::setToken(sToSet, nFound, TOX_STYLE_DELIMITER, sContent);
     691             :         }
     692             :     }
     693             : 
     694          34 :     ((SwAuthorityFieldType*)GetTyp())->RemoveField(m_nHandle);
     695          34 :     m_nHandle = ((SwAuthorityFieldType*)GetTyp())->AddField(sToSet);
     696             : 
     697             :     /* FIXME: it is weird that we always return false here */
     698          68 :     return false;
     699             : }
     700             : 
     701           0 : SwFieldType* SwAuthorityField::ChgTyp( SwFieldType* pFldTyp )
     702             : {
     703           0 :     SwAuthorityFieldType* pSrcTyp = (SwAuthorityFieldType*)GetTyp(),
     704           0 :                         * pDstTyp = (SwAuthorityFieldType*)pFldTyp;
     705           0 :     if( pSrcTyp != pDstTyp )
     706             :     {
     707             : 
     708           0 :         const SwAuthEntry* pEntry = pSrcTyp->GetEntryByHandle( m_nHandle );
     709           0 :         sal_uInt16 nHdlPos = pDstTyp->AppendField( *pEntry );
     710           0 :         pSrcTyp->RemoveField( m_nHandle );
     711           0 :         m_nHandle = pDstTyp->GetHandle( nHdlPos );
     712           0 :         pDstTyp->AddField( m_nHandle );
     713           0 :         SwField::ChgTyp( pFldTyp );
     714             :     }
     715           0 :     return pSrcTyp;
     716             : }
     717             : 
     718             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10