xref: /aoo42x/main/sw/inc/expfld.hxx (revision 69a74367)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef SW_EXPFLD_HXX
24 #define SW_EXPFLD_HXX
25 
26 #include <svl/svarray.hxx>
27 #include "swdllapi.h"
28 #include <fldbas.hxx>
29 #include <cellfml.hxx>
30 
31 class SfxPoolItem;
32 class SwTxtNode;
33 class SwFrm;
34 struct SwPosition;
35 class SwTxtFld;
36 class SwDoc;
37 class SwFmtFld;
38 class _SetGetExpFlds;
39 class SwEditShell;
40 
41 // Vorwaertsdeklaration: besorge den "Body-TextNode", fuer Exp.Fld in Fly's
42 //						Header/Footers/Footnodes
43 const SwTxtNode* GetBodyTxtNode( const SwDoc& pDoc, SwPosition& rPos,
44 								 const SwFrm& rFrm );
45 // Wandlung Address -> Adressen
46 void ReplacePoint(String& sTmpName, sal_Bool bWithCommandType = sal_False);
47 
48 struct _SeqFldLstElem
49 {
50 	String sDlgEntry;
51 	sal_uInt16 nSeqNo;
52 
53 	_SeqFldLstElem( const String& rStr, sal_uInt16 nNo )
54 		: sDlgEntry( rStr ), nSeqNo( nNo )
55 	{}
56 };
57 SV_DECL_PTRARR_DEL( _SwSeqFldList, _SeqFldLstElem*, 10, 10 )
58 
59 class SW_DLLPUBLIC SwSeqFldList : public _SwSeqFldList
60 {
61 public:
62 	SwSeqFldList()	: _SwSeqFldList( 10, 10 ) {}
63 
64 	sal_Bool InsertSort( _SeqFldLstElem* );
65 	sal_Bool SeekEntry( const _SeqFldLstElem& , sal_uInt16* pPos = 0 );
66 };
67 
68 /*--------------------------------------------------------------------
69 	Beschreibung: Ausdruck
70  --------------------------------------------------------------------*/
71 
72 class SwGetExpFieldType : public SwValueFieldType
73 {
74 public:
75 		SwGetExpFieldType(SwDoc* pDoc);
76 		virtual SwFieldType*    Copy() const;
77 
78 		// ueberlagert, weil das Get-Field nicht veraendert werden kann
79 		// und dann auch nicht aktualisiert werden muss. Aktualisierung
80 		// erfolgt beim Aendern von Set-Werten !
81 protected:
82    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
83 };
84 
85 /*--------------------------------------------------------------------
86 	Beschreibung: GetExperession
87  --------------------------------------------------------------------*/
88 
89 class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
90 {
91 	String 			sExpand;
92 	sal_Bool 			bIsInBodyTxt;
93 	sal_uInt16			nSubType;
94 
95     bool            bLateInitialization; // #i82544#
96 
97     virtual String              Expand() const;
98     virtual SwField*            Copy() const;
99 
100 public:
101 	SwGetExpField( SwGetExpFieldType*, const String& rFormel,
102 				   sal_uInt16 nSubType = nsSwGetSetExpType::GSE_EXPR, sal_uLong nFmt = 0);
103 
104 	virtual void 				SetValue( const double& rVal );
105 	virtual void				SetLanguage(sal_uInt16 nLng);
106 
107 	inline const String& 		GetExpStr() const;
108 	inline void  				ChgExpStr(const String& rExpand);
109 
110 	// wird von der Formatierung abgefragt
111 	inline sal_Bool 				IsInBodyTxt() const;
112 	// wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt)
113 	inline void 				ChgBodyTxtFlag( sal_Bool bIsInBody );
114 	// fuer Felder in Header/Footer/Footnotes/Flys:
115 	// (wird nur von der Formatierung aufgerufen!!)
116 	void 						ChangeExpansion( const SwFrm&, const SwTxtFld& );
117 
118     virtual String      GetFieldName() const;
119 
120 	// Die Formel aendern
121 	virtual String				GetPar2() const;
122 	virtual void				SetPar2(const String& rStr);
123 
124 	virtual sal_uInt16				GetSubType() const;
125 	virtual void				SetSubType(sal_uInt16 nType);
126     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
127     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
128 
129 	static sal_uInt16 		GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc);
130     // #i82544#
131     void				SetLateInitialization() { bLateInitialization = true;}
132 };
133 
134 inline void SwGetExpField::ChgExpStr(const String& rExpand)
135 	{ sExpand = rExpand;}
136 
137 inline const String& SwGetExpField::GetExpStr() const
138 	{ return sExpand; 	}
139 
140 // wird von der Formatierung abgefragt
141 inline sal_Bool SwGetExpField::IsInBodyTxt() const
142 	{ return bIsInBodyTxt; }
143 
144 // wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt)
145 inline void SwGetExpField::ChgBodyTxtFlag( sal_Bool bIsInBody )
146 	{ bIsInBodyTxt = bIsInBody; }
147 
148 
149 /*--------------------------------------------------------------------
150 	Beschreibung: Ausdruck setzen
151  --------------------------------------------------------------------*/
152 
153 class SwSetExpField;
154 
155 class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType
156 {
157 	String 		sName;
158 	const SwNode* pOutlChgNd;
159 	String		sDelim;
160 	sal_uInt16 		nType;
161 	sal_uInt8		nLevel;
162 	sal_Bool		bDeleted;
163 
164 protected:
165    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
166 
167 public:
168 	SwSetExpFieldType( SwDoc* pDoc, const String& rName,
169 						sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
170 	virtual SwFieldType*    Copy() const;
171 	virtual const String&	GetName() const;
172 
173 	inline void				SetType(sal_uInt16 nTyp);
174 	inline sal_uInt16			GetType() const;
175 
176 	void					SetSeqFormat(sal_uLong nFormat);
177 	sal_uLong					GetSeqFormat();
178 
179 	sal_Bool					IsDeleted() const 		{ return bDeleted; }
180 	void					SetDeleted( sal_Bool b )	{ bDeleted = b; }
181 
182 	// ueberlagert, weil das Set-Field selbst dafuer sorgt, das
183 	// es aktualisiert wird.
184 	inline const String& 	GetSetRefName() const;
185 
186 	sal_uInt16 SetSeqRefNo( SwSetExpField& rFld );
187 
188 	sal_uInt16 GetSeqFldList( SwSeqFldList& rList );
189 	String MakeSeqName( sal_uInt16 nSeqNo );
190 
191 	// Seqencefelder ggfs. Kapitelweise numerieren
192 //	sal_Unicode GetDelimiter() const 		{ return cDelim; }
193 //	void SetDelimiter( sal_Unicode c ) 		{ cDelim = c; }
194 	const String& GetDelimiter() const 		{ return sDelim; }
195 	void SetDelimiter( const String& s ) 	{ sDelim = s; }
196 	sal_uInt8 GetOutlineLvl() const 				{ return nLevel; }
197 	void SetOutlineLvl( sal_uInt8 n ) 			{ nLevel = n; }
198 	void SetChapter( SwSetExpField& rFld, const SwNode& rNd );
199 	// Member nur fuers SwDoc::UpdateExpFld - wird nur waehrend der Laufzeit
200 	// von SequencefeldTypen benoetigt!!!
201 	const SwNode* GetOutlineChgNd() const	{ return pOutlChgNd; }
202 	void SetOutlineChgNd( const SwNode* p )	{ pOutlChgNd = p; }
203 
204     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
205     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
206 };
207 
208 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
209 {
210 		nType = nTyp;
211 		EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
212 }
213 
214 inline sal_uInt16 SwSetExpFieldType::GetType() const
215 	{ return nType;	  }
216 
217 inline const String& SwSetExpFieldType::GetSetRefName() const
218 	{ return sName; }
219 
220 
221 /*--------------------------------------------------------------------
222 	Beschreibung: Ausdruck
223  --------------------------------------------------------------------*/
224 
225 class SW_DLLPUBLIC SwSetExpField : public SwFormulaField
226 {
227 	String 			sExpand;
228 	String			aPText;
229 	String			aSeqText;
230 	sal_Bool			bInput;
231 	sal_uInt16 			nSeqNo;
232 	sal_uInt16			nSubType;
233 
234     virtual String              Expand() const;
235     virtual SwField*            Copy() const;
236 
237 public:
238 	SwSetExpField(SwSetExpFieldType*, const String& rFormel, sal_uLong nFmt = 0);
239 
240 	virtual void 				SetValue( const double& rVal );
241 
242 	inline const String& 		GetExpStr() const;
243 
244 	inline void 				ChgExpStr( const String& rExpand );
245 
246 	inline void  				SetPromptText(const String& rStr);
247 	inline const 				String& GetPromptText() const;
248 
249 	inline void  				SetInputFlag(sal_Bool bInp);
250 	inline sal_Bool					GetInputFlag() const;
251 
252     virtual String              GetFieldName() const;
253 
254 	virtual sal_uInt16				GetSubType() const;
255 	virtual void				SetSubType(sal_uInt16 nType);
256 
257 	inline sal_Bool 				IsSequenceFld() const;
258 
259 	// fuer SequenceFelder - logische Nummer
260 	inline void					SetSeqNumber( sal_uInt16 n )	{ nSeqNo = n; }
261 	inline sal_uInt16				GetSeqNumber() const		{ return nSeqNo; }
262 
263 	// Der Name nur erfragen
264 	virtual const String&		GetPar1() 	const;
265 
266 	// Die Formel
267 	virtual String				GetPar2() 	const;
268 	virtual void				SetPar2(const String& rStr);
269     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
270     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
271 };
272 
273 inline const String& SwSetExpField::GetExpStr() const
274 	{ return sExpand; 		}
275 
276 inline void SwSetExpField::ChgExpStr( const String& rExpand )
277 	{ sExpand = rExpand; 	}
278 
279 inline void  SwSetExpField::SetPromptText(const String& rStr)
280 	{ aPText = rStr;  		}
281 
282 inline const String& SwSetExpField::GetPromptText() const
283 	{ return aPText;  		}
284 
285 inline void SwSetExpField::SetInputFlag(sal_Bool bInp)
286 	{ bInput = bInp; }
287 
288 inline sal_Bool	SwSetExpField::GetInputFlag() const
289 	{ return bInput; }
290 
291 inline sal_Bool SwSetExpField::IsSequenceFld() const
292 	{ return 0 != (nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType*)GetTyp())->GetType()); }
293 
294 /*--------------------------------------------------------------------
295 	Beschreibung: Eingabe im Text/Variable setzen
296  --------------------------------------------------------------------*/
297 
298 class SwInputFieldType : public SwFieldType
299 {
300 	SwDoc* pDoc;
301 public:
302 	SwInputFieldType( SwDoc* pDoc );
303 
304 	virtual SwFieldType* Copy() const;
305 
306 	SwDoc* GetDoc() const { return pDoc; }
307 };
308 
309 /*--------------------------------------------------------------------
310 	Beschreibung: Eingabefeld
311  --------------------------------------------------------------------*/
312 
313 class SW_DLLPUBLIC SwInputField : public SwField
314 {
315     mutable String aContent;
316     String aPText;
317     String aHelp;
318     String aToolTip;
319     sal_uInt16 nSubType;
320     bool mbIsFormField;
321 
322     SwFmtFld* mpFmtFld; // attribute to which the <SwInputField> belongs to
323 
324     virtual String          Expand() const;
325     virtual SwField*        Copy() const;
326 
327     // Accessing Input Field's content
328     const String& getContent() const;
329 
330 public:
331     // Direkte Eingabe ueber Dialog alten Wert loeschen
332     SwInputField(
333         SwInputFieldType* pFieldType,
334         const String& rContent,
335         const String& rPrompt,
336         sal_uInt16 nSubType = 0,
337         sal_uLong nFmt = 0,
338         bool bIsFormField = true );
339     virtual ~SwInputField();
340 
341     void SetFmtFld( SwFmtFld& rFmtFld );
342     SwFmtFld* GetFmtFld();
343 
344     // Providing new Input Field's content:
345     // Fill Input Field's content depending on <nSupType>.
346     void applyFieldContent( const String& rNewFieldContent );
347 
348     bool isFormField() const;
349 
350     virtual String          GetFieldName() const;
351 
352     // Content
353     virtual const String&   GetPar1() const;
354     virtual void            SetPar1(const String& rStr);
355 
356     // aPromptText
357     virtual String          GetPar2() const;
358     virtual void            SetPar2(const String& rStr);
359 
360     virtual String          GetHelp() const;
361     virtual void            SetHelp(const String & rStr);
362 
363     virtual String          GetToolTip() const;
364     virtual void            SetToolTip(const String & rStr);
365 
366     virtual sal_uInt16      GetSubType() const;
367     virtual void            SetSubType(sal_uInt16 nSub);
368     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
369     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
370 };
371 
372 /*--------------------------------------------------------------------
373     Description: Sorted list of input fields and DropDown fields
374  --------------------------------------------------------------------*/
375 
376 class SwInputFieldList
377 {
378 public:
379 	SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst = sal_False );
380 	~SwInputFieldList();
381 
382 	sal_uInt16		Count() const;
383 	SwField*    GetField(sal_uInt16 nId);
384 
385 	void		GotoFieldPos(sal_uInt16 nId);
386 	void		PushCrsr();
387 	void	 	PopCrsr();
388 
389 	// vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst
390 	// damit sie geupdatet werden koennen. Returnt die Anzahl.
391 	// (Fuer Textbausteine: nur seine Input-Felder aktualisieren)
392 	sal_uInt16		BuildSortLst();
393 
394 	// Alle unselektierten Felder aus Liste entfernen
395 	void		RemoveUnselectedFlds();
396 
397 private:
398 	SwEditShell*	pSh;
399 	_SetGetExpFlds*	pSrtLst;
400 	SvPtrarr		aTmpLst;
401 };
402 
403 /*--------------------------------------------------------------------
404 	Beschreibung: Tabellen-Formelfeld
405 				  (Implementierung steht in tblcalc.cxx)
406  --------------------------------------------------------------------*/
407 
408 class SwTblFieldType : public SwValueFieldType
409 {
410 public:
411 	SwTblFieldType(SwDoc* pDocPtr);
412 	virtual SwFieldType* Copy() const;
413 };
414 
415 
416 // MSC will den hier nicht
417 //typedef void (SwField:: *FnScanFormel)( const SwTable&, String&,
418 //									 String&, String* = 0, void* = 0 );
419 
420 
421 class SwTblField : public SwValueField, public SwTableFormula
422 {
423 	String 		sExpand;
424 	sal_uInt16		nSubType;
425 
426     virtual String      Expand() const;
427     virtual SwField*    Copy() const;
428 
429 	// suche den TextNode, in dem das Feld steht
430 	virtual const SwNode* GetNodeOfFormula() const;
431 
432     String GetCommand();
433 
434 public:
435 	SwTblField( SwTblFieldType*, const String& rFormel,
436 				sal_uInt16 nSubType = 0, sal_uLong nFmt = 0);
437 
438 	virtual void 		SetValue( const double& rVal );
439 	virtual sal_uInt16		GetSubType() const;
440 	virtual void		SetSubType(sal_uInt16 nType);
441 
442 	const String& 		GetExpStr() const 				{ return sExpand; }
443 	void 				ChgExpStr(const String& rStr) 	{ sExpand = rStr; }
444 
445 	// berechne sich selbst
446 	void 				CalcField( SwTblCalcPara& rCalcPara );
447 
448     virtual String      GetFieldName() const;
449 
450 	// Die Formel
451 	virtual String		GetPar2() 	const;
452 	virtual void		SetPar2(const String& rStr);
453     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
454     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
455 };
456 
457 
458 #endif // SW_EXPFLD_HXX
459