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  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
72 
73 public:
75  virtual ~SwAuthorityFieldType() override;
76 
77  virtual std::unique_ptr<SwFieldType> Copy() const override;
78 
79  virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
80  virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
81 
82  void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
83  SwDoc* GetDoc(){ return m_pDoc; }
84  void RemoveField(const SwAuthEntry* nHandle);
85  SwAuthEntry* AddField(const OUString& rFieldContents);
87  {
88  m_SequArr.clear();
89  m_SequArrRLHidden.clear();
90  }
91 
92  void GetAllEntryIdentifiers( std::vector<OUString>& rToFill ) const;
93  SwAuthEntry* GetEntryByIdentifier(const OUString& rIdentifier) const;
94 
95  bool ChangeEntryContent(const SwAuthEntry* pNewEntry);
96  // import interface
97  sal_uInt16 AppendField(const SwAuthEntry& rInsert);
98 
99  sal_uInt16 GetSequencePos(const SwAuthEntry* pAuthEntry, SwRootFrame const* pLayout);
100 
101  bool IsSequence() const {return m_bIsSequence;}
102  void SetSequence(bool bSet)
103  {
104  DelSequenceArray();
105  m_bIsSequence = bSet;
106  }
107 
109  {
110  m_cPrefix = cPre;
111  m_cSuffix = cSuf;
112  }
113  sal_Unicode GetPrefix() const { return m_cPrefix;}
114  sal_Unicode GetSuffix() const { return m_cSuffix;}
115 
116  bool IsSortByDocument() const {return m_bSortByDocument;}
117  void SetSortByDocument(bool bSet)
118  {
119  DelSequenceArray();
120  m_bSortByDocument = bSet;
121  }
122 
123  sal_uInt16 GetSortKeyCount() const ;
124  const SwTOXSortKey* GetSortKey(sal_uInt16 nIdx) const ;
125  void SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey const nKeys[]);
126 
127  //initui.cxx
128  static OUString const & GetAuthFieldName(ToxAuthorityField eType);
129  static OUString const & GetAuthTypeName(ToxAuthorityType eType);
130 
131  LanguageType GetLanguage() const {return m_eLanguage;}
132  void SetLanguage(LanguageType nLang) {m_eLanguage = nLang;}
133 
134  const OUString& GetSortAlgorithm() const {return m_sSortAlgorithm;}
135  void SetSortAlgorithm(const OUString& rSet) {m_sSortAlgorithm = rSet;}
136 
137 };
138 
147 class SAL_DLLPUBLIC_RTTI SwAuthorityField final : public SwField
148 {
150  mutable sal_IntPtr m_nTempSequencePos;
151  mutable sal_IntPtr m_nTempSequencePosRLHidden;
152 
153  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
154  virtual std::unique_ptr<SwField> Copy() const override;
155 
156 public:
158  OUString ConditionalExpandAuthIdentifier(SwRootFrame const* pLayout) const;
159 
160  //To handle Citation
161  SW_DLLPUBLIC OUString ExpandCitation(ToxAuthorityField eField, SwRootFrame const* pLayout) const;
162 
163  SwAuthorityField(SwAuthorityFieldType* pType, const OUString& rFieldContents);
165  virtual ~SwAuthorityField() override;
166 
167  const OUString & GetFieldText(ToxAuthorityField eField) const;
168 
169  virtual void SetPar1(const OUString& rStr) override;
170  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
171 
172  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
173  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
174 
175  SwAuthEntry* GetAuthEntry() const { return m_xAuthEntry.get(); }
176 
177  virtual OUString GetDescription() const override;
178 };
179 
180 inline OUString const & SwAuthEntry::GetAuthorField(ToxAuthorityField ePos) const
181 {
182  SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
183  return aAuthFields[ePos];
184 }
185 inline void SwAuthEntry::SetAuthorField(ToxAuthorityField ePos, const OUString& rField)
186 {
187  SAL_WARN_IF(AUTH_FIELD_END <= ePos, "sw", "wrong index");
188  if(AUTH_FIELD_END > ePos)
189  aAuthFields[ePos] = rField;
190 }
191 
192 #endif
193 
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:234
bool operator==(const SwAuthEntry &rComp)
Definition: authfld.cxx:56
OUString const & GetAuthorField(ToxAuthorityField ePos) const
Definition: authfld.hxx:180
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:86
void SetSortAlgorithm(const OUString &rSet)
Definition: authfld.hxx:135
Base class of all fields.
Definition: fldbas.hxx:280
Definition: doc.hxx:185
sal_Unicode m_cPrefix
Definition: authfld.hxx:64
void SetAuthorField(ToxAuthorityField ePos, const OUString &rField)
Definition: authfld.hxx:185
void SetDoc(SwDoc *pNewDoc)
Definition: authfld.hxx:82
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:60
sal_uInt16 sal_Unicode
void SetPreSuffix(sal_Unicode cPre, sal_Unicode cSuf)
Definition: authfld.hxx:108
sal_Unicode GetPrefix() const
Definition: authfld.hxx:113
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:147
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:306
eField
Definition: fields.hxx:26
void SetSortByDocument(bool bSet)
Definition: authfld.hxx:117
LanguageType m_eLanguage
Definition: authfld.hxx:68
sal_IntPtr m_nTempSequencePos
Definition: authfld.hxx:150
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:293
SwAuthEntry * GetAuthEntry() const
Definition: authfld.hxx:175
virtual OUString GetDescription() const
Definition: fldbas.cxx:753
SwAuthEntry()=default
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:330
rtl::Reference< SwAuthEntry > m_xAuthEntry
Definition: authfld.hxx:149
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:278
void SetSequence(bool bSet)
Definition: authfld.hxx:102
virtual std::unique_ptr< SwField > Copy() const =0
SwDoc * GetDoc()
Definition: authfld.hxx:83
sal_Unicode GetSuffix() const
Definition: authfld.hxx:114
LanguageType GetLanguage() const
Definition: authfld.hxx:131
bool IsSequence() const
Definition: authfld.hxx:101
#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:132
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:140
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:151
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:143
const OUString & GetSortAlgorithm() const
Definition: authfld.hxx:134
std::vector< SwAuthEntry * > m_SequArr
Definition: authfld.hxx:61
bool IsSortByDocument() const
Definition: authfld.hxx:116
ToxAuthorityType
Definition: toxe.hxx:52
OUString m_sSortAlgorithm
Definition: authfld.hxx:69