Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / authfld.hxx
blob2696ef619b2695ff82b29eed8bb3c4e7c86c9c9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_INC_AUTHFLD_HXX
20 #define INCLUDED_SW_INC_AUTHFLD_HXX
22 #include "swdllapi.h"
23 #include <fldbas.hxx>
24 #include <toxe.hxx>
25 #include <sal/log.hxx>
27 #include <memory>
28 #include <vector>
30 class SwAuthEntry
32 OUString aAuthFields[AUTH_FIELD_END];
33 sal_uInt16 nRefCount;
34 public:
35 SwAuthEntry() : nRefCount(0){}
36 SwAuthEntry( const SwAuthEntry& rCopy );
37 bool operator==(const SwAuthEntry& rComp);
39 inline OUString const & GetAuthorField(ToxAuthorityField ePos) const;
40 inline void SetAuthorField(ToxAuthorityField ePos,
41 const OUString& rField);
43 void AddRef() { ++nRefCount; }
44 void RemoveRef() { --nRefCount; }
45 sal_uInt16 GetRefCount() { return nRefCount; }
48 struct SwTOXSortKey
50 ToxAuthorityField eField;
51 bool bSortAscending;
52 SwTOXSortKey() :
53 eField(AUTH_FIELD_END),
54 bSortAscending(true){}
57 class SwAuthorityField;
58 typedef std::vector<SwTOXSortKey> SortKeyArr;
59 typedef std::vector<std::unique_ptr<SwAuthEntry>> SwAuthDataArr;
61 class SW_DLLPUBLIC SwAuthorityFieldType : public SwFieldType
63 SwDoc* m_pDoc;
64 SwAuthDataArr m_DataArr;
65 std::vector<sal_IntPtr> m_SequArr;
66 SortKeyArr m_SortKeyArr;
67 sal_Unicode m_cPrefix;
68 sal_Unicode m_cSuffix;
69 bool m_bIsSequence :1;
70 bool m_bSortByDocument :1;
71 LanguageType m_eLanguage;
72 OUString m_sSortAlgorithm;
74 protected:
75 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
77 public:
78 SwAuthorityFieldType(SwDoc* pDoc);
79 virtual ~SwAuthorityFieldType() override;
81 virtual SwFieldType* Copy() const override;
83 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
84 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
86 void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
87 SwDoc* GetDoc(){ return m_pDoc; }
88 void RemoveField(sal_IntPtr nHandle);
89 sal_IntPtr AddField(const OUString& rFieldContents);
90 bool AddField(sal_IntPtr nHandle);
91 void DelSequenceArray()
93 m_SequArr.clear();
96 const SwAuthEntry* GetEntryByHandle(sal_IntPtr nHandle) const;
98 void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
99 const SwAuthEntry* GetEntryByIdentifier(const OUString& rIdentifier) const;
101 bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
102 // import interface
103 sal_uInt16 AppendField(const SwAuthEntry& rInsert);
104 sal_IntPtr GetHandle(sal_uInt16 nPos);
106 sal_uInt16 GetSequencePos(sal_IntPtr nHandle);
108 bool IsSequence() const {return m_bIsSequence;}
109 void SetSequence(bool bSet)
111 DelSequenceArray();
112 m_bIsSequence = bSet;
115 void SetPreSuffix( sal_Unicode cPre, sal_Unicode cSuf)
117 m_cPrefix = cPre;
118 m_cSuffix = cSuf;
120 sal_Unicode GetPrefix() const { return m_cPrefix;}
121 sal_Unicode GetSuffix() const { return m_cSuffix;}
123 bool IsSortByDocument() const {return m_bSortByDocument;}
124 void SetSortByDocument(bool bSet)
126 DelSequenceArray();
127 m_bSortByDocument = bSet;
130 sal_uInt16 GetSortKeyCount() const ;
131 const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
132 void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey nKeys[]);
134 //initui.cxx
135 static OUString GetAuthFieldName(ToxAuthorityField eType);
136 static OUString GetAuthTypeName(ToxAuthorityType eType);
138 LanguageType GetLanguage() const {return m_eLanguage;}
139 void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
141 const OUString& GetSortAlgorithm() const {return m_sSortAlgorithm;}
142 void SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
146 class SwAuthorityField : public SwField
148 sal_IntPtr m_nHandle;
149 mutable sal_IntPtr m_nTempSequencePos;
151 virtual OUString Expand() const override;
152 virtual SwField* Copy() const override;
154 public:
155 /// For internal use only, in general continue using ExpandField() instead.
156 OUString ConditionalExpandAuthIdentifier() const;
158 //To handle Citation
159 SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField) const;
161 SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
162 SwAuthorityField(SwAuthorityFieldType* pType, sal_IntPtr nHandle);
163 virtual ~SwAuthorityField() override;
165 OUString GetFieldText(ToxAuthorityField eField) const;
167 virtual void SetPar1(const OUString& rStr) override;
168 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
170 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
171 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
173 sal_IntPtr GetHandle() const { return m_nHandle; }
175 virtual OUString GetDescription() const override;
178 inline OUString const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
180 SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
181 return aAuthFields[ePos];
183 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
185 SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
186 if(AUTH_FIELD_END > ePos)
187 aAuthFields[ePos] = rField;
190 #endif
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */