LCOV - code coverage report
Current view: top level - sw/source/core/fields - authfld.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 341 0.0 %
Date: 2014-04-14 Functions: 0 36 0.0 %
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           0 : sal_Bool    SwAuthEntry::operator==(const SwAuthEntry& rComp)
      55             : {
      56           0 :     for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++)
      57           0 :         if(aAuthFields[i] != rComp.aAuthFields[i])
      58           0 :             return sal_False;
      59           0 :     return sal_True;
      60             : }
      61             : 
      62           0 : 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           0 :     m_eLanguage(::GetAppLanguage())
      72             : {
      73           0 : }
      74             : 
      75           0 : SwAuthorityFieldType::~SwAuthorityFieldType()
      76             : {
      77           0 : }
      78             : 
      79           0 : SwFieldType*    SwAuthorityFieldType::Copy()  const
      80             : {
      81           0 :     return new SwAuthorityFieldType(m_pDoc);
      82             : }
      83             : 
      84           0 : void    SwAuthorityFieldType::RemoveField(sal_IntPtr nHandle)
      85             : {
      86             : #if OSL_DEBUG_LEVEL > 0
      87             :     bool bRemoved = false;
      88             : #endif
      89           0 :     for(sal_uInt16 j = 0; j < m_DataArr.size(); j++)
      90             :     {
      91           0 :         SwAuthEntry* pTemp = &m_DataArr[j];
      92           0 :         sal_IntPtr nRet = (sal_IntPtr)(void*)pTemp;
      93           0 :         if(nRet == nHandle)
      94             :         {
      95             : #if OSL_DEBUG_LEVEL > 0
      96             :             bRemoved = true;
      97             : #endif
      98           0 :             pTemp->RemoveRef();
      99           0 :             if(!pTemp->GetRefCount())
     100             :             {
     101           0 :                 m_DataArr.erase(m_DataArr.begin() + j);
     102             :                 //re-generate positions of the fields
     103           0 :                 DelSequenceArray();
     104             :             }
     105           0 :             break;
     106             :         }
     107             :     }
     108             : #if OSL_DEBUG_LEVEL > 0
     109             :     OSL_ENSURE(bRemoved, "Field unknown" );
     110             : #endif
     111           0 : }
     112             : 
     113           0 : sal_IntPtr SwAuthorityFieldType::AddField(const OUString& rFieldContents)
     114             : {
     115           0 :     sal_IntPtr nRet = 0;
     116           0 :     SwAuthEntry* pEntry = new SwAuthEntry;
     117           0 :     for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i )
     118             :         pEntry->SetAuthorField( (ToxAuthorityField)i,
     119           0 :                         rFieldContents.getToken( i, TOX_STYLE_DELIMITER ));
     120             : 
     121           0 :     for(sal_uInt16 j = 0; j < m_DataArr.size() && pEntry; j++)
     122             :     {
     123           0 :         SwAuthEntry* pTemp = &m_DataArr[j];
     124           0 :         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           0 :     if(pEntry)
     133             :     {
     134           0 :         nRet = (sal_IntPtr)(void*)pEntry;
     135           0 :         pEntry->AddRef();
     136           0 :         m_DataArr.push_back(pEntry);
     137             :         //re-generate positions of the fields
     138           0 :         DelSequenceArray();
     139             :     }
     140           0 :     return nRet;
     141             : }
     142             : 
     143           0 : sal_Bool SwAuthorityFieldType::AddField(sal_IntPtr nHandle)
     144             : {
     145           0 :     sal_Bool bRet = sal_False;
     146           0 :     for( sal_uInt16 j = 0; j < m_DataArr.size(); j++ )
     147             :     {
     148           0 :         SwAuthEntry* pTemp = &m_DataArr[j];
     149           0 :         sal_IntPtr nTmp = (sal_IntPtr)(void*)pTemp;
     150           0 :         if( nTmp == nHandle )
     151             :         {
     152           0 :             bRet = sal_True;
     153           0 :             pTemp->AddRef();
     154             :             //re-generate positions of the fields
     155           0 :             DelSequenceArray();
     156           0 :             break;
     157             :         }
     158             :     }
     159             :     OSL_ENSURE(bRet, "::AddField(sal_IntPtr) failed");
     160           0 :     return bRet;
     161             : }
     162             : 
     163           0 : const SwAuthEntry*  SwAuthorityFieldType::GetEntryByHandle(sal_IntPtr nHandle) const
     164             : {
     165           0 :     const SwAuthEntry* pRet = 0;
     166           0 :     for(sal_uInt16 j = 0; j < m_DataArr.size(); j++)
     167             :     {
     168           0 :         const SwAuthEntry* pTemp = &m_DataArr[j];
     169           0 :         sal_IntPtr nTmp = (sal_IntPtr)(void*)pTemp;
     170           0 :         if( nTmp == nHandle )
     171             :         {
     172           0 :             pRet = pTemp;
     173           0 :             break;
     174             :         }
     175             :     }
     176             :     OSL_ENSURE( pRet, "invalid Handle" );
     177           0 :     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           0 : bool SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const
     362             : {
     363           0 :     switch( nWhichId )
     364             :     {
     365             :     case FIELD_PROP_PAR1:
     366             :     case FIELD_PROP_PAR2:
     367             :         {
     368           0 :             OUString sVal;
     369           0 :             sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix;
     370           0 :             if(uRet)
     371           0 :                 sVal = OUString(uRet);
     372           0 :             rVal <<= sVal;
     373             :         }
     374           0 :         break;
     375             :     case FIELD_PROP_PAR3:
     376           0 :         rVal <<= GetSortAlgorithm();
     377           0 :         break;
     378             : 
     379             :     case FIELD_PROP_BOOL1:
     380             :     case FIELD_PROP_BOOL2:
     381             :         {
     382           0 :             sal_Bool bVal = FIELD_PROP_BOOL1 == nWhichId ? m_bIsSequence: m_bSortByDocument;
     383           0 :             rVal.setValue(&bVal, ::getBooleanCppuType());
     384             :         }
     385           0 :         break;
     386             : 
     387             :     case FIELD_PROP_LOCALE:
     388           0 :         rVal <<= LanguageTag(GetLanguage()).getLocale();
     389           0 :         break;
     390             : 
     391             :     case FIELD_PROP_PROP_SEQ:
     392             :         {
     393           0 :             Sequence<PropertyValues> aRet(m_SortKeyArr.size());
     394           0 :             PropertyValues* pValues = aRet.getArray();
     395           0 :             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           0 :             rVal <<= aRet;
     406             :         }
     407           0 :         break;
     408             :     default:
     409             :         OSL_FAIL("illegal property");
     410             :     }
     411           0 :     return true;
     412             : }
     413             : 
     414           0 : bool    SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId )
     415             : {
     416           0 :     bool bRet = true;
     417           0 :     switch( nWhichId )
     418             :     {
     419             :     case FIELD_PROP_PAR1:
     420             :     case FIELD_PROP_PAR2:
     421             :     {
     422           0 :         OUString sTmp;
     423           0 :         rAny >>= sTmp;
     424           0 :         const sal_Unicode uSet = !sTmp.isEmpty() ? sTmp[0] : 0;
     425           0 :         if( FIELD_PROP_PAR1 == nWhichId )
     426           0 :             m_cPrefix = uSet;
     427             :         else
     428           0 :             m_cSuffix = uSet;
     429             :     }
     430           0 :     break;
     431             :     case FIELD_PROP_PAR3:
     432             :     {
     433           0 :         OUString sTmp;
     434           0 :         rAny >>= sTmp;
     435           0 :         SetSortAlgorithm(sTmp);
     436           0 :         break;
     437             :     }
     438             :     case FIELD_PROP_BOOL1:
     439           0 :         m_bIsSequence = *(sal_Bool*)rAny.getValue();
     440           0 :         break;
     441             :     case FIELD_PROP_BOOL2:
     442           0 :         m_bSortByDocument = *(sal_Bool*)rAny.getValue();
     443           0 :         break;
     444             : 
     445             :     case FIELD_PROP_LOCALE:
     446             :         {
     447           0 :             com::sun::star::lang::Locale aLocale;
     448           0 :             if( (bRet = rAny >>= aLocale ))
     449           0 :                 SetLanguage( LanguageTag::convertToLanguageType( aLocale ));
     450             :         }
     451           0 :         break;
     452             : 
     453             :     case FIELD_PROP_PROP_SEQ:
     454             :         {
     455           0 :             Sequence<PropertyValues> aSeq;
     456           0 :             if( (bRet = rAny >>= aSeq) )
     457             :             {
     458           0 :                 m_SortKeyArr.clear();
     459           0 :                 const PropertyValues* pValues = aSeq.getConstArray();
     460           0 :                 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           0 :             }
     482             :         }
     483           0 :         break;
     484             :     default:
     485             :         OSL_FAIL("illegal property");
     486             :     }
     487           0 :     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           0 : SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
     520             :                                     const OUString& rFieldContents )
     521             :     : SwField(pInitType),
     522           0 :     m_nTempSequencePos( -1 )
     523             : {
     524           0 :     m_nHandle = pInitType->AddField( rFieldContents );
     525           0 : }
     526             : 
     527           0 : SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
     528             :                                                 sal_IntPtr nSetHandle )
     529             :     : SwField( pInitType ),
     530             :     m_nHandle( nSetHandle ),
     531           0 :     m_nTempSequencePos( -1 )
     532             : {
     533           0 :     pInitType->AddField( m_nHandle );
     534           0 : }
     535             : 
     536           0 : SwAuthorityField::~SwAuthorityField()
     537             : {
     538           0 :     ((SwAuthorityFieldType* )GetTyp())->RemoveField(m_nHandle);
     539           0 : }
     540             : 
     541           0 : OUString SwAuthorityField::Expand() const
     542             : {
     543           0 :     return ConditionalExpand(AUTH_FIELD_IDENTIFIER);
     544             : }
     545             : 
     546           0 : OUString SwAuthorityField::ConditionalExpand(ToxAuthorityField eField) const
     547             : {
     548           0 :     SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
     549           0 :     OUString sRet;
     550           0 :     if(pAuthType->GetPrefix() && eField != AUTH_FIELD_TITLE)
     551           0 :         sRet = OUString(pAuthType->GetPrefix());
     552             : 
     553           0 :     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           0 :         const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle(m_nHandle);
     563             :         //TODO: Expand to: identifier, number sequence, ...
     564           0 :         if(pEntry)
     565           0 :             sRet += pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER);
     566             :     }
     567           0 :     if(pAuthType->GetSuffix())
     568           0 :         sRet += OUString(pAuthType->GetSuffix());
     569           0 :     return sRet;
     570             : }
     571             : 
     572           0 : SwField* SwAuthorityField::Copy() const
     573             : {
     574           0 :     SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
     575           0 :     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           0 : bool    SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const
     633             : {
     634           0 :     if(!GetTyp())
     635           0 :         return false;
     636           0 :     const SwAuthEntry* pAuthEntry = ((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle);
     637           0 :     if(!pAuthEntry)
     638           0 :         return false;
     639           0 :     Sequence <PropertyValue> aRet(AUTH_FIELD_END);
     640           0 :     PropertyValue* pValues = aRet.getArray();
     641           0 :     for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++)
     642             :     {
     643           0 :         pValues[i].Name = OUString::createFromAscii(aFieldNames[i]);
     644           0 :         const OUString sField = pAuthEntry->GetAuthorField((ToxAuthorityField) i);
     645           0 :         if(i == AUTH_FIELD_AUTHORITY_TYPE)
     646           0 :             pValues[i].Value <<= sal_Int16(sField.toInt32());
     647             :         else
     648           0 :             pValues[i].Value <<= sField;
     649           0 :     }
     650           0 :     rAny <<= aRet;
     651             :     /* FIXME: it is weird that we always return false here */
     652           0 :     return false;
     653             : }
     654             : 
     655           0 : static sal_Int16 lcl_Find(const OUString& rFieldName)
     656             : {
     657           0 :     for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++)
     658           0 :         if(rFieldName.equalsAscii(aFieldNames[i]))
     659           0 :             return i;
     660           0 :     return -1;
     661             : }
     662             : 
     663           0 : bool    SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ )
     664             : {
     665           0 :     if(!GetTyp() || !((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle))
     666           0 :         return false;
     667             : 
     668           0 :     Sequence <PropertyValue> aParam;
     669           0 :     if(!(rAny >>= aParam))
     670           0 :         return false;
     671             : 
     672           0 :     OUStringBuffer sBuf;
     673           0 :     comphelper::string::padToLength(sBuf, AUTH_FIELD_ISBN, TOX_STYLE_DELIMITER);
     674           0 :     OUString sToSet(sBuf.makeStringAndClear());
     675           0 :     const PropertyValue* pParam = aParam.getConstArray();
     676           0 :     for(sal_Int32 i = 0; i < aParam.getLength(); i++)
     677             :     {
     678           0 :         sal_Int16 nFound = lcl_Find(pParam[i].Name);
     679           0 :         if(nFound >= 0)
     680             :         {
     681           0 :             OUString sContent;
     682           0 :             if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
     683             :             {
     684           0 :                 sal_Int16 nVal = 0;
     685           0 :                 pParam[i].Value >>= nVal;
     686           0 :                 sContent = OUString::number(nVal);
     687             :             }
     688             :             else
     689           0 :                 pParam[i].Value >>= sContent;
     690           0 :             sToSet = comphelper::string::setToken(sToSet, nFound, TOX_STYLE_DELIMITER, sContent);
     691             :         }
     692             :     }
     693             : 
     694           0 :     ((SwAuthorityFieldType*)GetTyp())->RemoveField(m_nHandle);
     695           0 :     m_nHandle = ((SwAuthorityFieldType*)GetTyp())->AddField(sToSet);
     696             : 
     697             :     /* FIXME: it is weird that we always return false here */
     698           0 :     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