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 <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/beans/PropertyValue.hpp>
40 class SetGetExpFields
;
43 /// Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
44 const SwTextNode
* GetBodyTextNode( const SwDoc
& pDoc
, SwPosition
& rPos
,
45 const SwFrame
& rFrame
);
47 OUString
ReplacePoint(const OUString
& sTmpName
, bool bWithCommandType
= false);
49 struct SeqFieldLstElem
54 SeqFieldLstElem( const OUString
& rStr
, sal_uInt16 nNo
)
55 : sDlgEntry( rStr
), nSeqNo( nNo
)
59 class SW_DLLPUBLIC SwSeqFieldList
61 std::vector
<SeqFieldLstElem
> maData
;
63 bool InsertSort(SeqFieldLstElem aNew
);
64 bool SeekEntry(const SeqFieldLstElem
& rNew
, size_t* pPos
) const;
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(); }
72 class SAL_DLLPUBLIC_RTTI SwGetExpFieldType final
: public SwValueFieldType
75 SwGetExpFieldType(SwDoc
* pDoc
);
76 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
78 /** Overlay, because get-field cannot be changed and therefore
79 does not need to be updated. Update at changing of set-values! */
81 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
84 class SW_DLLPUBLIC SwGetExpField final
: public SwFormulaField
86 double m_fValueRLHidden
; ///< SwValueField; hidden redlines
88 OUString m_sExpandRLHidden
; ///< hidden redlines
90 sal_uInt16 m_nSubType
;
92 bool m_bLateInitialization
; // #i82544#
94 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
95 virtual std::unique_ptr
<SwField
> Copy() const override
;
96 using SwFormulaField::GetValue
; // hide it, don't use
97 virtual void SetValue(const double& rVal
) override
; // hide it
100 SwGetExpField( SwGetExpFieldType
*, const OUString
& rFormel
,
101 sal_uInt16 nSubType
, sal_uLong nFormat
);
103 double GetValue(SwRootFrame
const* pLayout
) const;
104 void SetValue(const double& rVal
, SwRootFrame
const* pLayout
);
106 virtual void SetLanguage(LanguageType nLng
) override
;
108 void ChgExpStr(const OUString
& rExpand
, SwRootFrame
const* pLayout
);
110 /// Called by formatting.
111 inline bool IsInBodyText() const;
113 /// Set by UpdateExpFields where node position is known.
114 inline void ChgBodyTextFlag( bool bIsInBody
);
116 /** For fields in header/footer/footnotes/flys:
117 Only called by formatting!! */
118 void ChangeExpansion( const SwFrame
&, const SwTextField
& );
120 virtual OUString
GetFieldName() const override
;
123 virtual OUString
GetPar2() const override
;
124 virtual void SetPar2(const OUString
& rStr
) override
;
126 virtual sal_uInt16
GetSubType() const override
;
127 virtual void SetSubType(sal_uInt16 nType
) override
;
128 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
129 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
131 static sal_Int32
GetReferenceTextPos( const SwFormatField
& rFormat
, SwDoc
& rDoc
, sal_Int32 nHint
= 0);
133 void SetLateInitialization() { m_bLateInitialization
= true;}
136 /// Called by formatting.
137 inline bool SwGetExpField::IsInBodyText() const
138 { return m_bIsInBodyText
; }
140 /// Set by UpdateExpFields where node position is known.
141 inline void SwGetExpField::ChgBodyTextFlag( bool bIsInBody
)
142 { m_bIsInBodyText
= bIsInBody
; }
146 class SW_DLLPUBLIC SwSetExpFieldType final
: public SwValueFieldType
148 OUString
const m_sName
;
154 virtual void Modify( const SfxPoolItem
* pOld
, const SfxPoolItem
*pNew
) override
;
157 SwSetExpFieldType( SwDoc
* pDoc
, const OUString
& rName
,
158 sal_uInt16 nType
= nsSwGetSetExpType::GSE_EXPR
);
159 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
160 virtual OUString
GetName() const override
;
162 inline void SetType(sal_uInt16 nTyp
);
163 inline sal_uInt16
GetType() const;
165 void SetSeqFormat(sal_uLong nFormat
);
166 sal_uLong
GetSeqFormat() const;
168 bool IsDeleted() const { return m_bDeleted
; }
169 void SetDeleted( bool b
) { m_bDeleted
= b
; }
171 /// Overlay, because set-field takes care for its being updated by itself.
172 inline const OUString
& GetSetRefName() const;
174 void SetSeqRefNo( SwSetExpField
& rField
);
176 size_t GetSeqFieldList(SwSeqFieldList
& rList
, SwRootFrame
const* pLayout
);
178 /// Number sequence fields chapterwise if required.
179 const OUString
& GetDelimiter() const { return m_sDelim
; }
180 void SetDelimiter( const OUString
& s
) { m_sDelim
= s
; }
181 sal_uInt8
GetOutlineLvl() const { return m_nLevel
; }
182 void SetOutlineLvl( sal_uInt8 n
) { m_nLevel
= n
; }
183 void SetChapter(SwSetExpField
& rField
, const SwNode
& rNd
, SwRootFrame
const* pLayout
);
185 virtual void QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
186 virtual void PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
189 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp
)
192 EnableFormat( !(m_nType
& (nsSwGetSetExpType::GSE_SEQ
|nsSwGetSetExpType::GSE_STRING
)));
195 inline sal_uInt16
SwSetExpFieldType::GetType() const
198 inline const OUString
& SwSetExpFieldType::GetSetRefName() const
201 class SW_DLLPUBLIC SwSetExpField
: public SwFormulaField
203 double m_fValueRLHidden
; ///< SwValueField; hidden redlines
205 OUString msExpandRLHidden
; ///< hidden redlines
209 sal_uInt16 mnSubType
;
210 SwFormatField
* mpFormatField
; /// pool item to which the SwSetExpField belongs
212 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
213 virtual std::unique_ptr
<SwField
> Copy() const override
;
214 using SwFormulaField::GetValue
; // hide it, don't use
215 virtual void SetValue(const double& rVal
) override
; // hide it
218 SwSetExpField(SwSetExpFieldType
*, const OUString
& rFormel
, sal_uLong nFormat
= 0);
220 void SetFormatField(SwFormatField
& rFormatField
);
221 SwFormatField
* GetFormatField() { return mpFormatField
;}
223 double GetValue(SwRootFrame
const* pLayout
) const;
224 void SetValue(const double& rVal
, SwRootFrame
const* pLayout
);
226 const OUString
& GetExpStr(SwRootFrame
const* pLayout
) const;
228 void ChgExpStr(const OUString
& rExpand
, SwRootFrame
const* pLayout
);
230 inline void SetPromptText(const OUString
& rStr
);
231 inline const OUString
& GetPromptText() const;
233 inline void SetInputFlag(bool bInp
);
234 inline bool GetInputFlag() const;
236 virtual OUString
GetFieldName() const override
;
238 virtual sal_uInt16
GetSubType() const override
;
239 virtual void SetSubType(sal_uInt16 nType
) override
;
241 inline bool IsSequenceField() const;
243 /// Logical number, sequence fields.
244 void SetSeqNumber( sal_uInt16 n
) { mnSeqNo
= n
; }
245 sal_uInt16
GetSeqNumber() const { return mnSeqNo
; }
248 virtual OUString
GetPar1() const override
;
251 virtual OUString
GetPar2() const override
;
252 virtual void SetPar2(const OUString
& rStr
) override
;
253 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
254 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
257 inline void SwSetExpField::SetPromptText(const OUString
& rStr
)
260 inline const OUString
& SwSetExpField::GetPromptText() const
263 inline void SwSetExpField::SetInputFlag(bool bInp
)
266 inline bool SwSetExpField::GetInputFlag() const
269 inline bool SwSetExpField::IsSequenceField() const
270 { return 0 != (nsSwGetSetExpType::GSE_SEQ
& static_cast<SwSetExpFieldType
*>(GetTyp())->GetType()); }
272 class SAL_DLLPUBLIC_RTTI SwInputFieldType final
: public SwFieldType
276 SwInputFieldType( SwDoc
* pDoc
);
278 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
280 SwDoc
* GetDoc() const { return mpDoc
; }
283 class SW_DLLPUBLIC SwInputField final
: public SwField
285 mutable OUString maContent
;
289 sal_uInt16 mnSubType
;
291 css::uno::Sequence
<css::beans::PropertyValue
> maGrabBag
;
293 SwFormatField
* mpFormatField
; // attribute to which the <SwInputField> belongs to
295 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
296 virtual std::unique_ptr
<SwField
> Copy() const override
;
298 // Accessing Input Field's content
299 const OUString
& getContent() const { return maContent
;}
302 /// Direct input via dialog; delete old value.
304 SwInputFieldType
* pFieldType
,
305 const OUString
& rContent
,
306 const OUString
& rPrompt
,
308 sal_uLong nFormat
= 0,
309 bool bIsFormField
= true );
310 virtual ~SwInputField() override
;
312 void SetFormatField( SwFormatField
& rFormatField
);
313 SwFormatField
* GetFormatField() { return mpFormatField
;}
315 // Providing new Input Field's content:
316 // Fill Input Field's content depending on <nSupType>.
317 void applyFieldContent( const OUString
& rNewFieldContent
);
319 bool isFormField() const;
320 css::uno::Sequence
<css::beans::PropertyValue
> getGrabBagParams() const { return maGrabBag
; }
322 virtual OUString
GetFieldName() const override
;
325 virtual OUString
GetPar1() const override
;
326 virtual void SetPar1(const OUString
& rStr
) override
;
329 virtual OUString
GetPar2() const override
;
330 virtual void SetPar2(const OUString
& rStr
) override
;
332 const OUString
& GetHelp() const;
333 void SetHelp(const OUString
& rStr
);
335 const OUString
& GetToolTip() const;
336 void SetToolTip(const OUString
& rStr
);
338 virtual sal_uInt16
GetSubType() const override
;
339 virtual void SetSubType(sal_uInt16 nSub
) override
;
340 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
341 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
344 // Sorted list of input fields and DropDown fields
345 class SwInputFieldList
348 SwInputFieldList( SwEditShell
* pShell
, bool bBuildTmpLst
= false );
351 size_t Count() const;
352 SwField
* GetField(size_t nId
);
354 void GotoFieldPos(size_t nId
);
358 /** Put all that are new into SortList for updating. @return true if not empty.
359 (For Glossary: only update its input-fields).
360 Compare TmpLst with current fields. */
365 std::unique_ptr
<SetGetExpFields
> mpSrtLst
;
366 std::set
<const SwTextField
*> maTmpLst
;
369 /// Implementation in tblcalc.cxx.
370 class SwTableFieldType final
: public SwValueFieldType
373 SwTableFieldType(SwDoc
* pDocPtr
);
374 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
377 class SwTableField final
: public SwValueField
, public SwTableFormula
380 sal_uInt16 m_nSubType
;
382 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
383 virtual std::unique_ptr
<SwField
> Copy() const override
;
385 /// Search TextNode containing the field.
386 virtual const SwNode
* GetNodeOfFormula() const override
;
388 OUString
GetCommand();
391 SwTableField( SwTableFieldType
*, const OUString
& rFormel
,
392 sal_uInt16 nSubType
, sal_uLong nFormat
);
394 virtual void SetValue( const double& rVal
) override
;
395 virtual sal_uInt16
GetSubType() const override
;
396 virtual void SetSubType(sal_uInt16 nType
) override
;
398 void ChgExpStr(const OUString
& rStr
) { m_sExpand
= rStr
; }
400 void CalcField( SwTableCalcPara
& rCalcPara
);
402 virtual OUString
GetFieldName() const override
;
405 virtual OUString
GetPar2() const override
;
406 virtual void SetPar2(const OUString
& rStr
) override
;
407 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
408 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
411 #endif // INCLUDED_SW_INC_EXPFLD_HXX
413 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */