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