Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / expfld.hxx
bloba74734191cb518d5b48c56f1eac4dad85c736e5e
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 #ifndef INCLUDED_SW_INC_EXPFLD_HXX
20 #define INCLUDED_SW_INC_EXPFLD_HXX
22 #include "swdllapi.h"
23 #include <fldbas.hxx>
24 #include <cellfml.hxx>
25 #include <set>
26 #include <memory>
27 #include <vector>
29 class SfxPoolItem;
30 class SwTextNode;
31 class SwFrame;
32 struct SwPosition;
33 class SwTextField;
34 class SwDoc;
35 class SwFormatField;
36 class SetGetExpFields;
37 class SwEditShell;
39 /// Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
40 const SwTextNode* GetBodyTextNode( const SwDoc& pDoc, SwPosition& rPos,
41 const SwFrame& rFrame );
43 OUString ReplacePoint(const OUString& sTmpName, bool bWithCommandType = false);
45 struct SeqFieldLstElem
47 OUString sDlgEntry;
48 sal_uInt16 nSeqNo;
50 SeqFieldLstElem( const OUString& rStr, sal_uInt16 nNo )
51 : sDlgEntry( rStr ), nSeqNo( nNo )
55 class SW_DLLPUBLIC SwSeqFieldList
57 std::vector<SeqFieldLstElem*> maData;
58 public:
59 ~SwSeqFieldList()
61 for( std::vector<SeqFieldLstElem*>::const_iterator it = maData.begin(); it != maData.end(); ++it )
62 delete *it;
65 bool InsertSort(SeqFieldLstElem* pNew);
66 bool SeekEntry(const SeqFieldLstElem& rNew, size_t* pPos) const;
68 size_t Count() { return maData.size(); }
69 SeqFieldLstElem* operator[](size_t nIndex) { return maData[nIndex]; }
70 const SeqFieldLstElem* operator[](size_t nIndex) const { return maData[nIndex]; }
71 void Clear() { maData.clear(); }
74 class SwGetExpFieldType : public SwValueFieldType
76 public:
77 SwGetExpFieldType(SwDoc* pDoc);
78 virtual SwFieldType* Copy() const override;
80 /** Overlay, because get-field cannot be changed and therefore
81 does not need to be updated. Update at changing of set-values! */
82 protected:
83 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
86 class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
88 OUString sExpand;
89 bool bIsInBodyText;
90 sal_uInt16 nSubType;
92 bool bLateInitialization; // #i82544#
94 virtual OUString Expand() const override;
95 virtual SwField* Copy() const override;
97 public:
98 SwGetExpField( SwGetExpFieldType*, const OUString& rFormel,
99 sal_uInt16 nSubType, sal_uLong nFormat = 0);
101 virtual void SetValue( const double& rVal ) override;
102 virtual void SetLanguage(LanguageType nLng) override;
104 inline void ChgExpStr(const OUString& rExpand);
106 /// Called by formatting.
107 inline bool IsInBodyText() const;
109 /// Set by UpdateExpFields where node position is known.
110 inline void ChgBodyTextFlag( bool bIsInBody );
112 /** For fields in header/footer/footnotes/flys:
113 Only called by formatting!! */
114 void ChangeExpansion( const SwFrame&, const SwTextField& );
116 virtual OUString GetFieldName() const override;
118 /// Change formula.
119 virtual OUString GetPar2() const override;
120 virtual void SetPar2(const OUString& rStr) override;
122 virtual sal_uInt16 GetSubType() const override;
123 virtual void SetSubType(sal_uInt16 nType) override;
124 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
125 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
127 static sal_Int32 GetReferenceTextPos( const SwFormatField& rFormat, SwDoc& rDoc, sal_Int32 nHint = 0);
128 // #i82544#
129 void SetLateInitialization() { bLateInitialization = true;}
132 inline void SwGetExpField::ChgExpStr(const OUString& rExpand)
133 { sExpand = rExpand;}
135 /// Called by formatting.
136 inline bool SwGetExpField::IsInBodyText() const
137 { return bIsInBodyText; }
139 /// Set by UpdateExpFields where node position is known.
140 inline void SwGetExpField::ChgBodyTextFlag( bool bIsInBody )
141 { bIsInBodyText = bIsInBody; }
143 class SwSetExpField;
145 class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType
147 OUString sName;
148 const SwNode* pOutlChgNd;
149 OUString sDelim;
150 sal_uInt16 nType;
151 sal_uInt8 nLevel;
152 bool bDeleted;
154 protected:
155 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
157 public:
158 SwSetExpFieldType( SwDoc* pDoc, const OUString& rName,
159 sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
160 virtual SwFieldType* Copy() const override;
161 virtual OUString GetName() const override;
163 inline void SetType(sal_uInt16 nTyp);
164 inline sal_uInt16 GetType() const;
166 void SetSeqFormat(sal_uLong nFormat);
167 sal_uLong GetSeqFormat();
169 bool IsDeleted() const { return bDeleted; }
170 void SetDeleted( bool b ) { bDeleted = b; }
172 /// Overlay, because set-field takes care for its being updated by itself.
173 inline const OUString& GetSetRefName() const;
175 void SetSeqRefNo( SwSetExpField& rField );
177 size_t GetSeqFieldList( SwSeqFieldList& rList );
179 /// Number sequence fields chapterwise if required.
180 const OUString& GetDelimiter() const { return sDelim; }
181 void SetDelimiter( const OUString& s ) { sDelim = s; }
182 sal_uInt8 GetOutlineLvl() const { return nLevel; }
183 void SetOutlineLvl( sal_uInt8 n ) { nLevel = n; }
184 void SetChapter( SwSetExpField& rField, const SwNode& rNd );
186 /** Member only for SwDoc::UpdateExpField.
187 It is needed only at runtime of sequence field types! */
188 const SwNode* GetOutlineChgNd() const { return pOutlChgNd; }
189 void SetOutlineChgNd( const SwNode* p ) { pOutlChgNd = p; }
191 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
192 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
195 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
197 nType = nTyp;
198 EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
201 inline sal_uInt16 SwSetExpFieldType::GetType() const
202 { return nType; }
204 inline const OUString& SwSetExpFieldType::GetSetRefName() const
205 { return sName; }
207 class SW_DLLPUBLIC SwSetExpField : public SwFormulaField
209 OUString sExpand;
210 OUString aPText;
211 bool bInput;
212 sal_uInt16 nSeqNo;
213 sal_uInt16 nSubType;
214 SwFormatField * mpFormatField; /// pool item to which the SwSetExpField belongs
216 virtual OUString Expand() const override;
217 virtual SwField* Copy() const override;
219 public:
220 SwSetExpField(SwSetExpFieldType*, const OUString& rFormel, sal_uLong nFormat = 0);
222 void SetFormatField(SwFormatField & rFormatField);
223 SwFormatField* GetFormatField() { return mpFormatField;}
225 virtual void SetValue( const double& rVal ) override;
227 inline const OUString& GetExpStr() const;
229 inline void ChgExpStr( const OUString& rExpand );
231 inline void SetPromptText(const OUString& rStr);
232 inline const OUString& GetPromptText() const;
234 inline void SetInputFlag(bool bInp);
235 inline bool GetInputFlag() const;
237 virtual OUString GetFieldName() const override;
239 virtual sal_uInt16 GetSubType() const override;
240 virtual void SetSubType(sal_uInt16 nType) override;
242 inline bool IsSequenceField() const;
244 /// Logical number, sequence fields.
245 void SetSeqNumber( sal_uInt16 n ) { nSeqNo = n; }
246 sal_uInt16 GetSeqNumber() const { return nSeqNo; }
248 /// Query name only.
249 virtual OUString GetPar1() const override;
251 /// Query formula.
252 virtual OUString GetPar2() const override;
253 virtual void SetPar2(const OUString& rStr) override;
254 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
255 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
258 inline const OUString& SwSetExpField::GetExpStr() const
259 { return sExpand; }
261 inline void SwSetExpField::ChgExpStr( const OUString& rExpand )
262 { sExpand = rExpand; }
264 inline void SwSetExpField::SetPromptText(const OUString& rStr)
265 { aPText = rStr; }
267 inline const OUString& SwSetExpField::GetPromptText() const
268 { return aPText; }
270 inline void SwSetExpField::SetInputFlag(bool bInp)
271 { bInput = bInp; }
273 inline bool SwSetExpField::GetInputFlag() const
274 { return bInput; }
276 inline bool SwSetExpField::IsSequenceField() const
277 { return 0 != (nsSwGetSetExpType::GSE_SEQ & static_cast<SwSetExpFieldType*>(GetTyp())->GetType()); }
279 class SwInputFieldType : public SwFieldType
281 SwDoc* pDoc;
282 public:
283 SwInputFieldType( SwDoc* pDoc );
285 virtual SwFieldType* Copy() const override;
287 SwDoc* GetDoc() const { return pDoc; }
290 class SW_DLLPUBLIC SwInputField : public SwField
292 mutable OUString aContent;
293 OUString aPText;
294 OUString aHelp;
295 OUString aToolTip;
296 sal_uInt16 nSubType;
297 bool mbIsFormField;
299 SwFormatField* mpFormatField; // attribute to which the <SwInputField> belongs to
301 virtual OUString Expand() const override;
302 virtual SwField* Copy() const override;
304 // Accessing Input Field's content
305 const OUString& getContent() const { return aContent;}
307 public:
308 /// Direct input via dialog; delete old value.
309 SwInputField(
310 SwInputFieldType* pFieldType,
311 const OUString& rContent,
312 const OUString& rPrompt,
313 sal_uInt16 nSubType,
314 sal_uLong nFormat = 0,
315 bool bIsFormField = true );
316 virtual ~SwInputField() override;
318 void SetFormatField( SwFormatField& rFormatField );
319 SwFormatField* GetFormatField() { return mpFormatField;}
321 // Providing new Input Field's content:
322 // Fill Input Field's content depending on <nSupType>.
323 void applyFieldContent( const OUString& rNewFieldContent );
325 bool isFormField() const;
327 virtual OUString GetFieldName() const override;
329 /// Content
330 virtual OUString GetPar1() const override;
331 virtual void SetPar1(const OUString& rStr) override;
333 /// aPromptText
334 virtual OUString GetPar2() const override;
335 virtual void SetPar2(const OUString& rStr) override;
337 const OUString& GetHelp() const;
338 void SetHelp(const OUString & rStr);
340 const OUString& GetToolTip() const;
341 void SetToolTip(const OUString & rStr);
343 virtual sal_uInt16 GetSubType() const override;
344 virtual void SetSubType(sal_uInt16 nSub) override;
345 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
346 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
349 // Sorted list of input fields and DropDown fields
350 class SwInputFieldList
352 public:
353 SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst = false );
354 ~SwInputFieldList();
356 size_t Count() const;
357 SwField* GetField(size_t nId);
359 void GotoFieldPos(size_t nId);
360 void PushCursor();
361 void PopCursor();
363 /** Put all that are new into SortList for updating. @return true if not empty.
364 (For Glossary: only update its input-fields).
365 Compare TmpLst with current fields. */
366 bool BuildSortLst();
368 private:
369 SwEditShell* pSh;
370 std::unique_ptr<SetGetExpFields> pSrtLst;
371 std::set<const SwTextField*> aTmpLst;
374 /// Implementation in tblcalc.cxx.
375 class SwTableFieldType : public SwValueFieldType
377 public:
378 SwTableFieldType(SwDoc* pDocPtr);
379 virtual SwFieldType* Copy() const override;
382 class SwTableField : public SwValueField, public SwTableFormula
384 OUString sExpand;
385 sal_uInt16 nSubType;
387 virtual OUString Expand() const override;
388 virtual SwField* Copy() const override;
390 /// Search TextNode containing the field.
391 virtual const SwNode* GetNodeOfFormula() const override;
393 OUString GetCommand();
395 public:
396 SwTableField( SwTableFieldType*, const OUString& rFormel,
397 sal_uInt16 nSubType, sal_uLong nFormat = 0);
399 virtual void SetValue( const double& rVal ) override;
400 virtual sal_uInt16 GetSubType() const override;
401 virtual void SetSubType(sal_uInt16 nType) override;
403 void ChgExpStr(const OUString& rStr) { sExpand = rStr; }
405 void CalcField( SwTableCalcPara& rCalcPara );
407 virtual OUString GetFieldName() const override;
409 /// The formula.
410 virtual OUString GetPar2() const override;
411 virtual void SetPar2(const OUString& rStr) override;
412 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
413 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
416 #endif // INCLUDED_SW_INC_EXPFLD_HXX
418 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */