xref: /aoo42x/main/sw/inc/fldbas.hxx (revision 4d7c9de0)
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 enum SwAttrFieldTYpe
142 {
143 	ATTR_NONE,
144 	ATTR_DATEFLD,
145 	ATTR_TIMEFLD,
146 	ATTR_PAGENUMBERFLD,
147 	ATTR_PAGECOOUNTFLD,
148 	ATTR_BOOKMARKFLD,
149 	ATTR_SETREFATTRFLD
150 };
151 enum SwFileNameFormat
152 {
153 	FF_BEGIN,
154 	FF_NAME = FF_BEGIN,
155 	FF_PATHNAME,
156 	FF_PATH,
157 	FF_NAME_NOEXT,
158 	FF_UI_NAME,
159 	FF_UI_RANGE,
160 	FF_END,
161 	FF_FIXED = 0x8000
162 };
163 
164 enum SwVarFormat
165 {
166 	VVF_CMD			= 0x0010,	// Kommando anzeigen
167 	VVF_INVISIBLE   = 0x0040,   // unsichtbar
168 	VVF_XXP   		= 0x0400,   // 1234%
169 	VVF_XX_XXP   	= 0x0800,   // 1.234,56%
170 	VVF_CLEAR		= 0x000f,
171 
172 // ab hier neue Formate
173 	VVF_SYS	 		= 0x2000, 	//Zahlenformat aus der Systemeinstellung
174 	VVF_X			= 0x2100,	// 1234
175 	VVF_X_X         = 0x2200,   // 1234,5
176 	VVF_X_XX		= 0x2300,   // 1245,56
177 	VVF_XX_X 		= 0x2400,   // 1.234,5
178 	VVF_XX_XX		= 0x2500,   // 1.234,56
179 	VVF_XX_XXX		= 0x2600,   // 1.234,567
180 	VVF_SYS_CUR		= 0x2700,	// W???hrungsformat aus der Systemeinstellung
181 	VVF_CUR_X		= 0x2800,   // DM 1234
182 	VVF_CUR_XX_XX	= 0x2900,   // DM 1234,56 DM 1234,00
183 	VVF_CUR_XX_X0 	= 0x2a00,   // DM 1234,56 DM 1234,--
184 	VVF_X_CUR		= 0x2b00,   // 1234 DM
185 	VVF_XX_XX_CUR	= 0x2c00,   // 1234,56 DM 1234,00 DM
186 	VVF_XX_X0_CUR	= 0x2d00,    // 1234,56 DM 1234,-- DM
187 // Kompatibilitaet:
188 	VF_CMD			= VVF_CMD,
189 	VF_INVISIBLE    = VVF_INVISIBLE,
190 	VF_XXP   		= VVF_XXP,
191 	VF_XX_XXP   	= VVF_XX_XXP,
192 	VF_VISIBLE		= VVF_SYS,
193 	VF_XX   		= VVF_X,
194 	VF_XX_XX   		= VVF_XX_XX,
195 	VF_XX_XX_CUR   	= VVF_SYS_CUR,
196 	VF_CLEAR		= VVF_CLEAR
197 
198 };
199 
200 typedef sal_uInt16 SwGetSetExpType;
201 namespace nsSwGetSetExpType
202 {
203 	const SwGetSetExpType GSE_STRING  = 0x0001;	// String
204 	const SwGetSetExpType GSE_EXPR	  = 0x0002;	// Expression
205 	const SwGetSetExpType GSE_INP	  = 0x0004;	// InputField
206 	const SwGetSetExpType GSE_SEQ	  = 0x0008;	// Sequence
207 	const SwGetSetExpType GSE_FORMULA = 0x0010;	// Formel
208 }
209 
210 typedef sal_uInt16 SwExtendedSubType;
211 namespace nsSwExtendedSubType
212 {
213 	const SwExtendedSubType SUB_CMD	        = 0x0100;	// Kommando anzeigen
214 	const SwExtendedSubType SUB_INVISIBLE	= 0x0200;	// unsichtbar
215 	const SwExtendedSubType SUB_OWN_FMT		= 0x0400;	// SwDBField: Uebernimmt Formatierung nicht
216 								                        // aus Datenbank
217 }
218 
219 enum SwInputFieldSubType
220 {
221 	INP_TXT		= 0x01,
222 	INP_USR     = 0x02,
223 	INP_VAR     = 0x03
224 };
225 
226 
227 enum SwUserType
228 {
229 	UF_STRING 	= 0x01,
230 	UF_EXPR	  	= 0x02
231 };
232 
233 enum SwDateTimeSubType
234 {
235 	FIXEDFLD = 1,
236 	DATEFLD  = 2,
237 	TIMEFLD  = 4
238 };
239 
240 
241 extern sal_uInt16 __FAR_DATA aTypeTab[];
242 
243 /*--------------------------------------------------------------------
244 	Beschreibung: Allgemeine Tools
245  --------------------------------------------------------------------*/
246 
247 String	GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
248 void    SetErrorStr(const String& rStr);
249 //String	ExpandDate(const Date& rDate, sal_uLong nFmt, sal_uInt16 nLang);
250 //String 	ExpandTime(const Time& rTime, sal_uLong nFmt, sal_uInt16 nLang);
251 String  FormatNumber(sal_uInt16 nNum, sal_uInt32 nFormat);
252 
253 /*--------------------------------------------------------------------
254 	Beschreibung: 	Instanzen von SwFields und Abgeleiteten kommen 0-n mal vor.
255 					Zu jeder Klasse SwFields existiert
256 					1 Instanz der zugehoerigen Typenklasse
257 					Basisklasse aller Feldtypen ist SwFieldType
258  --------------------------------------------------------------------*/
259 
260 DBG_NAMEEX(SwFieldType)
261 
262 class SW_DLLPUBLIC SwFieldType : public SwModify
263 {
264 	sal_uInt16 nWhich;
265 
266 	friend void _FinitUI();		// um den Pointer zu loeschen!
267 	static	SvStringsDtor*	pFldNames;
268 
269 	static void _GetFldName();			// legt die FldNames an, fldmgr.cxx!
270 
271 protected:
272 	// single argument ctors shall be explicit.
273 	explicit SwFieldType( sal_uInt16 nWhichId );
274 
275 public:
276 
277 #ifdef DBG_UTIL
278 	virtual ~SwFieldType();
279 #endif
280 	static	const String&	GetTypeStr( sal_uInt16 nTypeId );
281 
282 	// nur in abgeleiteten Klassen
283 	virtual const String&	GetName() const;
284 	virtual SwFieldType* 	Copy()    const = 0;
285     virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
286     virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
287 
Which() const288 			sal_uInt16 			Which() const { return nWhich; }
289 
290 	inline  void 			UpdateFlds() const;
291 };
292 
UpdateFlds() const293 inline void SwFieldType::UpdateFlds() const
294 {
295 	((SwFieldType*)this)->ModifyNotification( 0, 0 );
296 }
297 
298 /*--------------------------------------------------------------------
299 	Beschreibung:  Basisklasse aller Felder.
300 				   Ueber Which wird der Typ des Feldes abgefragt.
301 				   Ueber Expand() wird der expandierte Inhalt
302 				   des Feldes in Erfahrung gebracht.
303  --------------------------------------------------------------------*/
304 
305 class SW_DLLPUBLIC SwField
306 {
307 private:
308     mutable String      m_Cache; /// #i85766# cached expansion (for clipboard)
309     bool m_bUseFieldValueCache; /// control the usage of the cached field value
310 
311 	sal_uInt16				nLang;	// Immer ueber SetLanguage aendern!
312     sal_Bool                bIsAutomaticLanguage;
313 	sal_uInt32			nFormat;
314 
315 	SwFieldType* 		pType;
316 
317 	virtual String		Expand() const = 0;
318 	virtual SwField* 	Copy() const = 0;
319 
320 protected:
SetFormat(sal_uInt32 nSet)321 	void				SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
322 
323     SwField( SwFieldType* pTyp,
324              sal_uInt32 nFmt = 0,
325              sal_uInt16 nLang = LANGUAGE_SYSTEM,
326              bool m_bUseFieldValueCache = true );
327 
328 public:
329 	virtual 			~SwField();
330 
331 	// Typ feststellen
332 	inline SwFieldType*	GetTyp() const;
333 
334 	// neuen Typ setzen (wird fuer das Kopieren zwischen Dokumenten benutzt)
335 	virtual SwFieldType* ChgTyp( SwFieldType* );
336 
337     /** expand the field.
338         @param  bCached     return cached field value.
339         @remark     most callers should use the cached field value.
340                     this is because various fields need special handing
341                     (ChangeExpansion()) to return correct values, and only
342                     SwTxtFormatter::NewFldPortion() sets things up properly.
343         @return     the generated text (suitable for display)
344       */
345     String              ExpandField(bool const bCached) const;
346 
347     virtual String      GetFieldName() const;
348 
349     SwField *           CopyField() const;
350 
351 	// ResId
Which() const352 	sal_uInt16              Which() const
353 #ifndef DBG_UTIL
354 		{ return pType->Which(); }
355 #else
356 		;       // in fldbas.cxx implementiert
357 #endif
358 
359 	// TYP_ID
360 			sal_uInt16		GetTypeId() const;
361 	virtual sal_uInt16		GetSubType() const;
362 	virtual void        SetSubType(sal_uInt16);
363 
364 	// Sprache an der Feldposition
365 	inline sal_uInt16		GetLanguage() const;
366 	virtual void		SetLanguage(sal_uInt16 nLng);
367 
368 	// Parameter fuer Dialog und BASIC erfragen
369 	inline sal_uInt32	GetFormat() const;
370 	virtual const String& GetPar1() const;
371 	virtual String		GetPar2() 	const;
372 
373 	virtual String		GetFormula() const;
374 
375 	virtual void  		ChangeFormat(sal_uInt32 n);
376 	virtual void		SetPar1(const String& rStr);
377 	virtual void		SetPar2(const String& rStr);
378 
379     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
380     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
381 	// hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
382 	sal_Bool		 	HasClickHdl() const;
383 	// ist es ein Fix-Feld?
384 	sal_Bool 			IsFixed() const;
385 
IsAutomaticLanguage() const386     sal_Bool                IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
SetAutomaticLanguage(sal_Bool bSet)387     void                SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;}
388 
389     virtual String      GetDescription() const;
390 };
391 
GetTyp() const392 inline SwFieldType*	SwField::GetTyp() const
393 	{ return pType; 	}
394 
GetFormat() const395 inline sal_uInt32 SwField::GetFormat() const
396 	{ return nFormat; 	}
397 
GetLanguage() const398 inline sal_uInt16 SwField::GetLanguage() const
399 	{ return nLang;		}
400 
401 /*--------------------------------------------------------------------
402 	Beschreibung:	Felder mit Values, die ueber der Numberformatter
403 					formatiert werden muessen
404  --------------------------------------------------------------------*/
405 
406 class SwValueFieldType : public SwFieldType
407 {
408 	SwDoc*	pDoc;
409 	sal_Bool	bUseFormat;	// Numberformatter verwenden
410 
411 protected:
412 	SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
413 	SwValueFieldType( const SwValueFieldType& rTyp );
414 
415 public:
GetDoc() const416 	inline SwDoc*	GetDoc() const						{ return pDoc; }
SetDoc(SwDoc * pNewDoc)417 	inline void		SetDoc(SwDoc* pNewDoc)				{ pDoc = pNewDoc; }
418 
UseFormat() const419 	inline sal_Bool		UseFormat() const					{ return bUseFormat; }
EnableFormat(sal_Bool bFormat=sal_True)420 	inline void		EnableFormat(sal_Bool bFormat = sal_True)	{ bUseFormat = bFormat; }
421 
422 	String			ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
423 	void			DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const;
424 	void			DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const;
425 };
426 
427 class SW_DLLPUBLIC SwValueField : public SwField
428 {
429 	double fValue;
430 //	String sExpand;
431 
432 protected:
433 	SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
434 	SwValueField( const SwValueField& rFld );
435 
436 public:
437 	virtual 				~SwValueField();
438 
439 	virtual SwFieldType*	ChgTyp( SwFieldType* );
440 	virtual void			SetLanguage(sal_uInt16 nLng);
441 //  os: wozu war das denn da?
442 //	virtual void  			ChangeFormat(sal_uLong n);
443 
GetDoc() const444 	inline SwDoc*			GetDoc() const			{ return ((SwValueFieldType*)GetTyp())->GetDoc(); }
445 
446 	virtual double			GetValue() const;
447 	virtual void 			SetValue( const double& rVal );
448 
ExpandValue(const double & rVal,sal_uInt32 nFmt,sal_uInt16 nLng=0) const449 	inline String	ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
450 		{ return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
451 
452 	static sal_uInt32		GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
453 };
454 
455 class SW_DLLPUBLIC SwFormulaField : public SwValueField
456 {
457 	String sFormula;
458 
459 protected:
460 	SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
461 	SwFormulaField( const SwFormulaField& rFld );
462 
463 public:
464 	virtual String			GetFormula() const;
465 	void 					SetFormula(const String& rStr);
466 
467 	void					SetExpandedFormula(const String& rStr);
468 	String					GetExpandedFormula() const;
469 };
470 
471 #endif // SW_FLDBAS_HXX
472