LCOV - code coverage report
Current view: top level - sw/inc - authfld.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 24 39 61.5 %
Date: 2015-06-13 12:38:46 Functions: 17 23 73.9 %
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             : #ifndef INCLUDED_SW_INC_AUTHFLD_HXX
      20             : #define INCLUDED_SW_INC_AUTHFLD_HXX
      21             : 
      22             : #include "swdllapi.h"
      23             : #include <fldbas.hxx>
      24             : #include <toxe.hxx>
      25             : #include <vector>
      26             : #include <boost/ptr_container/ptr_vector.hpp>
      27             : #include <sal/log.hxx>
      28             : 
      29          63 : class SwAuthEntry
      30             : {
      31             :     OUString        aAuthFields[AUTH_FIELD_END];
      32             :     sal_uInt16      nRefCount;
      33             : public:
      34          63 :     SwAuthEntry() : nRefCount(0){}
      35             :     SwAuthEntry( const SwAuthEntry& rCopy );
      36             :     bool            operator==(const SwAuthEntry& rComp);
      37             : 
      38             :     inline OUString         GetAuthorField(ToxAuthorityField ePos) const;
      39             :     inline void             SetAuthorField(ToxAuthorityField ePos,
      40             :                                             const OUString& rField);
      41             : 
      42         160 :     void            AddRef()                { ++nRefCount; }
      43         160 :     void            RemoveRef()             { --nRefCount; }
      44         160 :     sal_uInt16          GetRefCount()           { return nRefCount; }
      45             : };
      46             : 
      47             : struct SwTOXSortKey
      48             : {
      49             :     ToxAuthorityField   eField;
      50             :     bool                bSortAscending;
      51           1 :     SwTOXSortKey() :
      52             :         eField(AUTH_FIELD_END),
      53           1 :         bSortAscending(true){}
      54             : };
      55             : 
      56             : class SwAuthorityField;
      57             : typedef boost::ptr_vector<SwTOXSortKey> SortKeyArr;
      58             : typedef boost::ptr_vector<SwAuthEntry> SwAuthDataArr;
      59             : 
      60             : class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType
      61             : {
      62             :     SwDoc*                  m_pDoc;
      63             :     SwAuthDataArr           m_DataArr;
      64             :     std::vector<sal_IntPtr> m_SequArr;
      65             :     SortKeyArr              m_SortKeyArr;
      66             :     sal_Unicode             m_cPrefix;
      67             :     sal_Unicode             m_cSuffix;
      68             :     bool                m_bIsSequence :1;
      69             :     bool                m_bSortByDocument :1;
      70             :     LanguageType            m_eLanguage;
      71             :     OUString                m_sSortAlgorithm;
      72             : 
      73             : protected:
      74             : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) SAL_OVERRIDE;
      75             : 
      76             : public:
      77             :     SwAuthorityFieldType(SwDoc* pDoc);
      78             :     virtual ~SwAuthorityFieldType();
      79             : 
      80             :     virtual SwFieldType* Copy()    const SAL_OVERRIDE;
      81             : 
      82             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const SAL_OVERRIDE;
      83             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) SAL_OVERRIDE;
      84             : 
      85          23 :     inline void         SetDoc(SwDoc* pNewDoc)              { m_pDoc = pNewDoc; }
      86           0 :     SwDoc*              GetDoc(){ return m_pDoc; }
      87             :     void                RemoveField(sal_IntPtr nHandle);
      88             :     sal_IntPtr          AddField(const OUString& rFieldContents);
      89             :     bool            AddField(sal_IntPtr nHandle);
      90         223 :     void                DelSequenceArray()
      91             :                         {
      92         223 :                             m_SequArr.clear();
      93         223 :                         }
      94             : 
      95             :     const SwAuthEntry*  GetEntryByHandle(sal_IntPtr nHandle) const;
      96             : 
      97             :     void                GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
      98             :     const SwAuthEntry*  GetEntryByIdentifier(const OUString& rIdentifier) const;
      99             : 
     100             :     bool                ChangeEntryContent(const SwAuthEntry* pNewEntry);
     101             :     // import interface
     102             :     sal_uInt16          AppendField(const SwAuthEntry& rInsert);
     103             :     sal_IntPtr          GetHandle(sal_uInt16 nPos);
     104             : 
     105             :     sal_uInt16          GetSequencePos(sal_IntPtr nHandle);
     106             : 
     107          77 :     bool            IsSequence() const      {return m_bIsSequence;}
     108           0 :     void                SetSequence(bool bSet)
     109             :                             {
     110           0 :                                 DelSequenceArray();
     111           0 :                                 m_bIsSequence = bSet;
     112           0 :                             }
     113             : 
     114           0 :     void                SetPreSuffix( sal_Unicode cPre, sal_Unicode cSuf)
     115             :                             {
     116           0 :                                 m_cPrefix = cPre;
     117           0 :                                 m_cSuffix = cSuf;
     118           0 :                             }
     119         126 :     sal_Unicode         GetPrefix() const { return m_cPrefix;}
     120         126 :     sal_Unicode         GetSuffix() const { return m_cSuffix;}
     121             : 
     122           0 :     bool            IsSortByDocument() const {return m_bSortByDocument;}
     123           0 :     void                SetSortByDocument(bool bSet)
     124             :                             {
     125           0 :                                 DelSequenceArray();
     126           0 :                                 m_bSortByDocument = bSet;
     127           0 :                             }
     128             : 
     129             :     sal_uInt16          GetSortKeyCount() const ;
     130             :     const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
     131             :     void                SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey nKeys[]);
     132             : 
     133             :     //initui.cxx
     134             :     static OUString     GetAuthFieldName(ToxAuthorityField eType);
     135             :     static OUString     GetAuthTypeName(ToxAuthorityType eType);
     136             : 
     137           1 :     LanguageType    GetLanguage() const {return m_eLanguage;}
     138           5 :     void            SetLanguage(LanguageType nLang)  {m_eLanguage = nLang;}
     139             : 
     140           1 :     OUString        GetSortAlgorithm() const {return m_sSortAlgorithm;}
     141           4 :     void            SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
     142             : 
     143             : };
     144             : 
     145             : class SwAuthorityField : public SwField
     146             : {
     147             :     sal_IntPtr          m_nHandle;
     148             :     mutable sal_IntPtr  m_nTempSequencePos;
     149             : 
     150             :     virtual OUString    Expand() const SAL_OVERRIDE;
     151             :     virtual SwField*    Copy() const SAL_OVERRIDE;
     152             : 
     153             : public:
     154             :     /// For internal use only, in general continue using ExpandField() instead.
     155             :     OUString ConditionalExpand(ToxAuthorityField eField) const;
     156             : 
     157             :     //To handle Citation
     158             :     OUString ExpandCitation(ToxAuthorityField eField) const;
     159             : 
     160             :     SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
     161             :     SwAuthorityField(SwAuthorityFieldType* pType, sal_IntPtr nHandle);
     162             :     virtual ~SwAuthorityField();
     163             : 
     164             :     OUString            GetFieldText(ToxAuthorityField eField) const;
     165             : 
     166             :     virtual void        SetPar1(const OUString& rStr) SAL_OVERRIDE;
     167             :     virtual SwFieldType* ChgTyp( SwFieldType* ) SAL_OVERRIDE;
     168             : 
     169             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const SAL_OVERRIDE;
     170             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) SAL_OVERRIDE;
     171             : 
     172           0 :     sal_IntPtr          GetHandle() const       { return m_nHandle; }
     173             : 
     174             :     virtual OUString GetDescription() const SAL_OVERRIDE;
     175             : };
     176             : 
     177         728 : inline OUString SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
     178             : {
     179             :     SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
     180         728 :     return aAuthFields[ePos];
     181             : }
     182        1953 : inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
     183             : {
     184             :     SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
     185        1953 :     if(AUTH_FIELD_END > ePos)
     186        1953 :         aAuthFields[ePos] = rField;
     187        1953 : }
     188             : 
     189             : #endif
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11