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