tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sw / inc / authfld.hxx
blobab1d87f74a8b098b5ded263b5974f6f042918e63
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 #pragma once
21 #include <sal/config.h>
23 #include "swdllapi.h"
24 #include "fldbas.hxx"
25 #include "toxe.hxx"
26 #include <rtl/ref.hxx>
27 #include <sal/log.hxx>
28 #include <salhelper/simplereferenceobject.hxx>
30 #include <memory>
31 #include <vector>
33 class SwTOXInternational;
34 class SwTextAttr;
35 class SwForm;
37 class SwAuthEntry final : public salhelper::SimpleReferenceObject
39 friend class SwAuthorityFieldType;
40 OUString m_aAuthFields[AUTH_FIELD_END];
41 public:
42 SwAuthEntry() = default;
43 SwAuthEntry( const SwAuthEntry& rCopy );
44 bool operator==(const SwAuthEntry& rComp) const;
46 inline OUString const & GetAuthorField(ToxAuthorityField ePos) const;
47 inline void SetAuthorField(ToxAuthorityField ePos,
48 const OUString& rField);
49 void dumpAsXml(xmlTextWriterPtr pWriter) const;
52 struct SwTOXSortKey
54 ToxAuthorityField eField;
55 bool bSortAscending;
56 SwTOXSortKey() :
57 eField(AUTH_FIELD_END),
58 bSortAscending(true){}
61 typedef std::vector<SwTOXSortKey> SortKeyArr;
62 typedef std::vector<rtl::Reference<SwAuthEntry>> SwAuthDataArr;
64 class SW_DLLPUBLIC SwAuthorityFieldType final : public SwFieldType
66 SwDoc* m_pDoc;
67 SwAuthDataArr m_DataArr;
68 std::vector<SwAuthEntry*> m_SequArr;
69 std::vector<SwAuthEntry*> m_SequArrRLHidden; ///< hidden redlines
70 SortKeyArr m_SortKeyArr;
71 sal_Unicode m_cPrefix;
72 sal_Unicode m_cSuffix;
73 bool m_bIsSequence :1;
74 bool m_bSortByDocument :1;
75 LanguageType m_eLanguage;
76 OUString m_sSortAlgorithm;
78 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
80 public:
81 SwAuthorityFieldType(SwDoc* pDoc);
82 virtual ~SwAuthorityFieldType() override;
84 virtual std::unique_ptr<SwFieldType> Copy() const override;
86 virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
87 virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
89 void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
90 SwDoc* GetDoc(){ return m_pDoc; }
91 void RemoveField(const SwAuthEntry* nHandle);
92 SwAuthEntry* AddField(std::u16string_view rFieldContents);
93 void DelSequenceArray()
95 m_SequArr.clear();
96 m_SequArrRLHidden.clear();
99 void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
100 SwAuthEntry* GetEntryByIdentifier(std::u16string_view rIdentifier) const;
102 bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
103 // import interface
104 SwAuthEntry* AppendField(const SwAuthEntry& rInsert);
106 sal_uInt16 GetSequencePos(const SwAuthEntry* pAuthEntry, SwRootFrame const* pLayout);
107 std::unique_ptr<SwTOXInternational> CreateTOXInternational() const;
109 bool IsSequence() const {return m_bIsSequence;}
110 void SetSequence(bool bSet)
112 DelSequenceArray();
113 m_bIsSequence = bSet;
116 void SetPreSuffix( sal_Unicode cPre, sal_Unicode cSuf)
118 m_cPrefix = cPre;
119 m_cSuffix = cSuf;
121 sal_Unicode GetPrefix() const { return m_cPrefix;}
122 sal_Unicode GetSuffix() const { return m_cSuffix;}
124 bool IsSortByDocument() const {return m_bSortByDocument;}
125 void SetSortByDocument(bool bSet)
127 DelSequenceArray();
128 m_bSortByDocument = bSet;
131 sal_uInt16 GetSortKeyCount() const ;
132 const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
133 void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[]);
135 //initui.cxx
136 static OUString const & GetAuthFieldName(ToxAuthorityField eType);
137 static OUString const & GetAuthTypeName(ToxAuthorityType eType);
139 LanguageType GetLanguage() const {return m_eLanguage;}
140 void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
142 const OUString& GetSortAlgorithm() const {return m_sSortAlgorithm;}
143 void SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
144 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
148 /** Represents an inserted bibliography entry, created using Insert -> Table of Contents and Index
149 -> Bibliography Entry.
151 invariant for SwAuthorityField is that it is always registered at its
152 SwAuthorityFieldType via AddField()/RemoveField() & therefore has m_nHandle
153 set - but it's possible that multiple SwAuthorityField have the same
154 m_nHandle & so the number of instances is an upper bound on
155 SwAuthorityField::m_DataArr.size() - it's not clear to me if more than one
156 one of the instances with the same m_nHandle is actually in the document,
157 they're all cloned via CopyField()...
159 class SW_DLLPUBLIC SwAuthorityField final : public SwField
161 rtl::Reference<SwAuthEntry> m_xAuthEntry;
162 mutable sal_IntPtr m_nTempSequencePos;
163 mutable sal_IntPtr m_nTempSequencePosRLHidden; ///< hidden redlines
165 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
166 virtual std::unique_ptr<SwField> Copy() const override;
168 public:
169 enum TargetType : sal_uInt16
171 UseDisplayURL = 0,
172 UseTargetURL = 1,
173 None = 2,
174 BibliographyTableRow = 3,
175 // BibliographyTablePage = 4, // TODO: implement
179 /// For internal use only, in general continue using ExpandField() instead.
180 OUString ConditionalExpandAuthIdentifier(SwRootFrame const* pLayout) const;
182 //To handle Citation
183 OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
185 SwAuthorityField(SwAuthorityFieldType* pType, std::u16string_view rFieldContents);
186 SwAuthorityField(SwAuthorityFieldType* pType, SwAuthEntry* pAuthEntry);
187 virtual ~SwAuthorityField() override;
189 const OUString & GetFieldText(ToxAuthorityField eField) const;
191 virtual void SetPar1(const OUString& rStr) override;
192 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
194 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
195 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
197 SwAuthEntry* GetAuthEntry() const { return m_xAuthEntry.get(); }
199 virtual OUString GetDescription() const override;
202 * Returns the line matching the source's default row in the ToX.
204 * \param pLayout layout to be used
205 * \param pTOX bibliography table to take the format of the string from
206 * \return entry formatted as the appropriate authority type in the table
208 OUString GetAuthority(const SwRootFrame *pLayout,
209 const SwForm *pTOX = nullptr) const;
212 * Returns which target should be used when the entry
213 * (the standalone field, such as '[ASDF]', not in the table) is clicked.
215 TargetType GetTargetType() const;
217 * Returns absolute target URL in case there is one (GetTargetType() should be checked).
218 * If there isn't one, the result is undefined.
220 OUString GetAbsoluteURL() const;
223 * Returns relative URI for the URL
225 OUString GetRelativeURI() const;
227 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
230 inline OUString const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
232 SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
233 return m_aAuthFields[ePos];
235 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
237 SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
238 if(AUTH_FIELD_END > ePos)
239 m_aAuthFields[ePos] = rField;
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */