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

Generated by: LCOV version 1.10