LibreOffice Module sw (master)  1
expfld.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_EXPFLD_HXX
20 #define INCLUDED_SW_INC_EXPFLD_HXX
21 
22 #include "swdllapi.h"
23 #include "fldbas.hxx"
24 #include "cellfml.hxx"
25 #include <set>
26 #include <memory>
27 #include <vector>
28 #include <tools/solar.h>
29 
30 class SfxPoolItem;
31 class SwTextNode;
32 class SwFrame;
33 class SwRootFrame;
34 struct SwPosition;
35 class SwTextField;
36 class SwDoc;
37 class SwFormatField;
38 class SetGetExpFields;
39 class SwEditShell;
40 
42 const SwTextNode* GetBodyTextNode( const SwDoc& pDoc, SwPosition& rPos,
43  const SwFrame& rFrame );
44 
45 OUString ReplacePoint(const OUString& sTmpName, bool bWithCommandType = false);
46 
48 {
49  OUString sDlgEntry;
50  sal_uInt16 nSeqNo;
51 
52  SeqFieldLstElem( const OUString& rStr, sal_uInt16 nNo )
53  : sDlgEntry( rStr ), nSeqNo( nNo )
54  {}
55 };
56 
58 {
59  std::vector<SeqFieldLstElem> maData;
60 public:
61  bool InsertSort(SeqFieldLstElem aNew);
62  bool SeekEntry(const SeqFieldLstElem& rNew, size_t* pPos) const;
63 
64  size_t Count() { return maData.size(); }
65  SeqFieldLstElem& operator[](size_t nIndex) { return maData[nIndex]; }
66  const SeqFieldLstElem& operator[](size_t nIndex) const { return maData[nIndex]; }
67  void Clear() { maData.clear(); }
68 };
69 
70 class SAL_DLLPUBLIC_RTTI SwGetExpFieldType : public SwValueFieldType
71 {
72 public:
73  SwGetExpFieldType(SwDoc* pDoc);
74  virtual std::unique_ptr<SwFieldType> Copy() const override;
75 
78 protected:
79  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
80 };
81 
83 {
85  OUString m_sExpand;
86  OUString m_sExpandRLHidden;
88  sal_uInt16 m_nSubType;
89 
90  bool m_bLateInitialization; // #i82544#
91 
92  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
93  virtual std::unique_ptr<SwField> Copy() const override;
94  using SwFormulaField::GetValue; // hide it, don't use
95  virtual void SetValue(const double& rVal) override; // hide it
96 
97 public:
98  SwGetExpField( SwGetExpFieldType*, const OUString& rFormel,
99  sal_uInt16 nSubType, sal_uLong nFormat);
100 
101  double GetValue(SwRootFrame const* pLayout) const;
102  void SetValue(const double& rVal, SwRootFrame const* pLayout);
103 
104  virtual void SetLanguage(LanguageType nLng) override;
105 
106  void ChgExpStr(const OUString& rExpand, SwRootFrame const* pLayout);
107 
109  inline bool IsInBodyText() const;
110 
112  inline void ChgBodyTextFlag( bool bIsInBody );
113 
116  void ChangeExpansion( const SwFrame&, const SwTextField& );
117 
118  virtual OUString GetFieldName() const override;
119 
121  virtual OUString GetPar2() const override;
122  virtual void SetPar2(const OUString& rStr) override;
123 
124  virtual sal_uInt16 GetSubType() const override;
125  virtual void SetSubType(sal_uInt16 nType) override;
126  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
127  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
128 
129  static sal_Int32 GetReferenceTextPos( const SwFormatField& rFormat, SwDoc& rDoc, sal_Int32 nHint = 0);
130  // #i82544#
131  void SetLateInitialization() { m_bLateInitialization = true;}
132 };
133 
135 inline bool SwGetExpField::IsInBodyText() const
136  { return m_bIsInBodyText; }
137 
139 inline void SwGetExpField::ChgBodyTextFlag( bool bIsInBody )
140  { m_bIsInBodyText = bIsInBody; }
141 
142 class SwSetExpField;
143 
145 {
146  OUString const m_sName;
147  OUString m_sDelim;
148  sal_uInt16 m_nType;
151 
152 protected:
153  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
154 
155 public:
156  SwSetExpFieldType( SwDoc* pDoc, const OUString& rName,
157  sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
158  virtual std::unique_ptr<SwFieldType> Copy() const override;
159  virtual OUString GetName() const override;
160 
161  inline void SetType(sal_uInt16 nTyp);
162  inline sal_uInt16 GetType() const;
163 
164  void SetSeqFormat(sal_uLong nFormat);
165  sal_uLong GetSeqFormat();
166 
167  bool IsDeleted() const { return m_bDeleted; }
168  void SetDeleted( bool b ) { m_bDeleted = b; }
169 
171  inline const OUString& GetSetRefName() const;
172 
173  void SetSeqRefNo( SwSetExpField& rField );
174 
175  size_t GetSeqFieldList(SwSeqFieldList& rList, SwRootFrame const* pLayout);
176 
178  const OUString& GetDelimiter() const { return m_sDelim; }
179  void SetDelimiter( const OUString& s ) { m_sDelim = s; }
180  sal_uInt8 GetOutlineLvl() const { return m_nLevel; }
181  void SetOutlineLvl( sal_uInt8 n ) { m_nLevel = n; }
182  void SetChapter(SwSetExpField& rField, const SwNode& rNd, SwRootFrame const* pLayout);
183 
184  virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
185  virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
186 };
187 
188 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
189 {
190  m_nType = nTyp;
192 }
193 
194 inline sal_uInt16 SwSetExpFieldType::GetType() const
195  { return m_nType; }
196 
197 inline const OUString& SwSetExpFieldType::GetSetRefName() const
198  { return m_sName; }
199 
201 {
203  OUString msExpand;
204  OUString msExpandRLHidden;
205  OUString maPText;
206  bool mbInput;
207  sal_uInt16 mnSeqNo;
208  sal_uInt16 mnSubType;
210 
211  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
212  virtual std::unique_ptr<SwField> Copy() const override;
213  using SwFormulaField::GetValue; // hide it, don't use
214  virtual void SetValue(const double& rVal) override; // hide it
215 
216 public:
217  SwSetExpField(SwSetExpFieldType*, const OUString& rFormel, sal_uLong nFormat = 0);
218 
219  void SetFormatField(SwFormatField & rFormatField);
220  SwFormatField* GetFormatField() { return mpFormatField;}
221 
222  double GetValue(SwRootFrame const* pLayout) const;
223  void SetValue(const double& rVal, SwRootFrame const* pLayout);
224 
225  const OUString& GetExpStr(SwRootFrame const* pLayout) const;
226 
227  void ChgExpStr(const OUString& rExpand, SwRootFrame const* pLayout);
228 
229  inline void SetPromptText(const OUString& rStr);
230  inline const OUString& GetPromptText() const;
231 
232  inline void SetInputFlag(bool bInp);
233  inline bool GetInputFlag() const;
234 
235  virtual OUString GetFieldName() const override;
236 
237  virtual sal_uInt16 GetSubType() const override;
238  virtual void SetSubType(sal_uInt16 nType) override;
239 
240  inline bool IsSequenceField() const;
241 
243  void SetSeqNumber( sal_uInt16 n ) { mnSeqNo = n; }
244  sal_uInt16 GetSeqNumber() const { return mnSeqNo; }
245 
247  virtual OUString GetPar1() const override;
248 
250  virtual OUString GetPar2() const override;
251  virtual void SetPar2(const OUString& rStr) override;
252  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
253  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
254 };
255 
256 inline void SwSetExpField::SetPromptText(const OUString& rStr)
257  { maPText = rStr; }
258 
259 inline const OUString& SwSetExpField::GetPromptText() const
260  { return maPText; }
261 
262 inline void SwSetExpField::SetInputFlag(bool bInp)
263  { mbInput = bInp; }
264 
265 inline bool SwSetExpField::GetInputFlag() const
266  { return mbInput; }
267 
269  { return 0 != (nsSwGetSetExpType::GSE_SEQ & static_cast<SwSetExpFieldType*>(GetTyp())->GetType()); }
270 
271 class SAL_DLLPUBLIC_RTTI SwInputFieldType : public SwFieldType
272 {
273  SwDoc* const mpDoc;
274 public:
275  SwInputFieldType( SwDoc* pDoc );
276 
277  virtual std::unique_ptr<SwFieldType> Copy() const override;
278 
279  SwDoc* GetDoc() const { return mpDoc; }
280 };
281 
283 {
284  mutable OUString maContent;
285  OUString maPText;
286  OUString maHelp;
287  OUString maToolTip;
288  sal_uInt16 mnSubType;
289  bool const mbIsFormField;
290 
291  SwFormatField* mpFormatField; // attribute to which the <SwInputField> belongs to
292 
293  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
294  virtual std::unique_ptr<SwField> Copy() const override;
295 
296  // Accessing Input Field's content
297  const OUString& getContent() const { return maContent;}
298 
299 public:
301  SwInputField(
302  SwInputFieldType* pFieldType,
303  const OUString& rContent,
304  const OUString& rPrompt,
305  sal_uInt16 nSubType,
306  sal_uLong nFormat = 0,
307  bool bIsFormField = true );
308  virtual ~SwInputField() override;
309 
310  void SetFormatField( SwFormatField& rFormatField );
311  SwFormatField* GetFormatField() { return mpFormatField;}
312 
313  // Providing new Input Field's content:
314  // Fill Input Field's content depending on <nSupType>.
315  void applyFieldContent( const OUString& rNewFieldContent );
316 
317  bool isFormField() const;
318 
319  virtual OUString GetFieldName() const override;
320 
322  virtual OUString GetPar1() const override;
323  virtual void SetPar1(const OUString& rStr) override;
324 
326  virtual OUString GetPar2() const override;
327  virtual void SetPar2(const OUString& rStr) override;
328 
329  const OUString& GetHelp() const;
330  void SetHelp(const OUString & rStr);
331 
332  const OUString& GetToolTip() const;
333  void SetToolTip(const OUString & rStr);
334 
335  virtual sal_uInt16 GetSubType() const override;
336  virtual void SetSubType(sal_uInt16 nSub) override;
337  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
338  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
339 };
340 
341 // Sorted list of input fields and DropDown fields
343 {
344 public:
345  SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst = false );
347 
348  size_t Count() const;
349  SwField* GetField(size_t nId);
350 
351  void GotoFieldPos(size_t nId);
352  void PushCursor();
353  void PopCursor();
354 
358  bool BuildSortLst();
359 
360 private:
362  std::unique_ptr<SetGetExpFields> mpSrtLst;
363  std::set<const SwTextField*> maTmpLst;
364 };
365 
368 {
369 public:
370  SwTableFieldType(SwDoc* pDocPtr);
371  virtual std::unique_ptr<SwFieldType> Copy() const override;
372 };
373 
375 {
376  OUString m_sExpand;
377  sal_uInt16 m_nSubType;
378 
379  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
380  virtual std::unique_ptr<SwField> Copy() const override;
381 
383  virtual const SwNode* GetNodeOfFormula() const override;
384 
385  OUString GetCommand();
386 
387 public:
388  SwTableField( SwTableFieldType*, const OUString& rFormel,
389  sal_uInt16 nSubType, sal_uLong nFormat);
390 
391  virtual void SetValue( const double& rVal ) override;
392  virtual sal_uInt16 GetSubType() const override;
393  virtual void SetSubType(sal_uInt16 nType) override;
394 
395  void ChgExpStr(const OUString& rStr) { m_sExpand = rStr; }
396 
397  void CalcField( SwTableCalcPara& rCalcPara );
398 
399  virtual OUString GetFieldName() const override;
400 
402  virtual OUString GetPar2() const override;
403  virtual void SetPar2(const OUString& rStr) override;
404  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override;
405  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override;
406 };
407 
408 #endif // INCLUDED_SW_INC_EXPFLD_HXX
409 
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString msExpandRLHidden
hidden redlines
Definition: expfld.hxx:204
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
Base class of the Writer layout elements.
Definition: frame.hxx:295
SwInputFieldList(SwEditShell *pShell, bool bBuildTmpLst=false)
Definition: fldlst.cxx:37
void SetDelimiter(const OUString &s)
Definition: expfld.hxx:179
virtual sal_uInt16 GetSubType() const override
Definition: tblcalc.cxx:127
void CalcField(SwTableCalcPara &rCalcPara)
Definition: tblcalc.cxx:46
bool BuildSortLst()
Put all that are new into SortList for updating.
Definition: fldlst.cxx:128
bool mbInput
Definition: expfld.hxx:206
Marks a position in the document model.
Definition: pam.hxx:35
SwDoc * GetDoc() const
Definition: expfld.hxx:279
void SetType(sal_uInt16 nTyp)
Definition: expfld.hxx:188
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:419
SeqFieldLstElem(const OUString &rStr, sal_uInt16 nNo)
Definition: expfld.hxx:52
SwField * GetField(size_t nId)
Definition: fldlst.cxx:93
std::set< const SwTextField * > maTmpLst
Definition: expfld.hxx:363
void SetPromptText(const OUString &rStr)
Definition: expfld.hxx:256
sal_uInt16 mnSubType
Definition: expfld.hxx:288
virtual std::unique_ptr< SwFieldType > Copy() const =0
void SetOutlineLvl(sal_uInt8 n)
Definition: expfld.hxx:181
sal_uIntPtr sal_uLong
Base class of all fields.
Definition: fldbas.hxx:279
virtual void SetValue(const double &rVal) override
Definition: tblcalc.cxx:137
Definition: doc.hxx:185
bool IsDeleted() const
Definition: expfld.hxx:167
sal_Int16 nId
OUString sDlgEntry
Definition: expfld.hxx:49
SwTableFieldType(SwDoc *pDocPtr)
Definition: tblcalc.cxx:37
const OUString & GetPromptText() const
Definition: expfld.hxx:259
void SetDeleted(bool b)
Definition: expfld.hxx:168
virtual void SetSubType(sal_uInt16 nType) override
Definition: tblcalc.cxx:132
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: tblcalc.cxx:153
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
void PushCursor()
save cursor
Definition: fldlst.cxx:101
double m_fValueRLHidden
SwValueField; hidden redlines.
Definition: expfld.hxx:84
OUString maPText
Definition: expfld.hxx:205
virtual OUString GetPar1() const
Definition: fldbas.cxx:271
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: tblcalc.cxx:182
size_t Count()
Definition: expfld.hxx:64
OUString GetCommand()
Definition: tblcalc.cxx:95
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
OUString m_sExpand
Definition: expfld.hxx:376
OUString m_sExpandRLHidden
hidden redlines
Definition: expfld.hxx:86
virtual void SetPar2(const OUString &rStr)
Definition: fldbas.cxx:289
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:314
bool const mbIsFormField
Definition: expfld.hxx:289
SwDoc *const mpDoc
Definition: expfld.hxx:273
virtual void SetLanguage(LanguageType nLng) override
set language of the format
Definition: fldbas.cxx:633
virtual void SetPar2(const OUString &rStr) override
Definition: tblcalc.cxx:148
OUString m_sDelim
Definition: expfld.hxx:147
Implementation in tblcalc.cxx.
Definition: expfld.hxx:367
OUString ReplacePoint(const OUString &sTmpName, bool bWithCommandType=false)
Definition: expfld.cxx:107
sal_uInt16 m_nSubType
Definition: expfld.hxx:377
sal_uInt16 nSeqNo
Definition: expfld.hxx:50
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:196
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:301
sal_uInt16 GetSeqNumber() const
Definition: expfld.hxx:244
void PopCursor()
get cursor
Definition: fldlst.cxx:108
virtual OUString GetFieldName() const override
get name or content
Definition: tblcalc.cxx:77
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:286
virtual std::unique_ptr< SwField > Copy() const =0
void GotoFieldPos(size_t nId)
go to position of a field
Definition: fldlst.cxx:114
bool m_bIsInBodyText
Definition: expfld.hxx:87
void ChgBodyTextFlag(bool bIsInBody)
Set by UpdateExpFields where node position is known.
Definition: expfld.hxx:139
bool IsSequenceField() const
Definition: expfld.hxx:268
const OUString & getContent() const
Definition: expfld.hxx:297
OUString const m_sName
Definition: expfld.hxx:146
bool IsInBodyText() const
Called by formatting.
Definition: expfld.hxx:135
virtual OUString GetPar2() const override
The formula.
Definition: tblcalc.cxx:143
SwFormatField * mpFormatField
Definition: expfld.hxx:209
size_t Count() const
Definition: fldlst.cxx:87
sal_uInt16 mnSeqNo
Definition: expfld.hxx:207
virtual OUString GetPar2() const
Definition: fldbas.cxx:276
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
std::vector< SeqFieldLstElem > maData
Definition: expfld.hxx:59
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: calbck.hxx:183
sal_uInt8 GetOutlineLvl() const
Definition: expfld.hxx:180
SwFormatField * mpFormatField
Definition: expfld.hxx:291
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:292
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:150
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: tblcalc.cxx:41
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
bool GetInputFlag() const
Definition: expfld.hxx:265
void SetSeqNumber(sal_uInt16 n)
Logical number, sequence fields.
Definition: expfld.hxx:243
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:398
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
const SeqFieldLstElem & operator[](size_t nIndex) const
Definition: expfld.hxx:66
SwFormatField * GetFormatField()
Definition: expfld.hxx:220
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:197
bool m_bLateInitialization
Definition: expfld.hxx:90
const OUString & GetSetRefName() const
Overlay, because set-field takes care for its being updated by itself.
Definition: expfld.hxx:197
OUString maToolTip
Definition: expfld.hxx:287
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:145
sal_uInt16 m_nSubType
Definition: expfld.hxx:88
OUString maPText
Definition: expfld.hxx:285
unsigned char sal_uInt8
SwFormatField * GetFormatField()
Definition: expfld.hxx:311
sal_uInt16 mnSubType
Definition: expfld.hxx:208
void SetInputFlag(bool bInp)
Definition: expfld.hxx:262
SeqFieldLstElem & operator[](size_t nIndex)
Definition: expfld.hxx:65
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:153
SwTableField(SwTableFieldType *, const OUString &rFormel, sal_uInt16 nSubType, sal_uLong nFormat)
Definition: tblcalc.cxx:58
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:255
void InsertSort(std::vector< sal_uInt16 > &rArr, sal_uInt16 nIdx)
Definition: untbl.cxx:3022
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: tblcalc.cxx:111
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:195
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:680
OUString msExpand
Definition: expfld.hxx:203
sal_uInt16 m_nType
Definition: expfld.hxx:148
sal_uInt8 m_nLevel
Definition: expfld.hxx:149
OUString maHelp
Definition: expfld.hxx:286
virtual const SwNode * GetNodeOfFormula() const override
Search TextNode containing the field.
Definition: tblcalc.cxx:83
const OUString & GetDelimiter() const
Number sequence fields chapterwise if required.
Definition: expfld.hxx:178
sal_uInt16 GetType() const
Definition: expfld.hxx:194
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:297
SwEditShell * mpSh
Definition: expfld.hxx:361
double m_fValueRLHidden
SwValueField; hidden redlines.
Definition: expfld.hxx:202
OUString m_sExpand
Definition: expfld.hxx:85
const SwTextNode * GetBodyTextNode(const SwDoc &pDoc, SwPosition &rPos, const SwFrame &rFrame)
Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
Definition: expfld.cxx:166
virtual double GetValue() const
Definition: fldbas.cxx:675
OUString maContent
Definition: expfld.hxx:284
void ChgExpStr(const OUString &rStr)
Definition: expfld.hxx:395
std::unique_ptr< SetGetExpFields > mpSrtLst
Definition: expfld.hxx:362
void Clear()
Definition: expfld.hxx:67
void SetLateInitialization()
Definition: expfld.hxx:131
virtual std::unique_ptr< SwField > Copy() const override
Definition: tblcalc.cxx:66
Base class of the Writer document model elements.
Definition: node.hxx:79