LCOV - code coverage report
Current view: top level - sw/source/core/fields - authfld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 58 337 17.2 %
Date: 2012-08-25 Functions: 6 35 17.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 54 441 12.2 %

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

Generated by: LCOV version 1.10