update credits
[LibreOffice.git] / sw / inc / fldbas.hxx
blob2c934321be8ddeffdfd52adf5771e97fa0b8b61e
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_FLDBAS_HXX
20 #define SW_FLDBAS_HXX
22 #include <i18nlangtag/lang.h>
23 #include <tools/string.hxx>
24 #include "swdllapi.h"
25 #include <calbck.hxx>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <vector>
29 class SwDoc;
30 class SvNumberFormatter;
32 enum RES_FIELDS
34 /// For old documents the Field-Which IDs must be preserved !!!
35 RES_FIELDS_BEGIN,
36 RES_DBFLD = RES_FIELDS_BEGIN,
37 RES_USERFLD,
38 RES_FILENAMEFLD,
39 RES_DBNAMEFLD,
40 RES_DATEFLD,
41 RES_TIMEFLD,
42 RES_PAGENUMBERFLD,
43 RES_AUTHORFLD,
44 RES_CHAPTERFLD,
45 RES_DOCSTATFLD,
46 RES_GETEXPFLD,
47 RES_SETEXPFLD,
48 RES_GETREFFLD,
49 RES_HIDDENTXTFLD,
50 RES_POSTITFLD,
51 RES_FIXDATEFLD,
52 RES_FIXTIMEFLD,
53 RES_REGFLD,
54 RES_VARREGFLD,
55 RES_SETREFFLD,
56 RES_INPUTFLD,
57 RES_MACROFLD,
58 RES_DDEFLD,
59 RES_TABLEFLD,
60 RES_HIDDENPARAFLD,
61 RES_DOCINFOFLD,
62 RES_TEMPLNAMEFLD,
63 RES_DBNEXTSETFLD,
64 RES_DBNUMSETFLD,
65 RES_DBSETNUMBERFLD,
66 RES_EXTUSERFLD,
67 RES_REFPAGESETFLD,
68 RES_REFPAGEGETFLD,
69 RES_INTERNETFLD,
70 RES_JUMPEDITFLD,
71 RES_SCRIPTFLD,
72 RES_DATETIMEFLD,
73 RES_AUTHORITY, ///< Table of authorities
74 RES_COMBINED_CHARS,
75 RES_DROPDOWN,
76 RES_FIELDS_END
79 /// List of FieldTypes at UI.
80 enum SwFldTypesEnum
82 TYP_BEGIN,
83 TYP_DATEFLD = TYP_BEGIN, // 0
84 TYP_TIMEFLD,
85 TYP_FILENAMEFLD,
86 TYP_DBNAMEFLD,
87 TYP_CHAPTERFLD,
88 TYP_PAGENUMBERFLD,
89 TYP_DOCSTATFLD,
90 TYP_AUTHORFLD,
91 TYP_SETFLD,
92 TYP_GETFLD,
93 TYP_FORMELFLD, // 10
94 TYP_HIDDENTXTFLD,
95 TYP_SETREFFLD,
96 TYP_GETREFFLD,
97 TYP_DDEFLD,
98 TYP_MACROFLD,
99 TYP_INPUTFLD,
100 TYP_HIDDENPARAFLD,
101 TYP_DOCINFOFLD,
102 TYP_DBFLD,
103 TYP_USERFLD, // 20
104 TYP_POSTITFLD,
105 TYP_TEMPLNAMEFLD,
106 TYP_SEQFLD,
107 TYP_DBNEXTSETFLD,
108 TYP_DBNUMSETFLD,
109 TYP_DBSETNUMBERFLD,
110 TYP_CONDTXTFLD,
111 TYP_NEXTPAGEFLD,
112 TYP_PREVPAGEFLD,
113 TYP_EXTUSERFLD, // 30
114 TYP_FIXDATEFLD,
115 TYP_FIXTIMEFLD,
116 TYP_SETINPFLD,
117 TYP_USRINPFLD,
118 TYP_SETREFPAGEFLD,
119 TYP_GETREFPAGEFLD,
120 TYP_INTERNETFLD,
121 TYP_JUMPEDITFLD,
122 TYP_SCRIPTFLD,
123 TYP_AUTHORITY, // 40
124 TYP_COMBINED_CHARS,
125 TYP_DROPDOWN,
126 TYP_END
130 enum SwFileNameFormat
132 FF_BEGIN,
133 FF_NAME = FF_BEGIN,
134 FF_PATHNAME,
135 FF_PATH,
136 FF_NAME_NOEXT,
137 FF_UI_NAME,
138 FF_UI_RANGE,
139 FF_END,
140 FF_FIXED = 0x8000
143 enum SwVarFormat
145 VVF_CMD = 0x0010, ///< Show command.
146 VVF_INVISIBLE = 0x0040, ///< Invisible.
147 VVF_XXP = 0x0400, ///< 1234%
148 VVF_XX_XXP = 0x0800, ///< 1.234,56%
149 VVF_CLEAR = 0x000f,
151 // From here new formats:
152 VVF_SYS = 0x2000, ///< Format for numbers from system.
153 VVF_X = 0x2100, ///< 1234
154 VVF_X_X = 0x2200, ///< 1234.5
155 VVF_X_XX = 0x2300, ///< 1245.56
156 VVF_XX_X = 0x2400, ///< 1.234.5
157 VVF_XX_XX = 0x2500, ///< 1.234.56
158 VVF_XX_XXX = 0x2600, ///< 1.234.567
159 VVF_SYS_CUR = 0x2700, ///< Format for currency from system.
160 VVF_CUR_X = 0x2800, ///< EUR 1234
161 VVF_CUR_XX_XX = 0x2900, ///< EUR 1234.56 EUR 1234.00
162 VVF_CUR_XX_X0 = 0x2a00, ///< EUR 1234.56 EUR 1234.--
163 VVF_X_CUR = 0x2b00, ///< 1234 EUR
164 VVF_XX_XX_CUR = 0x2c00, ///< 1234.56 EUR 1234.00 EUR
165 VVF_XX_X0_CUR = 0x2d00, ///< 1234.56 EUR 1234.-- EUR
166 /// Compatibility:
167 VF_CMD = VVF_CMD,
168 VF_INVISIBLE = VVF_INVISIBLE,
169 VF_XXP = VVF_XXP,
170 VF_XX_XXP = VVF_XX_XXP,
171 VF_VISIBLE = VVF_SYS,
172 VF_XX = VVF_X,
173 VF_XX_XX = VVF_XX_XX,
174 VF_XX_XX_CUR = VVF_SYS_CUR,
175 VF_CLEAR = VVF_CLEAR
179 typedef sal_uInt16 SwGetSetExpType;
180 namespace nsSwGetSetExpType
182 const SwGetSetExpType GSE_STRING = 0x0001; ///< String
183 const SwGetSetExpType GSE_EXPR = 0x0002; ///< Expression
184 const SwGetSetExpType GSE_INP = 0x0004; ///< InputField
185 const SwGetSetExpType GSE_SEQ = 0x0008; ///< Sequence
186 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
189 typedef sal_uInt16 SwExtendedSubType;
190 namespace nsSwExtendedSubType
192 const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command.
193 const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible.
194 const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formating from database.
197 enum SwInputFieldSubType
199 INP_TXT = 0x01,
200 INP_USR = 0x02,
201 INP_VAR = 0x03
205 enum SwUserType
207 UF_STRING = 0x01,
208 UF_EXPR = 0x02
211 enum SwDateTimeSubType
213 FIXEDFLD = 1,
214 DATEFLD = 2,
215 TIMEFLD = 4
219 extern sal_uInt16 aTypeTab[];
221 /// General tools.
222 String GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
223 void SetErrorStr(const String& rStr);
224 String FormatNumber(sal_uInt32 nNum, sal_uInt32 nFormat);
226 /** Instances of SwFields and those derived from it occur 0 to n times.
227 For each class there is one instance of the associated type class.
228 Base class of all field types is SwFieldType. */
230 class SW_DLLPUBLIC SwFieldType : public SwModify
232 sal_uInt16 nWhich;
234 friend void _FinitUI(); ///< In order to delete pointer!
235 static std::vector<String>* pFldNames;
237 static void _GetFldName(); ///< Sets up FldNames; fldmgr.cxx!
239 protected:
240 /// Single argument ctors shall be explicit.
241 explicit SwFieldType( sal_uInt16 nWhichId );
243 public:
245 static const String& GetTypeStr( sal_uInt16 nTypeId );
247 /// Only in derived classes.
248 virtual const OUString& GetName() const;
249 virtual SwFieldType* Copy() const = 0;
250 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
251 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
253 sal_uInt16 Which() const { return nWhich; }
255 inline void UpdateFlds() const;
258 inline void SwFieldType::UpdateFlds() const
260 ((SwFieldType*)this)->ModifyNotification( 0, 0 );
263 /** Base class of all fields.
264 Type of field is queried via Which.
265 Expanded content of field is queried via Expand(). */
266 class SW_DLLPUBLIC SwField
268 private:
269 mutable String m_Cache; ///< Cached expansion (for clipboard).
270 sal_uInt16 nLang; ///< Always change via SetLanguage!
271 sal_Bool bIsAutomaticLanguage;
272 sal_uInt32 nFormat;
274 SwFieldType* pType;
276 virtual String Expand() const = 0;
277 virtual SwField* Copy() const = 0;
279 protected:
280 void SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
282 SwField(SwFieldType* pTyp, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM);
284 public:
285 virtual ~SwField();
287 inline SwFieldType* GetTyp() const;
289 /// Set new type (used for copying among documents).
290 virtual SwFieldType* ChgTyp( SwFieldType* );
292 /** expand the field.
293 @param bCached return cached field value.
294 @remark most callers should use the cached field value.
295 this is because various fields need special handing
296 (ChangeExpansion()) to return correct values, and only
297 SwTxtFormatter::NewFldPortion() sets things up properly.
298 @return the generated text (suitable for display)
300 String ExpandField(bool const bCached) const;
302 /// @return name or content.
303 virtual String GetFieldName() const;
305 SwField * CopyField() const;
307 /// ResId
308 sal_uInt16 Which() const
309 #ifdef DBG_UTIL
310 ; // implemented in fldbas.cxx
311 #else
312 { return pType->Which(); }
313 #endif
315 // TYP_ID
316 sal_uInt16 GetTypeId() const;
317 virtual sal_uInt16 GetSubType() const;
318 virtual void SetSubType(sal_uInt16);
320 /// Language at field position.
321 inline sal_uInt16 GetLanguage() const;
322 virtual void SetLanguage(sal_uInt16 nLng);
324 /// Query parameters for dialog and for BASIC.
325 inline sal_uInt32 GetFormat() const;
326 virtual const OUString& GetPar1() const;
327 virtual OUString GetPar2() const;
329 virtual String GetFormula() const;
331 virtual void ChangeFormat(sal_uInt32 n);
332 virtual void SetPar1(const OUString& rStr);
333 virtual void SetPar2(const OUString& rStr);
335 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
336 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
338 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
339 sal_Bool HasClickHdl() const;
340 sal_Bool IsFixed() const;
342 sal_Bool IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
343 void SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;}
345 virtual String GetDescription() const;
346 /// Is this field clickable?
347 bool IsClickable() const;
350 inline SwFieldType* SwField::GetTyp() const
351 { return pType; }
353 inline sal_uInt32 SwField::GetFormat() const
354 { return nFormat; }
356 inline sal_uInt16 SwField::GetLanguage() const
357 { return nLang; }
360 /// Fields containing values that have to be formated via number formatter.
361 class SwValueFieldType : public SwFieldType
363 SwDoc* pDoc;
364 sal_Bool bUseFormat; ///< Use number formatter.
366 protected:
367 SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
368 SwValueFieldType( const SwValueFieldType& rTyp );
370 public:
371 inline SwDoc* GetDoc() const { return pDoc; }
372 inline void SetDoc(SwDoc* pNewDoc) { pDoc = pNewDoc; }
374 inline sal_Bool UseFormat() const { return bUseFormat; }
375 inline void EnableFormat(sal_Bool bFormat = sal_True) { bUseFormat = bFormat; }
377 String ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
378 void DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const;
379 void DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const;
382 class SW_DLLPUBLIC SwValueField : public SwField
384 double fValue;
386 protected:
387 SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
388 SwValueField( const SwValueField& rFld );
390 public:
391 virtual ~SwValueField();
393 virtual SwFieldType* ChgTyp( SwFieldType* );
394 virtual void SetLanguage(sal_uInt16 nLng);
396 inline SwDoc* GetDoc() const { return ((SwValueFieldType*)GetTyp())->GetDoc(); }
398 virtual double GetValue() const;
399 virtual void SetValue( const double& rVal );
401 inline String ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
402 { return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
404 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
407 class SW_DLLPUBLIC SwFormulaField : public SwValueField
409 String sFormula;
411 protected:
412 SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
413 SwFormulaField( const SwFormulaField& rFld );
415 public:
416 virtual String GetFormula() const;
417 void SetFormula(const String& rStr);
419 void SetExpandedFormula(const String& rStr);
420 String GetExpandedFormula() const;
423 #endif // SW_FLDBAS_HXX
425 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */