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 
33 {
35 public:
36  SwAuthEntry() = default;
37  SwAuthEntry( const SwAuthEntry& rCopy );
38  bool operator==(const SwAuthEntry& rComp);
39 
40  inline OUString const & GetAuthorField(ToxAuthorityField ePos) const;
41  inline void SetAuthorField(ToxAuthorityField ePos,
42  const OUString& rField);
43 };
44 
46 {
50  eField(AUTH_FIELD_END),
51  bSortAscending(true){}
52 };
53 
54 typedef std::vector<SwTOXSortKey> SortKeyArr;
55 typedef std::vector<rtl::Reference<SwAuthEntry>> SwAuthDataArr;
56 
58 {
61  std::vector<SwAuthEntry*> m_SequArr;
62  std::vector<SwAuthEntry*> m_SequArrRLHidden;
66  bool m_bIsSequence :1;
67  bool m_bSortByDocument :1;
69  OUString m_sSortAlgorithm;
70 
71 protected:
72 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
73 
74 public:
76  virtual ~SwAuthorityFieldType() override;
77 
78  virtual std::unique_ptr<SwFieldType> Copy() const override;
79 
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;
82 
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);
88  {
89  m_SequArr.clear();
90  m_SequArrRLHidden.clear();
91  }
92 
93  void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
94  SwAuthEntry* GetEntryByIdentifier(const OUString& rIdentifier) const;
95 
96  bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
97  // import interface
98  sal_uInt16 AppendField(const SwAuthEntry& rInsert);
99 
100  sal_uInt16 GetSequencePos(const SwAuthEntry* pAuthEntry, SwRootFrame const* pLayout);
101 
102  bool IsSequence() const {return m_bIsSequence;}
103  void SetSequence(bool bSet)
104  {
105  DelSequenceArray();
106  m_bIsSequence = bSet;
107  }
108 
110  {
111  m_cPrefix = cPre;
112  m_cSuffix = cSuf;
113  }
114  sal_Unicode GetPrefix() const { return m_cPrefix;}
115  sal_Unicode GetSuffix() const { return m_cSuffix;}
116 
117  bool IsSortByDocument() const {return m_bSortByDocument;}
118  void SetSortByDocument(bool bSet)
119  {
120  DelSequenceArray();
121  m_bSortByDocument = bSet;
122  }
123 
124  sal_uInt16 GetSortKeyCount() const ;
125  const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
126  void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[]);
127 
128  //initui.cxx
129  static OUString const & GetAuthFieldName(ToxAuthorityField eType);
130  static OUString const & GetAuthTypeName(ToxAuthorityType eType);
131 
132  LanguageType GetLanguage() const {return m_eLanguage;}
133  void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
134 
135  const OUString& GetSortAlgorithm() const {return m_sSortAlgorithm;}
136  void SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
137 
138 };
139 
148 class SAL_DLLPUBLIC_RTTI SwAuthorityField : public SwField
149 {
151  mutable sal_IntPtr m_nTempSequencePos;
152  mutable sal_IntPtr m_nTempSequencePosRLHidden;
153 
154  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
155  virtual std::unique_ptr<SwField> Copy() const override;
156 
157 public:
159  OUString ConditionalExpandAuthIdentifier(SwRootFrame const* pLayout) const;
160 
161  //To handle Citation
162  SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
163 
164  SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
166  virtual ~SwAuthorityField() override;
167 
168  OUString GetFieldText(ToxAuthorityField eField) const;
169 
170  virtual void SetPar1(const OUString& rStr) override;
171  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
172 
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;
175 
176  SwAuthEntry* GetAuthEntry() const { return m_xAuthEntry.get(); }
177 
178  virtual OUString GetDescription() const override;
179 };
180 
181 inline OUString const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
182 {
183  SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
184  return aAuthFields[ePos];
185 }
186 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
187 {
188  SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
189  if(AUTH_FIELD_END > ePos)
190  aAuthFields[ePos] = rField;
191 }
192 
193 #endif
194 
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
bool operator==(const SwAuthEntry &rComp)
Definition: authfld.cxx:61
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:181
std::vector< rtl::Reference< SwAuthEntry > > SwAuthDataArr
Definition: authfld.hxx:55
SwAuthDataArr m_DataArr
Definition: authfld.hxx:60
virtual std::unique_ptr< SwFieldType > Copy() const =0
void DelSequenceArray()
Definition: authfld.hxx:87
void SetSortAlgorithm(const OUString &rSet)
Definition: authfld.hxx:136
Base class of all fields.
Definition: fldbas.hxx:279
Definition: doc.hxx:185
sal_Unicode m_cPrefix
Definition: authfld.hxx:64
void SetAuthorField(ToxAuthorityField ePos, const OUString &rField)
Definition: authfld.hxx:186
void SetDoc(SwDoc *pNewDoc)
Definition: authfld.hxx:83
sal_Unicode m_cSuffix
Definition: authfld.hxx:65
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
static LanguageType nLang
Definition: srtdlg.cxx:58
sal_uInt16 sal_Unicode
void SetPreSuffix(sal_Unicode cPre, sal_Unicode cSuf)
Definition: authfld.hxx:109
sal_Unicode GetPrefix() const
Definition: authfld.hxx:114
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:148
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:314
eField
Definition: fields.hxx:26
void SetSortByDocument(bool bSet)
Definition: authfld.hxx:118
LanguageType m_eLanguage
Definition: authfld.hxx:68
sal_IntPtr m_nTempSequencePos
Definition: authfld.hxx:151
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:301
SwAuthEntry * GetAuthEntry() const
Definition: authfld.hxx:176
virtual OUString GetDescription() const
Definition: fldbas.cxx:761
SwAuthEntry()=default
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:338
rtl::Reference< SwAuthEntry > m_xAuthEntry
Definition: authfld.hxx:150
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:286
void SetSequence(bool bSet)
Definition: authfld.hxx:103
virtual std::unique_ptr< SwField > Copy() const =0
SwDoc * GetDoc()
Definition: authfld.hxx:84
sal_Unicode GetSuffix() const
Definition: authfld.hxx:115
LanguageType GetLanguage() const
Definition: authfld.hxx:132
bool IsSequence() const
Definition: authfld.hxx:102
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: calbck.hxx:183
bool bSortAscending
Definition: authfld.hxx:48
void SetLanguage(LanguageType nLang)
Definition: authfld.hxx:133
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:150
ToxAuthorityField
Definition: toxe.hxx:82
std::vector< SwAuthEntry * > m_SequArrRLHidden
hidden redlines
Definition: authfld.hxx:62
ToxAuthorityField eField
Definition: authfld.hxx:47
#define SAL_WARN_IF(condition, area, stream)
sal_IntPtr m_nTempSequencePosRLHidden
hidden redlines
Definition: authfld.hxx:152
std::vector< SwTOXSortKey > SortKeyArr
Definition: authfld.hxx:54
SortKeyArr m_SortKeyArr
Definition: authfld.hxx:63
OUString aAuthFields[AUTH_FIELD_END]
Definition: authfld.hxx:34
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:153
const OUString & GetSortAlgorithm() const
Definition: authfld.hxx:135
std::vector< SwAuthEntry * > m_SequArr
Definition: authfld.hxx:61
bool IsSortByDocument() const
Definition: authfld.hxx:117
ToxAuthorityType
Definition: toxe.hxx:52
OUString m_sSortAlgorithm
Definition: authfld.hxx:69