1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <cellfml.hxx>
36 class SetGetExpFields
;
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
50 SeqFieldLstElem( const OUString
& rStr
, sal_uInt16 nNo
)
51 : sDlgEntry( rStr
), nSeqNo( nNo
)
55 class SW_DLLPUBLIC SwSeqFieldList
57 std::vector
<SeqFieldLstElem
*> maData
;
61 for( std::vector
<SeqFieldLstElem
*>::const_iterator it
= maData
.begin(); it
!= maData
.end(); ++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
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! */
83 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
86 class SW_DLLPUBLIC SwGetExpField
: public SwFormulaField
92 bool bLateInitialization
; // #i82544#
94 virtual OUString
Expand() const override
;
95 virtual SwField
* Copy() const override
;
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
;
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);
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
; }
145 class SW_DLLPUBLIC SwSetExpFieldType
: public SwValueFieldType
148 const SwNode
* pOutlChgNd
;
155 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
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
)
198 EnableFormat( !(nType
& (nsSwGetSetExpType::GSE_SEQ
|nsSwGetSetExpType::GSE_STRING
)));
201 inline sal_uInt16
SwSetExpFieldType::GetType() const
204 inline const OUString
& SwSetExpFieldType::GetSetRefName() const
207 class SW_DLLPUBLIC SwSetExpField
: public SwFormulaField
214 SwFormatField
* mpFormatField
; /// pool item to which the SwSetExpField belongs
216 virtual OUString
Expand() const override
;
217 virtual SwField
* Copy() const override
;
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
; }
249 virtual OUString
GetPar1() const override
;
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
261 inline void SwSetExpField::ChgExpStr( const OUString
& rExpand
)
262 { sExpand
= rExpand
; }
264 inline void SwSetExpField::SetPromptText(const OUString
& rStr
)
267 inline const OUString
& SwSetExpField::GetPromptText() const
270 inline void SwSetExpField::SetInputFlag(bool bInp
)
273 inline bool SwSetExpField::GetInputFlag() const
276 inline bool SwSetExpField::IsSequenceField() const
277 { return 0 != (nsSwGetSetExpType::GSE_SEQ
& static_cast<SwSetExpFieldType
*>(GetTyp())->GetType()); }
279 class SwInputFieldType
: public SwFieldType
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
;
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
;}
308 /// Direct input via dialog; delete old value.
310 SwInputFieldType
* pFieldType
,
311 const OUString
& rContent
,
312 const OUString
& rPrompt
,
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
;
330 virtual OUString
GetPar1() const override
;
331 virtual void SetPar1(const OUString
& rStr
) override
;
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
353 SwInputFieldList( SwEditShell
* pShell
, bool bBuildTmpLst
= false );
356 size_t Count() const;
357 SwField
* GetField(size_t nId
);
359 void GotoFieldPos(size_t nId
);
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. */
370 std::unique_ptr
<SetGetExpFields
> pSrtLst
;
371 std::set
<const SwTextField
*> aTmpLst
;
374 /// Implementation in tblcalc.cxx.
375 class SwTableFieldType
: public SwValueFieldType
378 SwTableFieldType(SwDoc
* pDocPtr
);
379 virtual SwFieldType
* Copy() const override
;
382 class SwTableField
: public SwValueField
, public SwTableFormula
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();
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
;
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: */