Replace workaround of resize to invalidate with an explicit SfxHint
[LibreOffice.git] / sw / inc / expfld.hxx
blobf8694304f6c13b9943115e513de9d90c480b2b2e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
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>
29 #include <o3tl/sorted_vector.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/beans/PropertyValue.hpp>
33 class SfxPoolItem;
34 class SwTextNode;
35 class SwFrame;
36 class SwRootFrame;
37 struct SwPosition;
38 class SwTextField;
39 class SwDoc;
40 class SwFormatField;
41 class SetGetExpFields;
42 class SwEditShell;
44 /// Forward declaration: get "BodyTextNode" for exp.fld in Fly's headers/footers/footnotes.
45 const SwTextNode* GetBodyTextNode( const SwDoc& pDoc, SwPosition& rPos,
46 const SwFrame& rFrame );
48 OUString ReplacePoint(const OUString& sTmpName, bool bWithCommandType = false);
50 struct SeqFieldLstElem
52 OUString sDlgEntry;
53 sal_uInt16 nSeqNo;
55 SeqFieldLstElem( OUString aStr, sal_uInt16 nNo )
56 : sDlgEntry(std::move( aStr )), nSeqNo( nNo )
60 class SW_DLLPUBLIC SwSeqFieldList
62 std::vector<SeqFieldLstElem> maData;
63 public:
64 bool InsertSort(SeqFieldLstElem aNew);
65 bool SeekEntry(const SeqFieldLstElem& rNew, size_t* pPos) const;
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(); }
73 class SAL_DLLPUBLIC_RTTI SwGetExpFieldType final : public SwValueFieldType
75 public:
76 SwGetExpFieldType(SwDoc* pDoc);
77 virtual std::unique_ptr<SwFieldType> Copy() const override;
78 virtual void UpdateFields() override {};
80 /** Overlay, because get-field cannot be changed and therefore
81 does not need to be updated. Update at changing of set-values! */
82 private:
83 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
86 class SW_DLLPUBLIC SwGetExpField final : public SwFormulaField
88 double m_fValueRLHidden; ///< SwValueField; hidden redlines
89 OUString m_sExpand;
90 OUString m_sExpandRLHidden; ///< hidden redlines
91 bool m_bIsInBodyText;
92 sal_uInt16 m_nSubType;
94 bool m_bLateInitialization; // #i82544#
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
101 public:
102 SwGetExpField( SwGetExpFieldType*, const OUString& rFormel,
103 sal_uInt16 nSubType, sal_uLong nFormat);
105 double GetValue(SwRootFrame const* pLayout) const;
106 void SetValue(const double& rVal, SwRootFrame const* pLayout);
108 virtual void SetLanguage(LanguageType nLng) override;
110 void ChgExpStr(const OUString& rExpand, SwRootFrame const* pLayout);
112 /// Called by formatting.
113 inline bool IsInBodyText() const;
115 /// Set by UpdateExpFields where node position is known.
116 inline void ChgBodyTextFlag( bool bIsInBody );
118 /** For fields in header/footer/footnotes/flys:
119 Only called by formatting!! */
120 void ChangeExpansion( const SwFrame&, const SwTextField& );
122 virtual OUString GetFieldName() const override;
124 /// Change formula.
125 virtual OUString GetPar2() const override;
126 virtual void SetPar2(const OUString& rStr) override;
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;
133 static sal_Int32 GetReferenceTextPos( const SwFormatField& rFormat, SwDoc& rDoc, sal_Int32 nHint = 0);
134 // #i82544#
135 void SetLateInitialization() { m_bLateInitialization = true;}
138 /// Called by formatting.
139 inline bool SwGetExpField::IsInBodyText() const
140 { return m_bIsInBodyText; }
142 /// Set by UpdateExpFields where node position is known.
143 inline void SwGetExpField::ChgBodyTextFlag( bool bIsInBody )
144 { m_bIsInBodyText = bIsInBody; }
146 class SwSetExpField;
148 class SW_DLLPUBLIC SwSetExpFieldType final : public SwValueFieldType
150 OUString m_sName;
151 OUString m_sDelim;
152 sal_uInt16 m_nType;
153 sal_uInt8 m_nLevel;
154 bool m_bDeleted;
156 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
158 public:
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;
164 inline void SetType(sal_uInt16 nTyp);
165 inline sal_uInt16 GetType() const;
167 void SetSeqFormat(sal_uLong nFormat);
168 sal_uLong GetSeqFormat() const;
170 bool IsDeleted() const { return m_bDeleted; }
171 void SetDeleted( bool b ) { m_bDeleted = b; }
173 /// Overlay, because set-field takes care for its being updated by itself.
174 inline const OUString& GetSetRefName() const;
176 void SetSeqRefNo( SwSetExpField& rField );
178 size_t GetSeqFieldList(SwSeqFieldList& rList, SwRootFrame const* pLayout);
180 /// Number sequence fields chapterwise if required.
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; }
184 void SetOutlineLvl( sal_uInt8 n ) { m_nLevel = n; }
185 void SetChapter(SwSetExpField& rField, const SwNode& rNd, SwRootFrame const* pLayout);
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 {};
192 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
194 m_nType = nTyp;
195 EnableFormat( !(m_nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
198 inline sal_uInt16 SwSetExpFieldType::GetType() const
199 { return m_nType; }
201 inline const OUString& SwSetExpFieldType::GetSetRefName() const
202 { return m_sName; }
204 class SW_DLLPUBLIC SwSetExpField final : public SwFormulaField
206 double m_fValueRLHidden; ///< SwValueField; hidden redlines
207 OUString msExpand;
208 OUString msExpandRLHidden; ///< hidden redlines
209 OUString maPText;
210 bool mbInput;
211 sal_uInt16 mnSeqNo;
212 sal_uInt16 mnSubType;
213 SwFormatField * mpFormatField; /// pool item to which the SwSetExpField belongs
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
220 public:
221 SwSetExpField(SwSetExpFieldType*, const OUString& rFormel, sal_uLong nFormat = 0);
223 void SetFormatField(SwFormatField & rFormatField);
224 SwFormatField* GetFormatField() { return mpFormatField;}
226 double GetValue(SwRootFrame const* pLayout) const;
227 void SetValue(const double& rVal, SwRootFrame const* pLayout);
229 const OUString& GetExpStr(SwRootFrame const* pLayout) const;
231 void ChgExpStr(const OUString& rExpand, SwRootFrame const* pLayout);
233 inline void SetPromptText(const OUString& rStr);
234 inline const OUString& GetPromptText() const;
236 inline void SetInputFlag(bool bInp);
237 inline bool GetInputFlag() const;
239 virtual OUString GetFieldName() const override;
241 virtual sal_uInt16 GetSubType() const override;
242 virtual void SetSubType(sal_uInt16 nType) override;
244 inline bool IsSequenceField() const;
246 /// Logical number, sequence fields.
247 void SetSeqNumber( sal_uInt16 n ) { mnSeqNo = n; }
248 sal_uInt16 GetSeqNumber() const { return mnSeqNo; }
250 /// Query name only.
251 virtual OUString GetPar1() const override;
253 /// Query formula.
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;
260 inline void SwSetExpField::SetPromptText(const OUString& rStr)
261 { maPText = rStr; }
263 inline const OUString& SwSetExpField::GetPromptText() const
264 { return maPText; }
266 inline void SwSetExpField::SetInputFlag(bool bInp)
267 { mbInput = bInp; }
269 inline bool SwSetExpField::GetInputFlag() const
270 { return mbInput; }
272 inline bool SwSetExpField::IsSequenceField() const
273 { return 0 != (nsSwGetSetExpType::GSE_SEQ & static_cast<SwSetExpFieldType*>(GetTyp())->GetType()); }
275 class SAL_DLLPUBLIC_RTTI SwInputFieldType final : public SwFieldType
277 SwDoc* mpDoc;
278 public:
279 SwInputFieldType( SwDoc* pDoc );
281 virtual std::unique_ptr<SwFieldType> Copy() const override;
283 SwDoc* GetDoc() const { return mpDoc; }
286 class SW_DLLPUBLIC SwInputField final : public SwField
288 mutable OUString maContent;
289 OUString maPText;
290 OUString maHelp;
291 OUString maToolTip;
292 sal_uInt16 mnSubType;
293 bool mbIsFormField;
294 css::uno::Sequence<css::beans::PropertyValue> maGrabBag;
296 SwFormatField* mpFormatField; // attribute to which the <SwInputField> belongs to
298 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
299 virtual std::unique_ptr<SwField> Copy() const override;
301 // Accessing Input Field's content
302 const OUString& getContent() const { return maContent;}
304 public:
305 /// Direct input via dialog; delete old value.
306 SwInputField(
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;
315 void SetFormatField( SwFormatField& rFormatField );
316 SwFormatField* GetFormatField() { return mpFormatField;}
318 // Providing new Input Field's content:
319 // Fill Input Field's content depending on <nSupType>.
320 void applyFieldContent( const OUString& rNewFieldContent );
322 bool isFormField() const;
323 const css::uno::Sequence<css::beans::PropertyValue> & getGrabBagParams() const { return maGrabBag; }
325 virtual OUString GetFieldName() const override;
327 /// Content
328 virtual OUString GetPar1() const override;
329 virtual void SetPar1(const OUString& rStr) override;
331 /// aPromptText
332 virtual OUString GetPar2() const override;
333 virtual void SetPar2(const OUString& rStr) override;
335 const OUString& GetHelp() const;
336 void SetHelp(const OUString & rStr);
338 const OUString& GetToolTip() const;
339 void SetToolTip(const OUString & rStr);
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;
347 // Sorted list of input fields and DropDown fields
348 class SwInputFieldList
350 public:
351 SwInputFieldList( SwEditShell* pShell, bool bBuildTmpLst = false );
352 ~SwInputFieldList();
354 size_t Count() const;
355 SwField* GetField(size_t nId);
357 void GotoFieldPos(size_t nId);
358 void PushCursor();
359 void PopCursor();
361 /** Put all that are new into SortList for updating. @return true if not empty.
362 (For Glossary: only update its input-fields).
363 Compare TmpLst with current fields. */
364 bool BuildSortLst();
366 private:
367 SwEditShell* mpSh;
368 std::unique_ptr<SetGetExpFields> mpSrtLst;
369 o3tl::sorted_vector<const SwTextField*> maTmpLst;
372 /// Implementation in tblcalc.cxx.
373 class SwTableFieldType final : public SwValueFieldType
375 public:
376 SwTableFieldType(SwDoc* pDocPtr);
377 virtual std::unique_ptr<SwFieldType> Copy() const override;
378 virtual void UpdateFields() override {};
381 class SwTableField final : public SwValueField, public SwTableFormula
383 OUString m_sExpand;
384 sal_uInt16 m_nSubType;
386 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
387 virtual std::unique_ptr<SwField> Copy() const override;
389 /// Search TextNode containing the field.
390 virtual const SwNode* GetNodeOfFormula() const override;
392 OUString GetCommand();
394 public:
395 SwTableField( SwTableFieldType*, const OUString& rFormel,
396 sal_uInt16 nSubType, sal_uLong nFormat);
398 virtual void SetValue( const double& rVal ) override;
399 virtual sal_uInt16 GetSubType() const override;
400 virtual void SetSubType(sal_uInt16 nType) override;
402 void ChgExpStr(const OUString& rStr) { m_sExpand = rStr; }
404 void CalcField( SwTableCalcPara& rCalcPara );
406 virtual OUString GetFieldName() const override;
408 /// The formula.
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;
415 #endif // INCLUDED_SW_INC_EXPFLD_HXX
417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */