update emoji autocorrect entries from po-files
[LibreOffice.git] / sw / inc / fldbas.hxx
blob6406fae27b715d779efeb88f8b39f9706aee5159
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 INCLUDED_SW_INC_FLDBAS_HXX
20 #define INCLUDED_SW_INC_FLDBAS_HXX
22 #include <i18nlangtag/lang.h>
23 #include "swdllapi.h"
24 #include <calbck.hxx>
25 #include <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <cppuhelper/weakref.hxx>
28 #include <vector>
29 #include <toxe.hxx>
30 class SwDoc;
31 class SvNumberFormatter;
33 enum RES_FIELDS
35 /// For old documents the Field-Which IDs must be preserved !!!
36 RES_FIELDS_BEGIN,
37 RES_DBFLD = RES_FIELDS_BEGIN,
38 RES_USERFLD,
39 RES_FILENAMEFLD,
40 RES_DBNAMEFLD,
41 RES_DATEFLD,
42 RES_TIMEFLD,
43 RES_PAGENUMBERFLD,
44 RES_AUTHORFLD,
45 RES_CHAPTERFLD,
46 RES_DOCSTATFLD,
47 RES_GETEXPFLD,
48 RES_SETEXPFLD,
49 RES_GETREFFLD,
50 RES_HIDDENTXTFLD,
51 RES_POSTITFLD,
52 RES_FIXDATEFLD,
53 RES_FIXTIMEFLD,
54 RES_REGFLD,
55 RES_VARREGFLD,
56 RES_SETREFFLD,
57 RES_INPUTFLD,
58 RES_MACROFLD,
59 RES_DDEFLD,
60 RES_TABLEFLD,
61 RES_HIDDENPARAFLD,
62 RES_DOCINFOFLD,
63 RES_TEMPLNAMEFLD,
64 RES_DBNEXTSETFLD,
65 RES_DBNUMSETFLD,
66 RES_DBSETNUMBERFLD,
67 RES_EXTUSERFLD,
68 RES_REFPAGESETFLD,
69 RES_REFPAGEGETFLD,
70 RES_INTERNETFLD,
71 RES_JUMPEDITFLD,
72 RES_SCRIPTFLD,
73 RES_DATETIMEFLD,
74 RES_AUTHORITY, ///< Table of authorities
75 RES_COMBINED_CHARS,
76 RES_DROPDOWN,
77 RES_FIELDS_END
80 /// List of FieldTypes at UI.
81 enum SwFieldTypesEnum
83 TYP_BEGIN,
84 TYP_DATEFLD = TYP_BEGIN, // 0
85 TYP_TIMEFLD,
86 TYP_FILENAMEFLD,
87 TYP_DBNAMEFLD,
88 TYP_CHAPTERFLD,
89 TYP_PAGENUMBERFLD,
90 TYP_DOCSTATFLD,
91 TYP_AUTHORFLD,
92 TYP_SETFLD,
93 TYP_GETFLD,
94 TYP_FORMELFLD, // 10
95 TYP_HIDDENTXTFLD,
96 TYP_SETREFFLD,
97 TYP_GETREFFLD,
98 TYP_DDEFLD,
99 TYP_MACROFLD,
100 TYP_INPUTFLD,
101 TYP_HIDDENPARAFLD,
102 TYP_DOCINFOFLD,
103 TYP_DBFLD,
104 TYP_USERFLD, // 20
105 TYP_POSTITFLD,
106 TYP_TEMPLNAMEFLD,
107 TYP_SEQFLD,
108 TYP_DBNEXTSETFLD,
109 TYP_DBNUMSETFLD,
110 TYP_DBSETNUMBERFLD,
111 TYP_CONDTXTFLD,
112 TYP_NEXTPAGEFLD,
113 TYP_PREVPAGEFLD,
114 TYP_EXTUSERFLD, // 30
115 TYP_FIXDATEFLD,
116 TYP_FIXTIMEFLD,
117 TYP_SETINPFLD,
118 TYP_USRINPFLD,
119 TYP_SETREFPAGEFLD,
120 TYP_GETREFPAGEFLD,
121 TYP_INTERNETFLD,
122 TYP_JUMPEDITFLD,
123 TYP_SCRIPTFLD,
124 TYP_AUTHORITY, // 40
125 TYP_COMBINED_CHARS,
126 TYP_DROPDOWN,
127 TYP_END
129 enum SwAttrFieldTYpe
131 ATTR_NONE,
132 ATTR_DATEFLD,
133 ATTR_TIMEFLD,
134 ATTR_PAGENUMBERFLD,
135 ATTR_PAGECOOUNTFLD,
136 ATTR_BOOKMARKFLD,
137 ATTR_SETREFATTRFLD
139 enum SwFileNameFormat
141 FF_BEGIN,
142 FF_NAME = FF_BEGIN,
143 FF_PATHNAME,
144 FF_PATH,
145 FF_NAME_NOEXT,
146 FF_UI_NAME,
147 FF_UI_RANGE,
148 FF_END,
149 FF_FIXED = 0x8000
152 enum SwVarFormat
154 VVF_CMD = 0x0010, ///< Show command.
155 VVF_INVISIBLE = 0x0040, ///< Invisible.
156 VVF_XXP = 0x0400, ///< 1234%
157 VVF_XX_XXP = 0x0800, ///< 1.234,56%
158 VVF_CLEAR = 0x000f,
160 // From here new formats:
161 VVF_SYS = 0x2000, ///< Format for numbers from system.
162 VVF_X = 0x2100, ///< 1234
163 VVF_X_X = 0x2200, ///< 1234.5
164 VVF_X_XX = 0x2300, ///< 1245.56
165 VVF_XX_X = 0x2400, ///< 1.234.5
166 VVF_XX_XX = 0x2500, ///< 1.234.56
167 VVF_XX_XXX = 0x2600, ///< 1.234.567
168 VVF_SYS_CUR = 0x2700, ///< Format for currency from system.
169 VVF_CUR_X = 0x2800, ///< EUR 1234
170 VVF_CUR_XX_XX = 0x2900, ///< EUR 1234.56 EUR 1234.00
171 VVF_CUR_XX_X0 = 0x2a00, ///< EUR 1234.56 EUR 1234.--
172 VVF_X_CUR = 0x2b00, ///< 1234 EUR
173 VVF_XX_XX_CUR = 0x2c00, ///< 1234.56 EUR 1234.00 EUR
174 VVF_XX_X0_CUR = 0x2d00, ///< 1234.56 EUR 1234.-- EUR
175 /// Compatibility:
176 VF_CMD = VVF_CMD,
177 VF_INVISIBLE = VVF_INVISIBLE,
178 VF_XXP = VVF_XXP,
179 VF_XX_XXP = VVF_XX_XXP,
180 VF_VISIBLE = VVF_SYS,
181 VF_XX = VVF_X,
182 VF_XX_XX = VVF_XX_XX,
183 VF_XX_XX_CUR = VVF_SYS_CUR,
184 VF_CLEAR = VVF_CLEAR
188 typedef sal_uInt16 SwGetSetExpType;
189 namespace nsSwGetSetExpType
191 const SwGetSetExpType GSE_STRING = 0x0001; ///< String
192 const SwGetSetExpType GSE_EXPR = 0x0002; ///< Expression
193 const SwGetSetExpType GSE_INP = 0x0004; ///< InputField
194 const SwGetSetExpType GSE_SEQ = 0x0008; ///< Sequence
195 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
198 typedef sal_uInt16 SwExtendedSubType;
199 namespace nsSwExtendedSubType
201 const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command.
202 const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible.
203 const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formatting from database.
206 enum SwInputFieldSubType
208 INP_TXT = 0x01,
209 INP_USR = 0x02,
210 INP_VAR = 0x03
213 enum SwUserType
215 UF_STRING = 0x01,
216 UF_EXPR = 0x02
219 enum SwDateTimeSubType
221 FIXEDFLD = 1,
222 DATEFLD = 2,
223 TIMEFLD = 4
226 /// General tools.
227 OUString GetResult(double nVal, sal_uInt32 nNumFormat, sal_uInt16 nLang = LANGUAGE_SYSTEM);
228 void SetErrorStr(const OUString& rStr);
229 OUString FormatNumber(sal_uInt32 nNum, sal_uInt32 nFormat);
231 /** Instances of SwFields and those derived from it occur 0 to n times.
232 For each class there is one instance of the associated type class.
233 Base class of all field types is SwFieldType. */
235 class SW_DLLPUBLIC SwFieldType : public SwModify
237 ::com::sun::star::uno::WeakReference<
238 ::com::sun::star::beans::XPropertySet> m_wXFieldMaster;
240 sal_uInt16 m_nWhich;
242 friend void _FinitUI(); ///< In order to delete pointer!
243 static std::vector<OUString>* s_pFieldNames;
245 static void _GetFieldName(); ///< Sets up FieldNames; fldmgr.cxx!
247 protected:
248 /// Single argument ctors shall be explicit.
249 explicit SwFieldType( sal_uInt16 nWhichId );
251 public:
253 SAL_DLLPRIVATE ::com::sun::star::uno::WeakReference<
254 ::com::sun::star::beans::XPropertySet> const& GetXObject() const
255 { return m_wXFieldMaster; }
256 SAL_DLLPRIVATE void SetXObject(::com::sun::star::uno::Reference<
257 ::com::sun::star::beans::XPropertySet> const& xFieldMaster)
258 { m_wXFieldMaster = xFieldMaster; }
260 static OUString GetTypeStr( sal_uInt16 nTypeId );
262 /// Only in derived classes.
263 virtual OUString GetName() const;
264 virtual SwFieldType* Copy() const = 0;
265 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
266 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
268 sal_uInt16 Which() const { return m_nWhich; }
270 inline void UpdateFields() const;
273 inline void SwFieldType::UpdateFields() const
275 const_cast<SwFieldType*>(this)->ModifyNotification( 0, 0 );
278 /** Base class of all fields.
279 Type of field is queried via Which.
280 Expanded content of field is queried via Expand(). */
281 class SW_DLLPUBLIC SwField
283 private:
284 mutable OUString m_Cache; ///< Cached expansion (for clipboard).
285 bool m_bUseFieldValueCache; /// control the usage of the cached field value
287 sal_uInt16 m_nLang; ///< Always change via SetLanguage!
288 bool m_bIsAutomaticLanguage;
289 sal_uInt32 m_nFormat;
291 SwFieldType* m_pType;
293 virtual OUString Expand() const = 0;
294 virtual SwField* Copy() const = 0;
296 protected:
297 void SetFormat(sal_uInt32 const nSet) { m_nFormat = nSet; }
299 SwField( SwFieldType* pTyp,
300 sal_uInt32 nFormat = 0,
301 sal_uInt16 nLang = LANGUAGE_SYSTEM,
302 bool m_bUseFieldValueCache = true );
304 public:
305 virtual ~SwField();
307 inline SwFieldType* GetTyp() const;
309 /// Set new type (used for copying among documents).
310 virtual SwFieldType* ChgTyp( SwFieldType* );
312 /** expand the field.
313 @param bCached return cached field value.
314 @remark most callers should use the cached field value.
315 this is because various fields need special handing
316 (ChangeExpansion()) to return correct values, and only
317 SwTextFormatter::NewFieldPortion() sets things up properly.
318 @return the generated text (suitable for display)
320 OUString ExpandField(bool const bCached, ToxAuthorityField eField = AUTH_FIELD_IDENTIFIER) const;
322 /// @return name or content.
323 virtual OUString GetFieldName() const;
325 SwField * CopyField() const;
327 /// ResId
328 sal_uInt16 Which() const
329 #ifdef DBG_UTIL
330 ; // implemented in fldbas.cxx
331 #else
332 { return m_pType->Which(); }
333 #endif
335 // TYP_ID
336 sal_uInt16 GetTypeId() const;
337 virtual sal_uInt16 GetSubType() const;
338 virtual void SetSubType(sal_uInt16);
340 /// Language at field position.
341 inline sal_uInt16 GetLanguage() const;
342 virtual void SetLanguage(sal_uInt16 nLng);
344 /// Query parameters for dialog and for BASIC.
345 inline sal_uInt32 GetFormat() const;
346 virtual OUString GetPar1() const;
347 virtual OUString GetPar2() const;
349 virtual OUString GetFormula() const;
351 void ChangeFormat(sal_uInt32 n);
352 virtual void SetPar1(const OUString& rStr);
353 virtual void SetPar2(const OUString& rStr);
355 virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
356 virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
358 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
359 bool HasClickHdl() const;
360 bool IsFixed() const;
362 bool IsAutomaticLanguage() const { return m_bIsAutomaticLanguage;}
363 void SetAutomaticLanguage(bool const bSet) {m_bIsAutomaticLanguage = bSet;}
365 virtual OUString GetDescription() const;
366 /// Is this field clickable?
367 bool IsClickable() const;
370 inline SwFieldType* SwField::GetTyp() const
371 { return m_pType; }
373 inline sal_uInt32 SwField::GetFormat() const
374 { return m_nFormat; }
376 inline sal_uInt16 SwField::GetLanguage() const
377 { return m_nLang; }
379 /// Fields containing values that have to be formatted via number formatter.
380 class SwValueFieldType : public SwFieldType
382 private:
383 SwDoc* m_pDoc;
384 bool m_bUseFormat; ///< Use number formatter.
386 protected:
387 SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
388 SwValueFieldType( const SwValueFieldType& rTyp );
390 public:
391 inline SwDoc* GetDoc() const { return m_pDoc; }
392 inline void SetDoc(SwDoc* pNewDoc) { m_pDoc = pNewDoc; }
394 inline bool UseFormat() const { return m_bUseFormat; }
395 inline void EnableFormat(bool bFormat = true) { m_bUseFormat = bFormat; }
397 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, sal_uInt16 nLng=0) const;
398 OUString DoubleToString(const double &rVal, LanguageType eLng) const;
399 OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
402 class SW_DLLPUBLIC SwValueField : public SwField
404 private:
405 double m_fValue;
407 protected:
408 SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
409 SwValueField( const SwValueField& rField );
411 public:
412 virtual ~SwValueField();
414 virtual SwFieldType* ChgTyp( SwFieldType* ) SAL_OVERRIDE;
415 virtual void SetLanguage(sal_uInt16 nLng) SAL_OVERRIDE;
417 inline SwDoc* GetDoc() const { return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc(); }
419 virtual double GetValue() const;
420 virtual void SetValue( const double& rVal );
422 inline OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, sal_uInt16 nLng=0) const
423 { return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng); }
425 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
428 class SW_DLLPUBLIC SwFormulaField : public SwValueField
430 private:
431 OUString m_sFormula;
433 protected:
434 SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat = 0, const double fVal = 0.0 );
435 SwFormulaField( const SwFormulaField& rField );
437 public:
438 virtual OUString GetFormula() const SAL_OVERRIDE;
439 void SetFormula(const OUString& rStr);
441 void SetExpandedFormula(const OUString& rStr);
442 OUString GetExpandedFormula() const;
445 #endif // INCLUDED_SW_INC_FLDBAS_HXX
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */