1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
25 #include <rtl/ref.hxx>
26 #include <sal/log.hxx>
27 #include <salhelper/simplereferenceobject.hxx>
32 class SwAuthEntry final
: public salhelper::SimpleReferenceObject
34 friend class SwAuthorityFieldType
;
35 OUString m_aAuthFields
[AUTH_FIELD_END
];
37 SwAuthEntry() = default;
38 SwAuthEntry( const SwAuthEntry
& rCopy
);
39 bool operator==(const SwAuthEntry
& rComp
) const;
41 inline OUString
const & GetAuthorField(ToxAuthorityField ePos
) const;
42 inline void SetAuthorField(ToxAuthorityField ePos
,
43 const OUString
& rField
);
48 ToxAuthorityField eField
;
51 eField(AUTH_FIELD_END
),
52 bSortAscending(true){}
55 typedef std::vector
<SwTOXSortKey
> SortKeyArr
;
56 typedef std::vector
<rtl::Reference
<SwAuthEntry
>> SwAuthDataArr
;
58 class SW_DLLPUBLIC SwAuthorityFieldType final
: public SwFieldType
61 SwAuthDataArr m_DataArr
;
62 std::vector
<SwAuthEntry
*> m_SequArr
;
63 std::vector
<SwAuthEntry
*> m_SequArrRLHidden
; ///< hidden redlines
64 SortKeyArr m_SortKeyArr
;
65 sal_Unicode m_cPrefix
;
66 sal_Unicode m_cSuffix
;
67 bool m_bIsSequence
:1;
68 bool m_bSortByDocument
:1;
69 LanguageType m_eLanguage
;
70 OUString m_sSortAlgorithm
;
72 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
75 SwAuthorityFieldType(SwDoc
* pDoc
);
76 virtual ~SwAuthorityFieldType() override
;
78 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
80 virtual void QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const override
;
81 virtual void PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
) override
;
83 void SetDoc(SwDoc
* pNewDoc
) { m_pDoc
= pNewDoc
; }
84 SwDoc
* GetDoc(){ return m_pDoc
; }
85 void RemoveField(const SwAuthEntry
* nHandle
);
86 SwAuthEntry
* AddField(const OUString
& rFieldContents
);
87 void DelSequenceArray()
90 m_SequArrRLHidden
.clear();
93 void GetAllEntryIdentifiers( std::vector
<OUString
>& rToFill
) const;
94 SwAuthEntry
* GetEntryByIdentifier(const OUString
& rIdentifier
) const;
96 bool ChangeEntryContent(const SwAuthEntry
* pNewEntry
);
98 sal_uInt16
AppendField(const SwAuthEntry
& rInsert
);
100 sal_uInt16
GetSequencePos(const SwAuthEntry
* pAuthEntry
, SwRootFrame
const* pLayout
);
102 bool IsSequence() const {return m_bIsSequence
;}
103 void SetSequence(bool bSet
)
106 m_bIsSequence
= bSet
;
109 void SetPreSuffix( sal_Unicode cPre
, sal_Unicode cSuf
)
114 sal_Unicode
GetPrefix() const { return m_cPrefix
;}
115 sal_Unicode
GetSuffix() const { return m_cSuffix
;}
117 bool IsSortByDocument() const {return m_bSortByDocument
;}
118 void SetSortByDocument(bool bSet
)
121 m_bSortByDocument
= bSet
;
124 sal_uInt16
GetSortKeyCount() const ;
125 const SwTOXSortKey
* GetSortKey(sal_uInt16 nIdx
) const ;
126 void SetSortKeys(sal_uInt16 nKeyCount
, SwTOXSortKey
const nKeys
[]);
129 static OUString
const & GetAuthFieldName(ToxAuthorityField eType
);
130 static OUString
const & GetAuthTypeName(ToxAuthorityType eType
);
132 LanguageType
GetLanguage() const {return m_eLanguage
;}
133 void SetLanguage(LanguageType nLang
) {m_eLanguage
= nLang
;}
135 const OUString
& GetSortAlgorithm() const {return m_sSortAlgorithm
;}
136 void SetSortAlgorithm(const OUString
& rSet
) {m_sSortAlgorithm
= rSet
;}
140 /** invariant for SwAuthorityField is that it is always registered at its
141 SwAuthorityFieldType via AddField()/RemoveField() & therefore has m_nHandle
142 set - but it's possible that multiple SwAuthorityField have the same
143 m_nHandle & so the number of instances is an upper bound on
144 SwAuthorityField::m_DataArr.size() - it's not clear to me if more than one
145 one of the instances with the same m_nHandle is actually in the document,
146 they're all cloned via CopyField()...
148 class SAL_DLLPUBLIC_RTTI SwAuthorityField final
: public SwField
150 rtl::Reference
<SwAuthEntry
> m_xAuthEntry
;
151 mutable sal_IntPtr m_nTempSequencePos
;
152 mutable sal_IntPtr m_nTempSequencePosRLHidden
; ///< hidden redlines
154 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
155 virtual std::unique_ptr
<SwField
> Copy() const override
;
158 /// For internal use only, in general continue using ExpandField() instead.
159 OUString
ConditionalExpandAuthIdentifier(SwRootFrame
const* pLayout
) const;
162 SW_DLLPUBLIC OUString
ExpandCitation(ToxAuthorityField eField
, SwRootFrame
const* pLayout
) const;
164 SwAuthorityField(SwAuthorityFieldType
* pType
, const OUString
& rFieldContents
);
165 SwAuthorityField(SwAuthorityFieldType
* pType
, SwAuthEntry
* pAuthEntry
);
166 virtual ~SwAuthorityField() override
;
168 const OUString
& GetFieldText(ToxAuthorityField eField
) const;
170 virtual void SetPar1(const OUString
& rStr
) override
;
171 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
173 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const override
;
174 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
) override
;
176 SwAuthEntry
* GetAuthEntry() const { return m_xAuthEntry
.get(); }
178 virtual OUString
GetDescription() const override
;
181 inline OUString
const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos
) const
183 SAL_WARN_IF(AUTH_FIELD_END
<= ePos
, "sw", "wrong index");
184 return m_aAuthFields
[ePos
];
186 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos
, const OUString
& rField
)
188 SAL_WARN_IF(AUTH_FIELD_END
<= ePos
, "sw", "wrong index");
189 if(AUTH_FIELD_END
> ePos
)
190 m_aAuthFields
[ePos
] = rField
;
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */