Resolves tdf#142513 - Order of ZoomIn and ZoomOut at Print Preview
[LibreOffice.git] / sw / inc / authfld.hxx
blobfcf4f128361dec38f9e805ceaab93e8e40518c80
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 <rtl/ref.hxx>
26 #include <sal/log.hxx>
27 #include <salhelper/simplereferenceobject.hxx>
29 #include <memory>
30 #include <vector>
32 class SwTOXInternational;
33 class SwTextAttr;
35 class SwAuthEntry final : public salhelper::SimpleReferenceObject
37 friend class SwAuthorityFieldType;
38 OUString m_aAuthFields[AUTH_FIELD_END];
39 public:
40 SwAuthEntry() = default;
41 SwAuthEntry( const SwAuthEntry& rCopy );
42 bool operator==(const SwAuthEntry& rComp) const;
44 inline OUString const & GetAuthorField(ToxAuthorityField ePos) const;
45 inline void SetAuthorField(ToxAuthorityField ePos,
46 const OUString& rField);
47 void dumpAsXml(xmlTextWriterPtr pWriter) const;
50 struct SwTOXSortKey
52 ToxAuthorityField eField;
53 bool bSortAscending;
54 SwTOXSortKey() :
55 eField(AUTH_FIELD_END),
56 bSortAscending(true){}
59 typedef std::vector<SwTOXSortKey> SortKeyArr;
60 typedef std::vector<rtl::Reference<SwAuthEntry>> SwAuthDataArr;
62 class SW_DLLPUBLIC SwAuthorityFieldType final : public SwFieldType
64 SwDoc* m_pDoc;
65 SwAuthDataArr m_DataArr;
66 std::vector<SwAuthEntry*> m_SequArr;
67 std::vector<SwAuthEntry*> m_SequArrRLHidden; ///< hidden redlines
68 SortKeyArr m_SortKeyArr;
69 sal_Unicode m_cPrefix;
70 sal_Unicode m_cSuffix;
71 bool m_bIsSequence :1;
72 bool m_bSortByDocument :1;
73 LanguageType m_eLanguage;
74 OUString m_sSortAlgorithm;
76 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
78 public:
79 SwAuthorityFieldType(SwDoc* pDoc);
80 virtual ~SwAuthorityFieldType() override;
82 virtual std::unique_ptr<SwFieldType> Copy() const override;
84 virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
85 virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
87 void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
88 SwDoc* GetDoc(){ return m_pDoc; }
89 void RemoveField(const SwAuthEntry* nHandle);
90 SwAuthEntry* AddField(const OUString& rFieldContents);
91 void DelSequenceArray()
93 m_SequArr.clear();
94 m_SequArrRLHidden.clear();
97 void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
98 SwAuthEntry* GetEntryByIdentifier(std::u16string_view rIdentifier) const;
100 bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
101 // import interface
102 SwAuthEntry* AppendField(const SwAuthEntry& rInsert);
104 sal_uInt16 GetSequencePos(const SwAuthEntry* pAuthEntry, SwRootFrame const* pLayout);
105 std::unique_ptr<SwTOXInternational> CreateTOXInternational() const;
107 bool IsSequence() const {return m_bIsSequence;}
108 void SetSequence(bool bSet)
110 DelSequenceArray();
111 m_bIsSequence = bSet;
114 void SetPreSuffix( sal_Unicode cPre, sal_Unicode cSuf)
116 m_cPrefix = cPre;
117 m_cSuffix = cSuf;
119 sal_Unicode GetPrefix() const { return m_cPrefix;}
120 sal_Unicode GetSuffix() const { return m_cSuffix;}
122 bool IsSortByDocument() const {return m_bSortByDocument;}
123 void SetSortByDocument(bool bSet)
125 DelSequenceArray();
126 m_bSortByDocument = bSet;
129 sal_uInt16 GetSortKeyCount() const ;
130 const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
131 void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[]);
133 //initui.cxx
134 static OUString const & GetAuthFieldName(ToxAuthorityField eType);
135 static OUString const & GetAuthTypeName(ToxAuthorityType eType);
137 LanguageType GetLanguage() const {return m_eLanguage;}
138 void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
140 const OUString& GetSortAlgorithm() const {return m_sSortAlgorithm;}
141 void SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
142 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
146 /** invariant for SwAuthorityField is that it is always registered at its
147 SwAuthorityFieldType via AddField()/RemoveField() & therefore has m_nHandle
148 set - but it's possible that multiple SwAuthorityField have the same
149 m_nHandle & so the number of instances is an upper bound on
150 SwAuthorityField::m_DataArr.size() - it's not clear to me if more than one
151 one of the instances with the same m_nHandle is actually in the document,
152 they're all cloned via CopyField()...
154 class SW_DLLPUBLIC SwAuthorityField final : public SwField
156 rtl::Reference<SwAuthEntry> m_xAuthEntry;
157 mutable sal_IntPtr m_nTempSequencePos;
158 mutable sal_IntPtr m_nTempSequencePosRLHidden; ///< hidden redlines
160 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
161 virtual std::unique_ptr<SwField> Copy() const override;
163 public:
164 /// For internal use only, in general continue using ExpandField() instead.
165 OUString ConditionalExpandAuthIdentifier(SwRootFrame const* pLayout) const;
167 //To handle Citation
168 OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
170 SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
171 SwAuthorityField(SwAuthorityFieldType* pType, SwAuthEntry* pAuthEntry);
172 virtual ~SwAuthorityField() override;
174 const OUString & GetFieldText(ToxAuthorityField eField) const;
176 virtual void SetPar1(const OUString& rStr) override;
177 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
179 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
180 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
182 SwAuthEntry* GetAuthEntry() const { return m_xAuthEntry.get(); }
184 virtual OUString GetDescription() const override;
186 /// Returns the line matching the source's default row in the ToX.
187 OUString GetAuthority(const SwTextAttr* pTextAttr, const SwRootFrame* pLayout) const;
189 bool HasURL() const;
190 OUString GetAbsoluteURL() const;
192 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
195 inline OUString const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
197 SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
198 return m_aAuthFields[ePos];
200 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
202 SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
203 if(AUTH_FIELD_END > ePos)
204 m_aAuthFields[ePos] = rField;
207 #endif
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */