xref: /aoo41x/main/sw/inc/fldbas.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_FLDBAS_HXX
24 #define SW_FLDBAS_HXX
25 
26 #include <i18npool/lang.h>
27 #include <tools/debug.hxx>
28 #include <tools/string.hxx>
29 #include "swdllapi.h"
30 #include <calbck.hxx>
31 #include <com/sun/star/uno/Any.hxx>
32 
33 class SwDoc;
34 class SvStringsDtor;
35 class SvNumberFormatter;
36 
37 
38 /*--------------------------------------------------------------------
39 	Beschreibung: 	die ID's fuer die Feldtypen
40  --------------------------------------------------------------------*/
41 
42 enum RES_FIELDS
43 {
44 // Fuer die alten Dokumente muessen die Field-Which IDS erhalten bleiben !!!!
45 	RES_FIELDS_BEGIN,
46 	RES_DBFLD = RES_FIELDS_BEGIN,
47 	RES_USERFLD,
48 	RES_FILENAMEFLD,
49 	RES_DBNAMEFLD,
50 	RES_DATEFLD,
51 	RES_TIMEFLD,
52 	RES_PAGENUMBERFLD,
53 	RES_AUTHORFLD,
54 	RES_CHAPTERFLD,
55 	RES_DOCSTATFLD,
56 	RES_GETEXPFLD,
57 	RES_SETEXPFLD,
58 	RES_GETREFFLD,
59 	RES_HIDDENTXTFLD,
60 	RES_POSTITFLD,
61 	RES_FIXDATEFLD,
62 	RES_FIXTIMEFLD,
63 	RES_REGFLD,
64 	RES_VARREGFLD,
65 	RES_SETREFFLD,
66 	RES_INPUTFLD,
67 	RES_MACROFLD,
68 	RES_DDEFLD,
69 	RES_TABLEFLD,
70 	RES_HIDDENPARAFLD,
71 	RES_DOCINFOFLD,
72 	RES_TEMPLNAMEFLD,
73 	RES_DBNEXTSETFLD,
74 	RES_DBNUMSETFLD,
75 	RES_DBSETNUMBERFLD,
76 	RES_EXTUSERFLD,
77 	RES_REFPAGESETFLD,
78 	RES_REFPAGEGETFLD,
79 	RES_INTERNETFLD,
80 	RES_JUMPEDITFLD,
81 	RES_SCRIPTFLD,
82 	RES_DATETIMEFLD,
83 	RES_AUTHORITY,	//Table of authorities
84 	RES_COMBINED_CHARS,
85     RES_DROPDOWN,
86 	RES_FIELDS_END
87 };
88 
89 /*--------------------------------------------------------------------
90 	Beschreibung: Liste der FieldTypes am UI
91  --------------------------------------------------------------------*/
92 
93 enum SwFldTypesEnum
94 {
95 	TYP_BEGIN,
96 	TYP_DATEFLD = TYP_BEGIN,	// 0
97 	TYP_TIMEFLD,
98 	TYP_FILENAMEFLD,
99 	TYP_DBNAMEFLD,
100 	TYP_CHAPTERFLD,
101 	TYP_PAGENUMBERFLD,
102 	TYP_DOCSTATFLD,
103 	TYP_AUTHORFLD,
104 	TYP_SETFLD,
105 	TYP_GETFLD,
106 	TYP_FORMELFLD,  			// 10
107 	TYP_HIDDENTXTFLD,
108 	TYP_SETREFFLD,
109 	TYP_GETREFFLD,
110 	TYP_DDEFLD,
111 	TYP_MACROFLD,
112 	TYP_INPUTFLD,
113 	TYP_HIDDENPARAFLD,
114 	TYP_DOCINFOFLD,
115 	TYP_DBFLD,
116 	TYP_USERFLD,				// 20
117 	TYP_POSTITFLD,
118 	TYP_TEMPLNAMEFLD,
119 	TYP_SEQFLD,
120 	TYP_DBNEXTSETFLD,
121 	TYP_DBNUMSETFLD,
122 	TYP_DBSETNUMBERFLD,
123 	TYP_CONDTXTFLD,
124 	TYP_NEXTPAGEFLD,
125 	TYP_PREVPAGEFLD,
126 	TYP_EXTUSERFLD,				// 30
127 	TYP_FIXDATEFLD,
128 	TYP_FIXTIMEFLD,
129 	TYP_SETINPFLD,
130 	TYP_USRINPFLD,
131 	TYP_SETREFPAGEFLD,
132 	TYP_GETREFPAGEFLD,
133 	TYP_INTERNETFLD,
134 	TYP_JUMPEDITFLD,
135 	TYP_SCRIPTFLD,				// 40
136 	TYP_AUTHORITY,
137 	TYP_COMBINED_CHARS,
138     TYP_DROPDOWN,
139 	TYP_END
140 };
141 //IAccessibility2 Implementation 2009-----
142 enum SwAttrFieldTYpe
143 {
144 	ATTR_NONE,
145 	ATTR_DATEFLD,
146 	ATTR_TIMEFLD,
147 	ATTR_PAGENUMBERFLD,
148 	ATTR_PAGECOOUNTFLD,
149 	ATTR_BOOKMARKFLD,
150 	ATTR_SETREFATTRFLD
151 };
152 //-----IAccessibility2 Implementation 2009
153 enum SwFileNameFormat
154 {
155 	FF_BEGIN,
156 	FF_NAME = FF_BEGIN,
157 	FF_PATHNAME,
158 	FF_PATH,
159 	FF_NAME_NOEXT,
160 	FF_UI_NAME,
161 	FF_UI_RANGE,
162 	FF_END,
163 	FF_FIXED = 0x8000
164 };
165 
166 enum SwVarFormat
167 {
168 	VVF_CMD			= 0x0010,	// Kommando anzeigen
169 	VVF_INVISIBLE   = 0x0040,   // unsichtbar
170 	VVF_XXP   		= 0x0400,   // 1234%
171 	VVF_XX_XXP   	= 0x0800,   // 1.234,56%
172 	VVF_CLEAR		= 0x000f,
173 
174 // ab hier neue Formate
175 	VVF_SYS	 		= 0x2000, 	//Zahlenformat aus der Systemeinstellung
176 	VVF_X			= 0x2100,	// 1234
177 	VVF_X_X         = 0x2200,   // 1234,5
178 	VVF_X_XX		= 0x2300,   // 1245,56
179 	VVF_XX_X 		= 0x2400,   // 1.234,5
180 	VVF_XX_XX		= 0x2500,   // 1.234,56
181 	VVF_XX_XXX		= 0x2600,   // 1.234,567
182 	VVF_SYS_CUR		= 0x2700,	// W???hrungsformat aus der Systemeinstellung
183 	VVF_CUR_X		= 0x2800,   // DM 1234
184 	VVF_CUR_XX_XX	= 0x2900,   // DM 1234,56 DM 1234,00
185 	VVF_CUR_XX_X0 	= 0x2a00,   // DM 1234,56 DM 1234,--
186 	VVF_X_CUR		= 0x2b00,   // 1234 DM
187 	VVF_XX_XX_CUR	= 0x2c00,   // 1234,56 DM 1234,00 DM
188 	VVF_XX_X0_CUR	= 0x2d00,    // 1234,56 DM 1234,-- DM
189 // Kompatibilitaet:
190 	VF_CMD			= VVF_CMD,
191 	VF_INVISIBLE    = VVF_INVISIBLE,
192 	VF_XXP   		= VVF_XXP,
193 	VF_XX_XXP   	= VVF_XX_XXP,
194 	VF_VISIBLE		= VVF_SYS,
195 	VF_XX   		= VVF_X,
196 	VF_XX_XX   		= VVF_XX_XX,
197 	VF_XX_XX_CUR   	= VVF_SYS_CUR,
198 	VF_CLEAR		= VVF_CLEAR
199 
200 };
201 
202 typedef sal_uInt16 SwGetSetExpType;
203 namespace nsSwGetSetExpType
204 {
205 	const SwGetSetExpType GSE_STRING  = 0x0001;	// String
206 	const SwGetSetExpType GSE_EXPR	  = 0x0002;	// Expression
207 	const SwGetSetExpType GSE_INP	  = 0x0004;	// InputField
208 	const SwGetSetExpType GSE_SEQ	  = 0x0008;	// Sequence
209 	const SwGetSetExpType GSE_FORMULA = 0x0010;	// Formel
210 }
211 
212 typedef sal_uInt16 SwExtendedSubType;
213 namespace nsSwExtendedSubType
214 {
215 	const SwExtendedSubType SUB_CMD	        = 0x0100;	// Kommando anzeigen
216 	const SwExtendedSubType SUB_INVISIBLE	= 0x0200;	// unsichtbar
217 	const SwExtendedSubType SUB_OWN_FMT		= 0x0400;	// SwDBField: Uebernimmt Formatierung nicht
218 								                        // aus Datenbank
219 }
220 
221 enum SwInputFieldSubType
222 {
223 	INP_TXT		= 0x01,
224 	INP_USR     = 0x02,
225 	INP_VAR     = 0x03
226 };
227 
228 
229 enum SwUserType
230 {
231 	UF_STRING 	= 0x01,
232 	UF_EXPR	  	= 0x02
233 };
234 
235 enum SwDateTimeSubType
236 {
237 	FIXEDFLD = 1,
238 	DATEFLD  = 2,
239 	TIMEFLD  = 4
240 };
241 
242 
243 extern sal_uInt16 __FAR_DATA aTypeTab[];
244 
245 /*--------------------------------------------------------------------
246 	Beschreibung: Allgemeine Tools
247  --------------------------------------------------------------------*/
248 
249 String	GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
250 void    SetErrorStr(const String& rStr);
251 //String	ExpandDate(const Date& rDate, sal_uLong nFmt, sal_uInt16 nLang);
252 //String 	ExpandTime(const Time& rTime, sal_uLong nFmt, sal_uInt16 nLang);
253 String  FormatNumber(sal_uInt16 nNum, sal_uInt32 nFormat);
254 
255 /*--------------------------------------------------------------------
256 	Beschreibung: 	Instanzen von SwFields und Abgeleiteten kommen 0-n mal vor.
257 					Zu jeder Klasse SwFields existiert
258 					1 Instanz der zugehoerigen Typenklasse
259 					Basisklasse aller Feldtypen ist SwFieldType
260  --------------------------------------------------------------------*/
261 
262 DBG_NAMEEX(SwFieldType)
263 
264 class SW_DLLPUBLIC SwFieldType : public SwModify
265 {
266 	sal_uInt16 nWhich;
267 
268 	friend void _FinitUI();		// um den Pointer zu loeschen!
269 	static	SvStringsDtor*	pFldNames;
270 
271 	static void _GetFldName();			// legt die FldNames an, fldmgr.cxx!
272 
273 protected:
274 	// single argument ctors shall be explicit.
275 	explicit SwFieldType( sal_uInt16 nWhichId );
276 
277 public:
278 
279 #ifdef DBG_UTIL
280 	virtual ~SwFieldType();
281 #endif
282 	static	const String&	GetTypeStr( sal_uInt16 nTypeId );
283 
284 	// nur in abgeleiteten Klassen
285 	virtual const String&	GetName() const;
286 	virtual SwFieldType* 	Copy()    const = 0;
287     virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
288     virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
289 
290 			sal_uInt16 			Which() const { return nWhich; }
291 
292 	inline  void 			UpdateFlds() const;
293 };
294 
295 inline void SwFieldType::UpdateFlds() const
296 {
297 	((SwFieldType*)this)->ModifyNotification( 0, 0 );
298 }
299 
300 /*--------------------------------------------------------------------
301 	Beschreibung:  Basisklasse aller Felder.
302 				   Ueber Which wird der Typ des Feldes abgefragt.
303 				   Ueber Expand() wird der expandierte Inhalt
304 				   des Feldes in Erfahrung gebracht.
305  --------------------------------------------------------------------*/
306 
307 class SW_DLLPUBLIC SwField
308 {
309 private:
310     mutable String      m_Cache; /// #i85766# cached expansion (for clipboard)
311     bool m_bUseFieldValueCache; /// control the usage of the cached field value
312 
313 	sal_uInt16				nLang;	// Immer ueber SetLanguage aendern!
314     sal_Bool                bIsAutomaticLanguage;
315 	sal_uInt32			nFormat;
316 
317 	SwFieldType* 		pType;
318 
319 	virtual String		Expand() const = 0;
320 	virtual SwField* 	Copy() const = 0;
321 
322 protected:
323 	void				SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
324 
325     SwField( SwFieldType* pTyp,
326              sal_uInt32 nFmt = 0,
327              sal_uInt16 nLang = LANGUAGE_SYSTEM,
328              bool m_bUseFieldValueCache = true );
329 
330 public:
331 	virtual 			~SwField();
332 
333 	// Typ feststellen
334 	inline SwFieldType*	GetTyp() const;
335 
336 	// neuen Typ setzen (wird fuer das Kopieren zwischen Dokumenten benutzt)
337 	virtual SwFieldType* ChgTyp( SwFieldType* );
338 
339     /** expand the field.
340         @param  bCached     return cached field value.
341         @remark     most callers should use the cached field value.
342                     this is because various fields need special handing
343                     (ChangeExpansion()) to return correct values, and only
344                     SwTxtFormatter::NewFldPortion() sets things up properly.
345         @return     the generated text (suitable for display)
346       */
347     String              ExpandField(bool const bCached) const;
348 
349     virtual String      GetFieldName() const;
350 
351     SwField *           CopyField() const;
352 
353 	// ResId
354 	sal_uInt16              Which() const
355 #ifndef DBG_UTIL
356 		{ return pType->Which(); }
357 #else
358 		;       // in fldbas.cxx implementiert
359 #endif
360 
361 	// TYP_ID
362 			sal_uInt16		GetTypeId() const;
363 	virtual sal_uInt16		GetSubType() const;
364 	virtual void        SetSubType(sal_uInt16);
365 
366 	// Sprache an der Feldposition
367 	inline sal_uInt16		GetLanguage() const;
368 	virtual void		SetLanguage(sal_uInt16 nLng);
369 
370 	// Parameter fuer Dialog und BASIC erfragen
371 	inline sal_uInt32	GetFormat() const;
372 	virtual const String& GetPar1() const;
373 	virtual String		GetPar2() 	const;
374 
375 	virtual String		GetFormula() const;
376 
377 	virtual void  		ChangeFormat(sal_uInt32 n);
378 	virtual void		SetPar1(const String& rStr);
379 	virtual void		SetPar2(const String& rStr);
380 
381     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
382     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
383 	// hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
384 	sal_Bool		 	HasClickHdl() const;
385 	// ist es ein Fix-Feld?
386 	sal_Bool 			IsFixed() const;
387 
388     sal_Bool                IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
389     void                SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;}
390 
391     virtual String      GetDescription() const;
392 };
393 
394 inline SwFieldType*	SwField::GetTyp() const
395 	{ return pType; 	}
396 
397 inline sal_uInt32 SwField::GetFormat() const
398 	{ return nFormat; 	}
399 
400 inline sal_uInt16 SwField::GetLanguage() const
401 	{ return nLang;		}
402 
403 /*--------------------------------------------------------------------
404 	Beschreibung:	Felder mit Values, die ueber der Numberformatter
405 					formatiert werden muessen
406  --------------------------------------------------------------------*/
407 
408 class SwValueFieldType : public SwFieldType
409 {
410 	SwDoc*	pDoc;
411 	sal_Bool	bUseFormat;	// Numberformatter verwenden
412 
413 protected:
414 	SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
415 	SwValueFieldType( const SwValueFieldType& rTyp );
416 
417 public:
418 	inline SwDoc*	GetDoc() const						{ return pDoc; }
419 	inline void		SetDoc(SwDoc* pNewDoc)				{ pDoc = pNewDoc; }
420 
421 	inline sal_Bool		UseFormat() const					{ return bUseFormat; }
422 	inline void		EnableFormat(sal_Bool bFormat = sal_True)	{ bUseFormat = bFormat; }
423 
424 	String			ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
425 	void			DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const;
426 	void			DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const;
427 };
428 
429 class SW_DLLPUBLIC SwValueField : public SwField
430 {
431 	double fValue;
432 //	String sExpand;
433 
434 protected:
435 	SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
436 	SwValueField( const SwValueField& rFld );
437 
438 public:
439 	virtual 				~SwValueField();
440 
441 	virtual SwFieldType*	ChgTyp( SwFieldType* );
442 	virtual void			SetLanguage(sal_uInt16 nLng);
443 //  os: wozu war das denn da?
444 //	virtual void  			ChangeFormat(sal_uLong n);
445 
446 	inline SwDoc*			GetDoc() const			{ return ((SwValueFieldType*)GetTyp())->GetDoc(); }
447 
448 	virtual double			GetValue() const;
449 	virtual void 			SetValue( const double& rVal );
450 
451 	inline String	ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
452 		{ return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
453 
454 	static sal_uInt32		GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
455 };
456 
457 class SW_DLLPUBLIC SwFormulaField : public SwValueField
458 {
459 	String sFormula;
460 
461 protected:
462 	SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
463 	SwFormulaField( const SwFormulaField& rFld );
464 
465 public:
466 	virtual String			GetFormula() const;
467 	void 					SetFormula(const String& rStr);
468 
469 	void					SetExpandedFormula(const String& rStr);
470 	String					GetExpandedFormula() const;
471 };
472 
473 #endif // SW_FLDBAS_HXX
474