LibreOffice Module sw (master)  1
authfld.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_SW_INC_AUTHFLD_HXX
20 #define INCLUDED_SW_INC_AUTHFLD_HXX
21 
22 #include "swdllapi.h"
23 #include "fldbas.hxx"
24 #include "toxe.hxx"
25 #include <rtl/ref.hxx>
26 #include <sal/log.hxx>
28 
29 #include <memory>
30 #include <vector>
31 
32 class SwTOXInternational;
33 class SwTextAttr;
34 
36 {
37 friend class SwAuthorityFieldType;
39 public:
40  SwAuthEntry() = default;
41  SwAuthEntry( const SwAuthEntry& rCopy );
42  bool operator==(const SwAuthEntry& rComp) const;
43 
44  inline OUString const & GetAuthorField(ToxAuthorityField ePos) const;
45  inline void SetAuthorField(ToxAuthorityField ePos,
46  const OUString& rField);
47  void dumpAsXml(xmlTextWriterPtr pWriter) const;
48 };
49 
51 {
55  eField(AUTH_FIELD_END),
56  bSortAscending(true){}
57 };
58 
59 typedef std::vector<SwTOXSortKey> SortKeyArr;
60 typedef std::vector<rtl::Reference<SwAuthEntry>> SwAuthDataArr;
61 
63 {
66  std::vector<SwAuthEntry*> m_SequArr;
67  std::vector<SwAuthEntry*> m_SequArrRLHidden;
71  bool m_bIsSequence :1;
72  bool m_bSortByDocument :1;
74  OUString m_sSortAlgorithm;
75 
76  virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
77 
78 public:
80  virtual ~SwAuthorityFieldType() override;
81 
82  virtual std::unique_ptr<SwFieldType> Copy() const override;
83 
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;
86 
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);
92  {
93  m_SequArr.clear();
94  m_SequArrRLHidden.clear();
95  }
96 
97  void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
98  SwAuthEntry* GetEntryByIdentifier(std::u16string_view rIdentifier) const;
99 
100  bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
101  // import interface
102  sal_uInt16 AppendField(const SwAuthEntry& rInsert);
103 
104  sal_uInt16 GetSequencePos(const SwAuthEntry* pAuthEntry, SwRootFrame const* pLayout);
105  std::unique_ptr<SwTOXInternational> CreateTOXInternational() const;
106 
107  bool IsSequence() const {return m_bIsSequence;}
108  void SetSequence(bool bSet)
109  {
110  DelSequenceArray();
111  m_bIsSequence = bSet;
112  }
113 
115  {
116  m_cPrefix = cPre;
117  m_cSuffix = cSuf;
118  }
119  sal_Unicode GetPrefix() const { return m_cPrefix;}
120  sal_Unicode GetSuffix() const { return m_cSuffix;}
121 
122  bool IsSortByDocument() const {return m_bSortByDocument;}
123  void SetSortByDocument(bool bSet)
124  {
125  DelSequenceArray();
126  m_bSortByDocument = bSet;
127  }
128 
129  sal_uInt16 GetSortKeyCount() const ;
130  const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
131  void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[]);
132 
133  //initui.cxx
134  static OUString const & GetAuthFieldName(ToxAuthorityField eType);
135  static OUString const & GetAuthTypeName(ToxAuthorityType eType);
136 
137  LanguageType GetLanguage() const {return m_eLanguage;}
138  void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
139 
140  const OUString& GetSortAlgorithm() const {return m_sSortAlgorithm;}
141  void SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
142 
143 };
144 
154 {
156  mutable sal_IntPtr m_nTempSequencePos;
157  mutable sal_IntPtr m_nTempSequencePosRLHidden;
158 
159  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
160  virtual std::unique_ptr<SwField> Copy() const override;
161 
162 public:
164  OUString ConditionalExpandAuthIdentifier(SwRootFrame const* pLayout) const;
165 
166  //To handle Citation
167  OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
168 
169  SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
171  virtual ~SwAuthorityField() override;
172 
173  const OUString & GetFieldText(ToxAuthorityField eField) const;
174 
175  virtual void SetPar1(const OUString& rStr) override;
176  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
177 
178  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
179  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
180 
181  SwAuthEntry* GetAuthEntry() const { return m_xAuthEntry.get(); }
182 
183  virtual OUString GetDescription() const override;
184 
186  OUString GetAuthority(const SwTextAttr* pTextAttr, const SwRootFrame* pLayout) const;
187 
188  bool HasURL() const;
189  OUString GetAbsoluteURL() const;
190 
191  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
192 };
193 
194 inline OUString const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
195 {
196  SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
197  return m_aAuthFields[ePos];
198 }
199 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
200 {
201  SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
202  if(AUTH_FIELD_END > ePos)
203  m_aAuthFields[ePos] = rField;
204 }
205 
206 #endif
207 
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:194
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:832
std::vector< rtl::Reference< SwAuthEntry > > SwAuthDataArr
Definition: authfld.hxx:60
SwAuthDataArr m_DataArr
Definition: authfld.hxx:65
virtual std::unique_ptr< SwFieldType > Copy() const =0
void DelSequenceArray()
Definition: authfld.hxx:91
void SetSortAlgorithm(const OUString &rSet)
Definition: authfld.hxx:141
Base class of all fields.
Definition: fldbas.hxx:289
Definition: doc.hxx:187
sal_Unicode m_cPrefix
Definition: authfld.hxx:69
void SetAuthorField(ToxAuthorityField ePos, const OUString &rField)
Definition: authfld.hxx:199
void SetDoc(SwDoc *pNewDoc)
Definition: authfld.hxx:87
sal_Unicode m_cSuffix
Definition: authfld.hxx:70
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: authfld.cxx:684
static LanguageType nLang
Definition: srtdlg.cxx:51
OUString m_aAuthFields[AUTH_FIELD_END]
Definition: authfld.hxx:38
sal_uInt16 sal_Unicode
void SetPreSuffix(sal_Unicode cPre, sal_Unicode cSuf)
Definition: authfld.hxx:114
sal_Unicode GetPrefix() const
Definition: authfld.hxx:119
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:153
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:357
eField
void SetSortByDocument(bool bSet)
Definition: authfld.hxx:123
LanguageType m_eLanguage
Definition: authfld.hxx:73
sal_IntPtr m_nTempSequencePos
Definition: authfld.hxx:156
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:344
SwAuthEntry * GetAuthEntry() const
Definition: authfld.hxx:181
virtual OUString GetDescription() const
Definition: fldbas.cxx:810
SwAuthEntry()=default
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:381
rtl::Reference< SwAuthEntry > m_xAuthEntry
Definition: authfld.hxx:155
struct _xmlTextWriter * xmlTextWriterPtr
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:329
void SetSequence(bool bSet)
Definition: authfld.hxx:108
virtual std::unique_ptr< SwField > Copy() const =0
SwDoc * GetDoc()
Definition: authfld.hxx:88
sal_Unicode GetSuffix() const
Definition: authfld.hxx:120
LanguageType GetLanguage() const
Definition: authfld.hxx:137
bool IsSequence() const
Definition: authfld.hxx:107
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
bool bSortAscending
Definition: authfld.hxx:53
void SetLanguage(LanguageType nLang)
Definition: authfld.hxx:138
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:141
ToxAuthorityField
Definition: toxe.hxx:82
std::vector< SwAuthEntry * > m_SequArrRLHidden
hidden redlines
Definition: authfld.hxx:67
bool operator==(const SwAuthEntry &rComp) const
Definition: authfld.cxx:61
ToxAuthorityField eField
Definition: authfld.hxx:52
#define SAL_WARN_IF(condition, area, stream)
sal_IntPtr m_nTempSequencePosRLHidden
hidden redlines
Definition: authfld.hxx:157
std::vector< SwTOXSortKey > SortKeyArr
Definition: authfld.hxx:59
SortKeyArr m_SortKeyArr
Definition: authfld.hxx:68
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:144
const OUString & GetSortAlgorithm() const
Definition: authfld.hxx:140
std::vector< SwAuthEntry * > m_SequArr
Definition: authfld.hxx:66
bool IsSortByDocument() const
Definition: authfld.hxx:122
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:302
ToxAuthorityType
Definition: toxe.hxx:52
OUString m_sSortAlgorithm
Definition: authfld.hxx:74