Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef SW_EXPFLD_HXX
20 : #define SW_EXPFLD_HXX
21 :
22 : #include "swdllapi.h"
23 : #include <fldbas.hxx>
24 : #include <cellfml.hxx>
25 : #include <set>
26 : #include <vector>
27 :
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;
37 :
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 );
41 :
42 : void ReplacePoint(String& sTmpName, bool bWithCommandType = false);
43 :
44 0 : struct _SeqFldLstElem
45 : {
46 : String sDlgEntry;
47 : sal_uInt16 nSeqNo;
48 :
49 0 : _SeqFldLstElem( const String& rStr, sal_uInt16 nNo )
50 0 : : sDlgEntry( rStr ), nSeqNo( nNo )
51 0 : {}
52 : };
53 :
54 0 : class SW_DLLPUBLIC SwSeqFldList
55 : {
56 : std::vector<_SeqFldLstElem*> maData;
57 : public:
58 0 : ~SwSeqFldList()
59 0 : {
60 0 : for( std::vector<_SeqFldLstElem*>::const_iterator it = maData.begin(); it != maData.end(); ++it )
61 0 : delete *it;
62 0 : }
63 :
64 : bool InsertSort(_SeqFldLstElem* pNew);
65 : bool SeekEntry(const _SeqFldLstElem& rNew, sal_uInt16* pPos) const;
66 :
67 0 : sal_uInt16 Count() { return maData.size(); }
68 0 : _SeqFldLstElem* operator[](sal_uInt16 nIndex) { return maData[nIndex]; }
69 : const _SeqFldLstElem* operator[](sal_uInt16 nIndex) const { return maData[nIndex]; }
70 0 : void Clear() { maData.clear(); }
71 : };
72 :
73 204 : class SwGetExpFieldType : public SwValueFieldType
74 : {
75 : public:
76 : SwGetExpFieldType(SwDoc* pDoc);
77 : virtual SwFieldType* Copy() const;
78 :
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 );
83 : };
84 :
85 8 : class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
86 : {
87 : String sExpand;
88 : bool bIsInBodyTxt;
89 : sal_uInt16 nSubType;
90 :
91 : bool bLateInitialization; // #i82544#
92 :
93 : virtual String Expand() const;
94 : virtual SwField* Copy() const;
95 :
96 : public:
97 : SwGetExpField( SwGetExpFieldType*, const String& rFormel,
98 : sal_uInt16 nSubType = nsSwGetSetExpType::GSE_EXPR, sal_uLong nFmt = 0);
99 :
100 : virtual void SetValue( const double& rVal );
101 : virtual void SetLanguage(sal_uInt16 nLng);
102 :
103 : inline const String& GetExpStr() const;
104 : inline void ChgExpStr(const String& rExpand);
105 :
106 : /// Called by formating.
107 : inline bool IsInBodyTxt() const;
108 :
109 : /// Set by UpdateExpFlds where node position is known.
110 : inline void ChgBodyTxtFlag( bool bIsInBody );
111 :
112 : /** For fields in header/footer/footnotes/flys:
113 : Only called by formating!! */
114 : void ChangeExpansion( const SwFrm&, const SwTxtFld& );
115 :
116 : virtual String GetFieldName() const;
117 :
118 : /// Change formula.
119 : virtual rtl::OUString GetPar2() const;
120 : virtual void SetPar2(const rtl::OUString& rStr);
121 :
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 );
126 :
127 : static sal_uInt16 GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc, unsigned nHint = 0);
128 : // #i82544#
129 0 : void SetLateInitialization() { bLateInitialization = true;}
130 : };
131 :
132 1 : inline void SwGetExpField::ChgExpStr(const String& rExpand)
133 1 : { sExpand = rExpand;}
134 :
135 1 : inline const String& SwGetExpField::GetExpStr() const
136 1 : { return sExpand; }
137 :
138 : /// Called by formating.
139 1 : inline bool SwGetExpField::IsInBodyTxt() const
140 1 : { return bIsInBodyTxt; }
141 :
142 : /// Set by UpdateExpFlds where node position is known.
143 0 : inline void SwGetExpField::ChgBodyTxtFlag( bool bIsInBody )
144 0 : { bIsInBodyTxt = bIsInBody; }
145 :
146 : class SwSetExpField;
147 :
148 817 : class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType
149 : {
150 : rtl::OUString sName;
151 : const SwNode* pOutlChgNd;
152 : String sDelim;
153 : sal_uInt16 nType;
154 : sal_uInt8 nLevel;
155 : sal_Bool bDeleted;
156 :
157 : protected:
158 : virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
159 :
160 : public:
161 : SwSetExpFieldType( SwDoc* pDoc, const String& rName,
162 : sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
163 : virtual SwFieldType* Copy() const;
164 : virtual const rtl::OUString& GetName() const;
165 :
166 : inline void SetType(sal_uInt16 nTyp);
167 : inline sal_uInt16 GetType() const;
168 :
169 : void SetSeqFormat(sal_uLong nFormat);
170 : sal_uLong GetSeqFormat();
171 :
172 1 : sal_Bool IsDeleted() const { return bDeleted; }
173 0 : void SetDeleted( sal_Bool b ) { bDeleted = b; }
174 :
175 : /// Overlay, because set-field takes care for its being updated by itself.
176 : inline const rtl::OUString& GetSetRefName() const;
177 :
178 : sal_uInt16 SetSeqRefNo( SwSetExpField& rFld );
179 :
180 : sal_uInt16 GetSeqFldList( SwSeqFldList& rList );
181 : String MakeSeqName( sal_uInt16 nSeqNo );
182 :
183 : /// Number sequence fields chapterwise if required.
184 0 : const String& GetDelimiter() const { return sDelim; }
185 0 : void SetDelimiter( const String& s ) { sDelim = s; }
186 0 : sal_uInt8 GetOutlineLvl() const { return nLevel; }
187 68 : void SetOutlineLvl( sal_uInt8 n ) { nLevel = n; }
188 : void SetChapter( SwSetExpField& rFld, const SwNode& rNd );
189 :
190 : /** Member only for SwDoc::UpdateExpFld.
191 : It is needed only at runtime of sequence field types! */
192 0 : const SwNode* GetOutlineChgNd() const { return pOutlChgNd; }
193 4 : void SetOutlineChgNd( const SwNode* p ) { pOutlChgNd = p; }
194 :
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 );
197 : };
198 :
199 6 : inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
200 : {
201 6 : nType = nTyp;
202 6 : EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
203 6 : }
204 :
205 90 : inline sal_uInt16 SwSetExpFieldType::GetType() const
206 90 : { return nType; }
207 :
208 0 : inline const rtl::OUString& SwSetExpFieldType::GetSetRefName() const
209 0 : { return sName; }
210 :
211 :
212 8 : class SW_DLLPUBLIC SwSetExpField : public SwFormulaField
213 : {
214 : String sExpand;
215 : String aPText;
216 : String aSeqText;
217 : sal_Bool bInput;
218 : sal_uInt16 nSeqNo;
219 : sal_uInt16 nSubType;
220 :
221 : virtual String Expand() const;
222 : virtual SwField* Copy() const;
223 :
224 : public:
225 : SwSetExpField(SwSetExpFieldType*, const String& rFormel, sal_uLong nFmt = 0);
226 :
227 : virtual void SetValue( const double& rVal );
228 :
229 : inline const String& GetExpStr() const;
230 :
231 : inline void ChgExpStr( const String& rExpand );
232 :
233 : inline void SetPromptText(const String& rStr);
234 : inline const String& GetPromptText() const;
235 :
236 : inline void SetInputFlag(sal_Bool bInp);
237 : inline sal_Bool GetInputFlag() const;
238 :
239 : virtual String GetFieldName() const;
240 :
241 : virtual sal_uInt16 GetSubType() const;
242 : virtual void SetSubType(sal_uInt16 nType);
243 :
244 : inline sal_Bool IsSequenceFld() const;
245 :
246 : /// Logical number, sequence fields.
247 1 : inline void SetSeqNumber( sal_uInt16 n ) { nSeqNo = n; }
248 0 : inline sal_uInt16 GetSeqNumber() const { return nSeqNo; }
249 :
250 : /// Query name only.
251 : virtual const rtl::OUString& GetPar1() const;
252 :
253 : /// Query formula.
254 : virtual rtl::OUString GetPar2() const;
255 : virtual void SetPar2(const rtl::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 );
258 : };
259 :
260 0 : inline const String& SwSetExpField::GetExpStr() const
261 0 : { return sExpand; }
262 :
263 0 : inline void SwSetExpField::ChgExpStr( const String& rExpand )
264 0 : { sExpand = rExpand; }
265 :
266 1 : inline void SwSetExpField::SetPromptText(const String& rStr)
267 1 : { aPText = rStr; }
268 :
269 0 : inline const String& SwSetExpField::GetPromptText() const
270 0 : { return aPText; }
271 :
272 1 : inline void SwSetExpField::SetInputFlag(sal_Bool bInp)
273 1 : { bInput = bInp; }
274 :
275 0 : inline sal_Bool SwSetExpField::GetInputFlag() const
276 0 : { return bInput; }
277 :
278 5 : inline sal_Bool SwSetExpField::IsSequenceFld() const
279 5 : { return 0 != (nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType*)GetTyp())->GetType()); }
280 :
281 :
282 204 : class SwInputFieldType : public SwFieldType
283 : {
284 : SwDoc* pDoc;
285 : public:
286 : SwInputFieldType( SwDoc* pDoc );
287 :
288 : virtual SwFieldType* Copy() const;
289 :
290 0 : SwDoc* GetDoc() const { return pDoc; }
291 : };
292 :
293 :
294 0 : class SW_DLLPUBLIC SwInputField : public SwField
295 : {
296 : rtl::OUString aContent;
297 : String aPText;
298 : String aHelp;
299 : String aToolTip;
300 : sal_uInt16 nSubType;
301 :
302 : virtual String Expand() const;
303 : virtual SwField* Copy() const;
304 :
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);
310 :
311 : virtual String GetFieldName() const;
312 :
313 : /// Content
314 : virtual const rtl::OUString& GetPar1() const;
315 : virtual void SetPar1(const rtl::OUString& rStr);
316 :
317 : /// aPromptText
318 : virtual rtl::OUString GetPar2() const;
319 : virtual void SetPar2(const rtl::OUString& rStr);
320 :
321 : virtual String GetHelp() const;
322 : virtual void SetHelp(const String & rStr);
323 :
324 : virtual String GetToolTip() const;
325 : virtual void SetToolTip(const String & rStr);
326 :
327 : virtual sal_Bool isFormField() const;
328 :
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 );
333 : };
334 :
335 : /*--------------------------------------------------------------------
336 : Description: Sorted list of input fields and DropDown fields
337 : --------------------------------------------------------------------*/
338 :
339 : class SwInputFieldList
340 : {
341 : public:
342 : SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst = sal_False );
343 : ~SwInputFieldList();
344 :
345 : sal_uInt16 Count() const;
346 : SwField* GetField(sal_uInt16 nId);
347 :
348 : void GotoFieldPos(sal_uInt16 nId);
349 : void PushCrsr();
350 : void PopCrsr();
351 :
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();
356 :
357 : void RemoveUnselectedFlds();
358 :
359 : private:
360 : SwEditShell* pSh;
361 : _SetGetExpFlds* pSrtLst;
362 : std::set<const SwTxtFld*> aTmpLst;
363 : };
364 :
365 : /// Implementation in tblcalc.cxx.
366 204 : class SwTblFieldType : public SwValueFieldType
367 : {
368 : public:
369 : SwTblFieldType(SwDoc* pDocPtr);
370 : virtual SwFieldType* Copy() const;
371 : };
372 :
373 :
374 0 : class SwTblField : public SwValueField, public SwTableFormula
375 : {
376 : String sExpand;
377 : sal_uInt16 nSubType;
378 :
379 : virtual String Expand() const;
380 : virtual SwField* Copy() const;
381 :
382 : /// Search TextNode containing the field.
383 : virtual const SwNode* GetNodeOfFormula() const;
384 :
385 : String GetCommand();
386 :
387 : public:
388 : SwTblField( SwTblFieldType*, const String& rFormel,
389 : sal_uInt16 nSubType = 0, sal_uLong nFmt = 0);
390 :
391 : virtual void SetValue( const double& rVal );
392 : virtual sal_uInt16 GetSubType() const;
393 : virtual void SetSubType(sal_uInt16 nType);
394 :
395 0 : const String& GetExpStr() const { return sExpand; }
396 0 : void ChgExpStr(const String& rStr) { sExpand = rStr; }
397 :
398 : void CalcField( SwTblCalcPara& rCalcPara );
399 :
400 : virtual String GetFieldName() const;
401 :
402 : /// The formula.
403 : virtual rtl::OUString GetPar2() const;
404 : virtual void SetPar2(const rtl::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 );
407 : };
408 :
409 :
410 : #endif // SW_EXPFLD_HXX
411 :
412 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|