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"
28 #include <tools/solar.h>
29 #include <o3tl/sorted_vector.hxx>
39 class SetGetExpFields
;
42 /// Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
43 const SwTextNode
* GetBodyTextNode( const SwDoc
& pDoc
, SwPosition
& rPos
,
44 const SwFrame
& rFrame
);
46 OUString
ReplacePoint(const OUString
& sTmpName
, bool bWithCommandType
= false);
48 struct SeqFieldLstElem
53 SeqFieldLstElem( const OUString
& rStr
, sal_uInt16 nNo
)
54 : sDlgEntry( rStr
), nSeqNo( nNo
)
58 class SW_DLLPUBLIC SwSeqFieldList
60 std::vector
<SeqFieldLstElem
> maData
;
62 bool InsertSort(SeqFieldLstElem aNew
);
63 bool SeekEntry(const SeqFieldLstElem
& rNew
, size_t* pPos
) const;
65 size_t Count() { return maData
.size(); }
66 SeqFieldLstElem
& operator[](size_t nIndex
) { return maData
[nIndex
]; }
67 const SeqFieldLstElem
& operator[](size_t nIndex
) const { return maData
[nIndex
]; }
68 void Clear() { maData
.clear(); }
71 class SAL_DLLPUBLIC_RTTI SwGetExpFieldType final
: public SwValueFieldType
74 SwGetExpFieldType(SwDoc
* pDoc
);
75 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
77 /** Overlay, because get-field cannot be changed and therefore
78 does not need to be updated. Update at changing of set-values! */
80 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
83 class SW_DLLPUBLIC SwGetExpField final
: public SwFormulaField
85 double m_fValueRLHidden
; ///< SwValueField; hidden redlines
87 OUString m_sExpandRLHidden
; ///< hidden redlines
89 sal_uInt16 m_nSubType
;
91 bool m_bLateInitialization
; // #i82544#
93 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
94 virtual std::unique_ptr
<SwField
> Copy() const override
;
95 using SwFormulaField::GetValue
; // hide it, don't use
96 virtual void SetValue(const double& rVal
) override
; // hide it
99 SwGetExpField( SwGetExpFieldType
*, const OUString
& rFormel
,
100 sal_uInt16 nSubType
, sal_uLong nFormat
);
102 double GetValue(SwRootFrame
const* pLayout
) const;
103 void SetValue(const double& rVal
, SwRootFrame
const* pLayout
);
105 virtual void SetLanguage(LanguageType nLng
) override
;
107 void ChgExpStr(const OUString
& rExpand
, SwRootFrame
const* pLayout
);
109 /// Called by formatting.
110 inline bool IsInBodyText() const;
112 /// Set by UpdateExpFields where node position is known.
113 inline void ChgBodyTextFlag( bool bIsInBody
);
115 /** For fields in header/footer/footnotes/flys:
116 Only called by formatting!! */
117 void ChangeExpansion( const SwFrame
&, const SwTextField
& );
119 virtual OUString
GetFieldName() const override
;
122 virtual OUString
GetPar2() const override
;
123 virtual void SetPar2(const OUString
& rStr
) override
;
125 virtual sal_uInt16
GetSubType() const override
;
126 virtual void SetSubType(sal_uInt16 nType
) override
;
127 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
128 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
130 static sal_Int32
GetReferenceTextPos( const SwFormatField
& rFormat
, SwDoc
& rDoc
, sal_Int32 nHint
= 0);
132 void SetLateInitialization() { m_bLateInitialization
= true;}
135 /// Called by formatting.
136 inline bool SwGetExpField::IsInBodyText() const
137 { return m_bIsInBodyText
; }
139 /// Set by UpdateExpFields where node position is known.
140 inline void SwGetExpField::ChgBodyTextFlag( bool bIsInBody
)
141 { m_bIsInBodyText
= bIsInBody
; }
145 class SW_DLLPUBLIC SwSetExpFieldType final
: public SwValueFieldType
153 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
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
;
161 inline void SetType(sal_uInt16 nTyp
);
162 inline sal_uInt16
GetType() const;
164 void SetSeqFormat(sal_uLong nFormat
);
165 sal_uLong
GetSeqFormat() const;
167 bool IsDeleted() const { return m_bDeleted
; }
168 void SetDeleted( bool b
) { m_bDeleted
= b
; }
170 /// Overlay, because set-field takes care for its being updated by itself.
171 inline const OUString
& GetSetRefName() const;
173 void SetSeqRefNo( SwSetExpField
& rField
);
175 size_t GetSeqFieldList(SwSeqFieldList
& rList
, SwRootFrame
const* pLayout
);
177 /// Number sequence fields chapterwise if required.
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
);
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
;
188 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp
)
191 EnableFormat( !(m_nType
& (nsSwGetSetExpType::GSE_SEQ
|nsSwGetSetExpType::GSE_STRING
)));
194 inline sal_uInt16
SwSetExpFieldType::GetType() const
197 inline const OUString
& SwSetExpFieldType::GetSetRefName() const
200 class SW_DLLPUBLIC SwSetExpField
: public SwFormulaField
202 double m_fValueRLHidden
; ///< SwValueField; hidden redlines
204 OUString msExpandRLHidden
; ///< hidden redlines
208 sal_uInt16 mnSubType
;
209 SwFormatField
* mpFormatField
; /// pool item to which the SwSetExpField belongs
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
217 SwSetExpField(SwSetExpFieldType
*, const OUString
& rFormel
, sal_uLong nFormat
= 0);
219 void SetFormatField(SwFormatField
& rFormatField
);
220 SwFormatField
* GetFormatField() { return mpFormatField
;}
222 double GetValue(SwRootFrame
const* pLayout
) const;
223 void SetValue(const double& rVal
, SwRootFrame
const* pLayout
);
225 const OUString
& GetExpStr(SwRootFrame
const* pLayout
) const;
227 void ChgExpStr(const OUString
& rExpand
, SwRootFrame
const* pLayout
);
229 inline void SetPromptText(const OUString
& rStr
);
230 inline const OUString
& GetPromptText() const;
232 inline void SetInputFlag(bool bInp
);
233 inline bool GetInputFlag() const;
235 virtual OUString
GetFieldName() const override
;
237 virtual sal_uInt16
GetSubType() const override
;
238 virtual void SetSubType(sal_uInt16 nType
) override
;
240 inline bool IsSequenceField() const;
242 /// Logical number, sequence fields.
243 void SetSeqNumber( sal_uInt16 n
) { mnSeqNo
= n
; }
244 sal_uInt16
GetSeqNumber() const { return mnSeqNo
; }
247 virtual OUString
GetPar1() const override
;
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
;
256 inline void SwSetExpField::SetPromptText(const OUString
& rStr
)
259 inline const OUString
& SwSetExpField::GetPromptText() const
262 inline void SwSetExpField::SetInputFlag(bool bInp
)
265 inline bool SwSetExpField::GetInputFlag() const
268 inline bool SwSetExpField::IsSequenceField() const
269 { return 0 != (nsSwGetSetExpType::GSE_SEQ
& static_cast<SwSetExpFieldType
*>(GetTyp())->GetType()); }
271 class SAL_DLLPUBLIC_RTTI SwInputFieldType final
: public SwFieldType
275 SwInputFieldType( SwDoc
* pDoc
);
277 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
279 SwDoc
* GetDoc() const { return mpDoc
; }
282 class SW_DLLPUBLIC SwInputField final
: public SwField
284 mutable OUString maContent
;
288 sal_uInt16 mnSubType
;
291 SwFormatField
* mpFormatField
; // attribute to which the <SwInputField> belongs to
293 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
294 virtual std::unique_ptr
<SwField
> Copy() const override
;
296 // Accessing Input Field's content
297 const OUString
& getContent() const { return maContent
;}
300 /// Direct input via dialog; delete old value.
302 SwInputFieldType
* pFieldType
,
303 const OUString
& rContent
,
304 const OUString
& rPrompt
,
306 sal_uLong nFormat
= 0,
307 bool bIsFormField
= true );
308 virtual ~SwInputField() override
;
310 void SetFormatField( SwFormatField
& rFormatField
);
311 SwFormatField
* GetFormatField() { return mpFormatField
;}
313 // Providing new Input Field's content:
314 // Fill Input Field's content depending on <nSupType>.
315 void applyFieldContent( const OUString
& rNewFieldContent
);
317 bool isFormField() const;
319 virtual OUString
GetFieldName() const override
;
322 virtual OUString
GetPar1() const override
;
323 virtual void SetPar1(const OUString
& rStr
) override
;
326 virtual OUString
GetPar2() const override
;
327 virtual void SetPar2(const OUString
& rStr
) override
;
329 const OUString
& GetHelp() const;
330 void SetHelp(const OUString
& rStr
);
332 const OUString
& GetToolTip() const;
333 void SetToolTip(const OUString
& rStr
);
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
;
341 // Sorted list of input fields and DropDown fields
342 class SwInputFieldList
345 SwInputFieldList( SwEditShell
* pShell
, bool bBuildTmpLst
= false );
348 size_t Count() const;
349 SwField
* GetField(size_t nId
);
351 void GotoFieldPos(size_t nId
);
355 /** Put all that are new into SortList for updating. @return true if not empty.
356 (For Glossary: only update its input-fields).
357 Compare TmpLst with current fields. */
362 std::unique_ptr
<SetGetExpFields
> mpSrtLst
;
363 o3tl::sorted_vector
<const SwTextField
*> maTmpLst
;
366 /// Implementation in tblcalc.cxx.
367 class SwTableFieldType final
: public SwValueFieldType
370 SwTableFieldType(SwDoc
* pDocPtr
);
371 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
374 class SwTableField final
: public SwValueField
, public SwTableFormula
377 sal_uInt16 m_nSubType
;
379 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
380 virtual std::unique_ptr
<SwField
> Copy() const override
;
382 /// Search TextNode containing the field.
383 virtual const SwNode
* GetNodeOfFormula() const override
;
385 OUString
GetCommand();
388 SwTableField( SwTableFieldType
*, const OUString
& rFormel
,
389 sal_uInt16 nSubType
, sal_uLong nFormat
);
391 virtual void SetValue( const double& rVal
) override
;
392 virtual sal_uInt16
GetSubType() const override
;
393 virtual void SetSubType(sal_uInt16 nType
) override
;
395 void ChgExpStr(const OUString
& rStr
) { m_sExpand
= rStr
; }
397 void CalcField( SwTableCalcPara
& rCalcPara
);
399 virtual OUString
GetFieldName() const override
;
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
;
408 #endif // INCLUDED_SW_INC_EXPFLD_HXX
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */