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
22 #include <sal/config.h>
27 #include <rtl/ref.hxx>
28 #include <sal/log.hxx>
29 #include <salhelper/simplereferenceobject.hxx>
34 class SwTOXInternational
;
38 class SwAuthEntry final
: public salhelper::SimpleReferenceObject
40 friend class SwAuthorityFieldType
;
41 OUString m_aAuthFields
[AUTH_FIELD_END
];
43 SwAuthEntry() = default;
44 SwAuthEntry( const SwAuthEntry
& rCopy
);
45 bool operator==(const SwAuthEntry
& rComp
) const;
47 inline OUString
const & GetAuthorField(ToxAuthorityField ePos
) const;
48 inline void SetAuthorField(ToxAuthorityField ePos
,
49 const OUString
& rField
);
50 void dumpAsXml(xmlTextWriterPtr pWriter
) const;
55 ToxAuthorityField eField
;
58 eField(AUTH_FIELD_END
),
59 bSortAscending(true){}
62 typedef std::vector
<SwTOXSortKey
> SortKeyArr
;
63 typedef std::vector
<rtl::Reference
<SwAuthEntry
>> SwAuthDataArr
;
65 class SW_DLLPUBLIC SwAuthorityFieldType final
: public SwFieldType
68 SwAuthDataArr m_DataArr
;
69 std::vector
<SwAuthEntry
*> m_SequArr
;
70 std::vector
<SwAuthEntry
*> m_SequArrRLHidden
; ///< hidden redlines
71 SortKeyArr m_SortKeyArr
;
72 sal_Unicode m_cPrefix
;
73 sal_Unicode m_cSuffix
;
74 bool m_bIsSequence
:1;
75 bool m_bSortByDocument
:1;
76 LanguageType m_eLanguage
;
77 OUString m_sSortAlgorithm
;
79 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
82 SwAuthorityFieldType(SwDoc
* pDoc
);
83 virtual ~SwAuthorityFieldType() override
;
85 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
87 virtual void QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const override
;
88 virtual void PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
) override
;
90 void SetDoc(SwDoc
* pNewDoc
) { m_pDoc
= pNewDoc
; }
91 SwDoc
* GetDoc(){ return m_pDoc
; }
92 void RemoveField(const SwAuthEntry
* nHandle
);
93 SwAuthEntry
* AddField(std::u16string_view rFieldContents
);
94 void DelSequenceArray()
97 m_SequArrRLHidden
.clear();
100 void GetAllEntryIdentifiers( std::vector
<OUString
>& rToFill
) const;
101 SwAuthEntry
* GetEntryByIdentifier(std::u16string_view rIdentifier
) const;
103 bool ChangeEntryContent(const SwAuthEntry
* pNewEntry
);
105 SwAuthEntry
* AppendField(const SwAuthEntry
& rInsert
);
107 sal_uInt16
GetSequencePos(const SwAuthEntry
* pAuthEntry
, SwRootFrame
const* pLayout
);
108 std::unique_ptr
<SwTOXInternational
> CreateTOXInternational() const;
110 bool IsSequence() const {return m_bIsSequence
;}
111 void SetSequence(bool bSet
)
114 m_bIsSequence
= bSet
;
117 void SetPreSuffix( sal_Unicode cPre
, sal_Unicode cSuf
)
122 sal_Unicode
GetPrefix() const { return m_cPrefix
;}
123 sal_Unicode
GetSuffix() const { return m_cSuffix
;}
125 bool IsSortByDocument() const {return m_bSortByDocument
;}
126 void SetSortByDocument(bool bSet
)
129 m_bSortByDocument
= bSet
;
132 sal_uInt16
GetSortKeyCount() const ;
133 const SwTOXSortKey
* GetSortKey(sal_uInt16 nIdx
) const ;
134 void SetSortKeys(sal_uInt16 nKeyCount
, SwTOXSortKey
const nKeys
[]);
137 static OUString
const & GetAuthFieldName(ToxAuthorityField eType
);
138 static OUString
const & GetAuthTypeName(ToxAuthorityType eType
);
140 LanguageType
GetLanguage() const {return m_eLanguage
;}
141 void SetLanguage(LanguageType nLang
) {m_eLanguage
= nLang
;}
143 const OUString
& GetSortAlgorithm() const {return m_sSortAlgorithm
;}
144 void SetSortAlgorithm(const OUString
& rSet
) {m_sSortAlgorithm
= rSet
;}
145 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
149 /** Represents an inserted bibliography entry, created using Insert -> Table of Contents and Index
150 -> Bibliography Entry.
152 invariant for SwAuthorityField is that it is always registered at its
153 SwAuthorityFieldType via AddField()/RemoveField() & therefore has m_nHandle
154 set - but it's possible that multiple SwAuthorityField have the same
155 m_nHandle & so the number of instances is an upper bound on
156 SwAuthorityField::m_DataArr.size() - it's not clear to me if more than one
157 one of the instances with the same m_nHandle is actually in the document,
158 they're all cloned via CopyField()...
160 class SW_DLLPUBLIC SwAuthorityField final
: public SwField
162 rtl::Reference
<SwAuthEntry
> m_xAuthEntry
;
163 mutable sal_IntPtr m_nTempSequencePos
;
164 mutable sal_IntPtr m_nTempSequencePosRLHidden
; ///< hidden redlines
166 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
167 virtual std::unique_ptr
<SwField
> Copy() const override
;
170 enum TargetType
: sal_uInt16
175 BibliographyTableRow
= 3,
176 // BibliographyTablePage = 4, // TODO: implement
180 /// For internal use only, in general continue using ExpandField() instead.
181 OUString
ConditionalExpandAuthIdentifier(SwRootFrame
const* pLayout
) const;
184 OUString
ExpandCitation(ToxAuthorityField eField
, SwRootFrame
const* pLayout
) const;
186 SwAuthorityField(SwAuthorityFieldType
* pType
, std::u16string_view rFieldContents
);
187 SwAuthorityField(SwAuthorityFieldType
* pType
, SwAuthEntry
* pAuthEntry
);
188 virtual ~SwAuthorityField() override
;
190 const OUString
& GetFieldText(ToxAuthorityField eField
) const;
192 virtual void SetPar1(const OUString
& rStr
) override
;
193 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
195 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const override
;
196 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
) override
;
198 SwAuthEntry
* GetAuthEntry() const { return m_xAuthEntry
.get(); }
200 virtual OUString
GetDescription() const override
;
203 * Returns the line matching the source's default row in the ToX.
205 * \param pLayout layout to be used
206 * \param pTOX bibliography table to take the format of the string from
207 * \return entry formatted as the appropriate authority type in the table
209 OUString
GetAuthority(const SwRootFrame
*pLayout
,
210 const SwForm
*pTOX
= nullptr) const;
213 * Returns which target should be used when the entry
214 * (the standalone field, such as '[ASDF]', not in the table) is clicked.
216 TargetType
GetTargetType() const;
218 * Returns absolute target URL in case there is one (GetTargetType() should be checked).
219 * If there isn't one, the result is undefined.
221 OUString
GetAbsoluteURL() const;
224 * Returns full URI for the URL, relative if specified
225 * \param bRelative whether the path should be relative (when dealing with local files)
227 OUString
GetURI(bool bRelative
) const;
229 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
232 inline OUString
const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos
) const
234 SAL_WARN_IF(AUTH_FIELD_END
<= ePos
, "sw", "wrong index");
235 return m_aAuthFields
[ePos
];
237 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos
, const OUString
& rField
)
239 SAL_WARN_IF(AUTH_FIELD_END
<= ePos
, "sw", "wrong index");
240 if(AUTH_FIELD_END
> ePos
)
241 m_aAuthFields
[ePos
] = rField
;
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */