update credits
[LibreOffice.git] / sw / inc / expfld.hxx
blob8ac6e48fa17c0e9d3786f01b76ced90cecb9287b
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 SW_EXPFLD_HXX
20 #define SW_EXPFLD_HXX
22 #include "swdllapi.h"
23 #include <fldbas.hxx>
24 #include <cellfml.hxx>
25 #include <set>
26 #include <vector>
28 class SfxPoolItem;
29 class SwTxtNode;
30 class SwFrm;
31 struct SwPosition;
32 class SwTxtFld;
33 class SwDoc;
34 class SwFmtFld;
35 class _SetGetExpFlds;
36 class SwEditShell;
38 /// Forward declaration: get "BodyTxtNode" for exp.fld in Fly's headers/footers/footnotes.
39 const SwTxtNode* GetBodyTxtNode( const SwDoc& pDoc, SwPosition& rPos,
40 const SwFrm& rFrm );
42 void ReplacePoint(String& sTmpName, bool bWithCommandType = false);
44 struct _SeqFldLstElem
46 String sDlgEntry;
47 sal_uInt16 nSeqNo;
49 _SeqFldLstElem( const String& rStr, sal_uInt16 nNo )
50 : sDlgEntry( rStr ), nSeqNo( nNo )
54 class SW_DLLPUBLIC SwSeqFldList
56 std::vector<_SeqFldLstElem*> maData;
57 public:
58 ~SwSeqFldList()
60 for( std::vector<_SeqFldLstElem*>::const_iterator it = maData.begin(); it != maData.end(); ++it )
61 delete *it;
64 bool InsertSort(_SeqFldLstElem* pNew);
65 bool SeekEntry(const _SeqFldLstElem& rNew, sal_uInt16* pPos) const;
67 sal_uInt16 Count() { return maData.size(); }
68 _SeqFldLstElem* operator[](sal_uInt16 nIndex) { return maData[nIndex]; }
69 const _SeqFldLstElem* operator[](sal_uInt16 nIndex) const { return maData[nIndex]; }
70 void Clear() { maData.clear(); }
73 class SwGetExpFieldType : public SwValueFieldType
75 public:
76 SwGetExpFieldType(SwDoc* pDoc);
77 virtual SwFieldType* Copy() const;
79 /** Overlay, because get-field cannot be changed and therefore
80 does not need to be updated. Update at changing of set-values! */
81 protected:
82 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
85 class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
87 String sExpand;
88 bool bIsInBodyTxt;
89 sal_uInt16 nSubType;
91 bool bLateInitialization; // #i82544#
93 virtual String Expand() const;
94 virtual SwField* Copy() const;
96 public:
97 SwGetExpField( SwGetExpFieldType*, const String& rFormel,
98 sal_uInt16 nSubType = nsSwGetSetExpType::GSE_EXPR, sal_uLong nFmt = 0);
100 virtual void SetValue( const double& rVal );
101 virtual void SetLanguage(sal_uInt16 nLng);
103 inline const String& GetExpStr() const;
104 inline void ChgExpStr(const String& rExpand);
106 /// Called by formating.
107 inline bool IsInBodyTxt() const;
109 /// Set by UpdateExpFlds where node position is known.
110 inline void ChgBodyTxtFlag( bool bIsInBody );
112 /** For fields in header/footer/footnotes/flys:
113 Only called by formating!! */
114 void ChangeExpansion( const SwFrm&, const SwTxtFld& );
116 virtual String GetFieldName() const;
118 /// Change formula.
119 virtual OUString GetPar2() const;
120 virtual void SetPar2(const OUString& rStr);
122 virtual sal_uInt16 GetSubType() const;
123 virtual void SetSubType(sal_uInt16 nType);
124 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
125 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
127 static sal_uInt16 GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc, unsigned nHint = 0);
128 // #i82544#
129 void SetLateInitialization() { bLateInitialization = true;}
132 inline void SwGetExpField::ChgExpStr(const String& rExpand)
133 { sExpand = rExpand;}
135 inline const String& SwGetExpField::GetExpStr() const
136 { return sExpand; }
138 /// Called by formating.
139 inline bool SwGetExpField::IsInBodyTxt() const
140 { return bIsInBodyTxt; }
142 /// Set by UpdateExpFlds where node position is known.
143 inline void SwGetExpField::ChgBodyTxtFlag( bool bIsInBody )
144 { bIsInBodyTxt = bIsInBody; }
146 class SwSetExpField;
148 class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType
150 OUString sName;
151 const SwNode* pOutlChgNd;
152 String sDelim;
153 sal_uInt16 nType;
154 sal_uInt8 nLevel;
155 sal_Bool bDeleted;
157 protected:
158 virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
160 public:
161 SwSetExpFieldType( SwDoc* pDoc, const String& rName,
162 sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
163 virtual SwFieldType* Copy() const;
164 virtual const OUString& GetName() const;
166 inline void SetType(sal_uInt16 nTyp);
167 inline sal_uInt16 GetType() const;
169 void SetSeqFormat(sal_uLong nFormat);
170 sal_uLong GetSeqFormat();
172 sal_Bool IsDeleted() const { return bDeleted; }
173 void SetDeleted( sal_Bool b ) { bDeleted = b; }
175 /// Overlay, because set-field takes care for its being updated by itself.
176 inline const OUString& GetSetRefName() const;
178 sal_uInt16 SetSeqRefNo( SwSetExpField& rFld );
180 sal_uInt16 GetSeqFldList( SwSeqFldList& rList );
181 String MakeSeqName( sal_uInt16 nSeqNo );
183 /// Number sequence fields chapterwise if required.
184 const String& GetDelimiter() const { return sDelim; }
185 void SetDelimiter( const String& s ) { sDelim = s; }
186 sal_uInt8 GetOutlineLvl() const { return nLevel; }
187 void SetOutlineLvl( sal_uInt8 n ) { nLevel = n; }
188 void SetChapter( SwSetExpField& rFld, const SwNode& rNd );
190 /** Member only for SwDoc::UpdateExpFld.
191 It is needed only at runtime of sequence field types! */
192 const SwNode* GetOutlineChgNd() const { return pOutlChgNd; }
193 void SetOutlineChgNd( const SwNode* p ) { pOutlChgNd = p; }
195 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
196 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
199 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
201 nType = nTyp;
202 EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
205 inline sal_uInt16 SwSetExpFieldType::GetType() const
206 { return nType; }
208 inline const OUString& SwSetExpFieldType::GetSetRefName() const
209 { return sName; }
212 class SW_DLLPUBLIC SwSetExpField : public SwFormulaField
214 String sExpand;
215 String aPText;
216 String aSeqText;
217 sal_Bool bInput;
218 sal_uInt16 nSeqNo;
219 sal_uInt16 nSubType;
221 virtual String Expand() const;
222 virtual SwField* Copy() const;
224 public:
225 SwSetExpField(SwSetExpFieldType*, const String& rFormel, sal_uLong nFmt = 0);
227 virtual void SetValue( const double& rVal );
229 inline const String& GetExpStr() const;
231 inline void ChgExpStr( const String& rExpand );
233 inline void SetPromptText(const String& rStr);
234 inline const String& GetPromptText() const;
236 inline void SetInputFlag(sal_Bool bInp);
237 inline sal_Bool GetInputFlag() const;
239 virtual String GetFieldName() const;
241 virtual sal_uInt16 GetSubType() const;
242 virtual void SetSubType(sal_uInt16 nType);
244 inline sal_Bool IsSequenceFld() const;
246 /// Logical number, sequence fields.
247 inline void SetSeqNumber( sal_uInt16 n ) { nSeqNo = n; }
248 inline sal_uInt16 GetSeqNumber() const { return nSeqNo; }
250 /// Query name only.
251 virtual const OUString& GetPar1() const;
253 /// Query formula.
254 virtual OUString GetPar2() const;
255 virtual void SetPar2(const OUString& rStr);
256 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
257 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
260 inline const String& SwSetExpField::GetExpStr() const
261 { return sExpand; }
263 inline void SwSetExpField::ChgExpStr( const String& rExpand )
264 { sExpand = rExpand; }
266 inline void SwSetExpField::SetPromptText(const String& rStr)
267 { aPText = rStr; }
269 inline const String& SwSetExpField::GetPromptText() const
270 { return aPText; }
272 inline void SwSetExpField::SetInputFlag(sal_Bool bInp)
273 { bInput = bInp; }
275 inline sal_Bool SwSetExpField::GetInputFlag() const
276 { return bInput; }
278 inline sal_Bool SwSetExpField::IsSequenceFld() const
279 { return 0 != (nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType*)GetTyp())->GetType()); }
282 class SwInputFieldType : public SwFieldType
284 SwDoc* pDoc;
285 public:
286 SwInputFieldType( SwDoc* pDoc );
288 virtual SwFieldType* Copy() const;
290 SwDoc* GetDoc() const { return pDoc; }
294 class SW_DLLPUBLIC SwInputField : public SwField
296 OUString aContent;
297 String aPText;
298 String aHelp;
299 String aToolTip;
300 sal_uInt16 nSubType;
302 virtual String Expand() const;
303 virtual SwField* Copy() const;
305 public:
306 /// Direct input via dialog; delete old value.
307 SwInputField(SwInputFieldType*, const String& rContent ,
308 const String& rPrompt, sal_uInt16 nSubType = 0,
309 sal_uLong nFmt = 0);
311 virtual String GetFieldName() const;
313 /// Content
314 virtual const OUString& GetPar1() const;
315 virtual void SetPar1(const OUString& rStr);
317 /// aPromptText
318 virtual OUString GetPar2() const;
319 virtual void SetPar2(const OUString& rStr);
321 virtual String GetHelp() const;
322 virtual void SetHelp(const String & rStr);
324 virtual String GetToolTip() const;
325 virtual void SetToolTip(const String & rStr);
327 virtual sal_Bool isFormField() const;
329 virtual sal_uInt16 GetSubType() const;
330 virtual void SetSubType(sal_uInt16 nSub);
331 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
332 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
335 /*--------------------------------------------------------------------
336 Description: Sorted list of input fields and DropDown fields
337 --------------------------------------------------------------------*/
339 class SwInputFieldList
341 public:
342 SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst = sal_False );
343 ~SwInputFieldList();
345 sal_uInt16 Count() const;
346 SwField* GetField(sal_uInt16 nId);
348 void GotoFieldPos(sal_uInt16 nId);
349 void PushCrsr();
350 void PopCrsr();
352 /** Put all that are new into SortLst for updating. @return count.
353 (For Glossary: only update its input-fields).
354 Compare TmpLst with current fields. */
355 sal_uInt16 BuildSortLst();
357 void RemoveUnselectedFlds();
359 private:
360 SwEditShell* pSh;
361 _SetGetExpFlds* pSrtLst;
362 std::set<const SwTxtFld*> aTmpLst;
365 /// Implementation in tblcalc.cxx.
366 class SwTblFieldType : public SwValueFieldType
368 public:
369 SwTblFieldType(SwDoc* pDocPtr);
370 virtual SwFieldType* Copy() const;
374 class SwTblField : public SwValueField, public SwTableFormula
376 String sExpand;
377 sal_uInt16 nSubType;
379 virtual String Expand() const;
380 virtual SwField* Copy() const;
382 /// Search TextNode containing the field.
383 virtual const SwNode* GetNodeOfFormula() const;
385 String GetCommand();
387 public:
388 SwTblField( SwTblFieldType*, const String& rFormel,
389 sal_uInt16 nSubType = 0, sal_uLong nFmt = 0);
391 virtual void SetValue( const double& rVal );
392 virtual sal_uInt16 GetSubType() const;
393 virtual void SetSubType(sal_uInt16 nType);
395 const String& GetExpStr() const { return sExpand; }
396 void ChgExpStr(const String& rStr) { sExpand = rStr; }
398 void CalcField( SwTblCalcPara& rCalcPara );
400 virtual String GetFieldName() const;
402 /// The formula.
403 virtual OUString GetPar2() const;
404 virtual void SetPar2(const OUString& rStr);
405 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
406 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
410 #endif // SW_EXPFLD_HXX
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */