Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / fldbas.hxx
blob91aa97657955a97dce7570740452c0e5f131ab5d
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 <editeng/svxenum.hxx>
29 #include <vector>
30 #include <toxe.hxx>
32 class SwDoc;
33 class SvNumberFormatter;
35 enum class SwFieldIds : sal_uInt16 {
36 /// For old documents the Field-Which IDs must be preserved !!!
37 Database,
38 User,
39 Filename,
40 DatabaseName,
41 Date,
42 Time,
43 PageNumber,
44 Author,
45 Chapter,
46 DocStat,
47 GetExp,
48 SetExp,
49 GetRef,
50 HiddenText,
51 Postit,
52 FixDate,
53 FixTime,
54 Reg,
55 VarReg,
56 SetRef,
57 Input,
58 Macro,
59 Dde,
60 Table,
61 HiddenPara,
62 DocInfo,
63 TemplateName,
64 DbNextSet,
65 DbNumSet,
66 DbSetNumber,
67 ExtUser,
68 RefPageSet,
69 RefPageGet,
70 Internet,
71 JumpEdit,
72 Script,
73 DateTime,
74 TableOfAuthorities,
75 CombinedChars,
76 Dropdown,
77 LAST = Dropdown,
79 Unknown = USHRT_MAX, // used as default value in some method calls
82 /// List of FieldTypes at UI.
83 enum SwFieldTypesEnum {
84 TYP_BEGIN,
85 TYP_DATEFLD = TYP_BEGIN, // 0
86 TYP_TIMEFLD,
87 TYP_FILENAMEFLD,
88 TYP_DBNAMEFLD,
89 TYP_CHAPTERFLD,
90 TYP_PAGENUMBERFLD,
91 TYP_DOCSTATFLD,
92 TYP_AUTHORFLD,
93 TYP_SETFLD,
94 TYP_GETFLD,
95 TYP_FORMELFLD, // 10
96 TYP_HIDDENTXTFLD,
97 TYP_SETREFFLD,
98 TYP_GETREFFLD,
99 TYP_DDEFLD,
100 TYP_MACROFLD,
101 TYP_INPUTFLD,
102 TYP_HIDDENPARAFLD,
103 TYP_DOCINFOFLD,
104 TYP_DBFLD,
105 TYP_USERFLD, // 20
106 TYP_POSTITFLD,
107 TYP_TEMPLNAMEFLD,
108 TYP_SEQFLD,
109 TYP_DBNEXTSETFLD,
110 TYP_DBNUMSETFLD,
111 TYP_DBSETNUMBERFLD,
112 TYP_CONDTXTFLD,
113 TYP_NEXTPAGEFLD,
114 TYP_PREVPAGEFLD,
115 TYP_EXTUSERFLD, // 30
116 TYP_FIXDATEFLD,
117 TYP_FIXTIMEFLD,
118 TYP_SETINPFLD,
119 TYP_USRINPFLD,
120 TYP_SETREFPAGEFLD,
121 TYP_GETREFPAGEFLD,
122 TYP_INTERNETFLD,
123 TYP_JUMPEDITFLD,
124 TYP_SCRIPTFLD,
125 TYP_AUTHORITY, // 40
126 TYP_COMBINED_CHARS,
127 TYP_DROPDOWN,
128 TYP_END
130 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 {
140 FF_BEGIN,
141 FF_NAME = FF_BEGIN,
142 FF_PATHNAME,
143 FF_PATH,
144 FF_NAME_NOEXT,
145 FF_UI_NAME,
146 FF_UI_RANGE,
147 FF_END,
148 FF_FIXED = 0x8000
151 enum SwVarFormat {
152 VVF_CMD = 0x0010, ///< Show command.
153 VVF_INVISIBLE = 0x0040, ///< Invisible.
154 VVF_XXP = 0x0400, ///< 1234%
155 VVF_XX_XXP = 0x0800, ///< 1.234,56%
156 VVF_CLEAR = 0x000f,
158 // From here new formats:
159 VVF_SYS = 0x2000, ///< Format for numbers from system.
160 VVF_X = 0x2100, ///< 1234
161 VVF_X_X = 0x2200, ///< 1234.5
162 VVF_X_XX = 0x2300, ///< 1245.56
163 VVF_XX_X = 0x2400, ///< 1.234.5
164 VVF_XX_XX = 0x2500, ///< 1.234.56
165 VVF_XX_XXX = 0x2600, ///< 1.234.567
166 VVF_SYS_CUR = 0x2700, ///< Format for currency from system.
167 VVF_CUR_X = 0x2800, ///< EUR 1234
168 VVF_CUR_XX_XX = 0x2900, ///< EUR 1234.56 EUR 1234.00
169 VVF_CUR_XX_X0 = 0x2a00, ///< EUR 1234.56 EUR 1234.--
170 VVF_X_CUR = 0x2b00, ///< 1234 EUR
171 VVF_XX_XX_CUR = 0x2c00, ///< 1234.56 EUR 1234.00 EUR
172 VVF_XX_X0_CUR = 0x2d00, ///< 1234.56 EUR 1234.-- EUR
173 /// Compatibility:
174 VF_CMD = VVF_CMD,
175 VF_INVISIBLE = VVF_INVISIBLE,
176 VF_XXP = VVF_XXP,
177 VF_XX_XXP = VVF_XX_XXP,
178 VF_VISIBLE = VVF_SYS,
179 VF_XX = VVF_X,
180 VF_XX_XX = VVF_XX_XX,
181 VF_XX_XX_CUR = VVF_SYS_CUR,
182 VF_CLEAR = VVF_CLEAR
186 typedef sal_uInt16 SwGetSetExpType;
187 namespace nsSwGetSetExpType
189 const SwGetSetExpType GSE_STRING = 0x0001; ///< String
190 const SwGetSetExpType GSE_EXPR = 0x0002; ///< Expression
191 const SwGetSetExpType GSE_INP = 0x0004; ///< InputField
192 const SwGetSetExpType GSE_SEQ = 0x0008; ///< Sequence
193 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
196 typedef sal_uInt16 SwExtendedSubType;
197 namespace nsSwExtendedSubType
199 const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command.
200 const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible.
201 const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formatting from database.
204 enum SwInputFieldSubType {
205 INP_TXT = 0x01,
206 INP_USR = 0x02,
207 INP_VAR = 0x03
210 enum SwUserType {
211 UF_STRING = 0x01,
212 UF_EXPR = 0x02
215 enum SwDateTimeSubType {
216 FIXEDFLD = 1,
217 DATEFLD = 2,
218 TIMEFLD = 4
221 /// General tools.
222 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat);
224 /** Instances of SwFields and those derived from it occur 0 to n times.
225 For each class there is one instance of the associated type class.
226 Base class of all field types is SwFieldType. */
228 class SW_DLLPUBLIC SwFieldType : public SwModify
230 css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
232 SwFieldIds m_nWhich;
234 friend void FinitUI(); ///< In order to delete pointer!
235 static std::vector<OUString>* s_pFieldNames;
237 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
239 protected:
240 /// Single argument ctors shall be explicit.
241 explicit SwFieldType( SwFieldIds nWhichId );
243 public:
245 SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
246 return m_wXFieldMaster;
248 SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
249 m_wXFieldMaster = xFieldMaster;
252 static OUString GetTypeStr( sal_uInt16 nTypeId );
254 /// Only in derived classes.
255 virtual OUString GetName() const;
256 virtual SwFieldType* Copy() const = 0;
257 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
258 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
260 SwFieldIds Which() const { return m_nWhich; }
262 inline void UpdateFields() const;
265 inline void SwFieldType::UpdateFields() const
267 const_cast<SwFieldType*>(this)->ModifyNotification( nullptr, nullptr );
270 /** Base class of all fields.
271 Type of field is queried via Which.
272 Expanded content of field is queried via Expand(). */
273 class SW_DLLPUBLIC SwField
275 private:
276 mutable OUString m_Cache; ///< Cached expansion (for clipboard).
277 bool m_bUseFieldValueCache; /// control the usage of the cached field value
278 LanguageType m_nLang; ///< Always change via SetLanguage!
279 bool m_bIsAutomaticLanguage;
280 sal_uInt32 m_nFormat; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
281 SwFieldType* m_pType;
283 virtual OUString Expand() const = 0;
284 virtual SwField* Copy() const = 0;
286 protected:
287 void SetFormat(sal_uInt32 const nSet) {
288 m_nFormat = nSet;
291 SwField( SwFieldType* pTyp,
292 sal_uInt32 nFormat = 0,
293 LanguageType nLang = LANGUAGE_SYSTEM,
294 bool m_bUseFieldValueCache = true );
296 public:
297 virtual ~SwField();
299 inline SwFieldType* GetTyp() const;
301 /// Set new type (used for copying among documents).
302 virtual SwFieldType* ChgTyp( SwFieldType* );
304 /** expand the field.
305 @param bCached return cached field value.
306 @remark most callers should use the cached field value.
307 this is because various fields need special handing
308 (ChangeExpansion()) to return correct values, and only
309 SwTextFormatter::NewFieldPortion() sets things up properly.
310 @return the generated text (suitable for display)
312 OUString ExpandField(bool const bCached) const;
314 /// @return name or content.
315 virtual OUString GetFieldName() const;
317 SwField * CopyField() const;
319 /// ResId
320 SwFieldIds Which() const
321 #ifdef DBG_UTIL
322 ; // implemented in fldbas.cxx
323 #else
325 return m_pType->Which();
327 #endif
329 // TYP_ID
330 sal_uInt16 GetTypeId() const;
331 virtual sal_uInt16 GetSubType() const;
332 virtual void SetSubType(sal_uInt16);
334 /// Language at field position.
335 inline LanguageType GetLanguage() const;
336 virtual void SetLanguage(LanguageType nLng);
338 /// Query parameters for dialog and for BASIC.
339 inline sal_uInt32 GetFormat() const;
340 virtual OUString GetPar1() const;
341 virtual OUString GetPar2() const;
343 virtual OUString GetFormula() const;
345 void ChangeFormat(sal_uInt32 n);
346 virtual void SetPar1(const OUString& rStr);
347 virtual void SetPar2(const OUString& rStr);
349 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
350 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
352 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
353 bool HasClickHdl() const;
354 bool IsFixed() const;
356 bool IsAutomaticLanguage() const {
357 return m_bIsAutomaticLanguage;
359 void SetAutomaticLanguage(bool const bSet) {
360 m_bIsAutomaticLanguage = bSet;
363 virtual OUString GetDescription() const;
364 /// Is this field clickable?
365 bool IsClickable() const;
366 virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const;
369 inline SwFieldType* SwField::GetTyp() const
371 return m_pType;
374 inline sal_uInt32 SwField::GetFormat() const
376 return m_nFormat;
379 inline LanguageType SwField::GetLanguage() const
381 return m_nLang;
384 /// Fields containing values that have to be formatted via number formatter.
385 class SwValueFieldType : public SwFieldType
387 private:
388 SwDoc* m_pDoc;
389 bool m_bUseFormat; ///< Use number formatter.
391 protected:
392 SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
393 SwValueFieldType( const SwValueFieldType& rTyp );
395 public:
396 SwDoc* GetDoc() const {
397 return m_pDoc;
399 void SetDoc(SwDoc* pNewDoc) {
400 m_pDoc = pNewDoc;
403 bool UseFormat() const {
404 return m_bUseFormat;
406 void EnableFormat(bool bFormat = true) {
407 m_bUseFormat = bFormat;
410 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
411 OUString DoubleToString(const double &rVal, LanguageType eLng) const;
412 OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
415 class SW_DLLPUBLIC SwValueField : public SwField
417 private:
418 double m_fValue;
420 protected:
421 SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
422 SwValueField( const SwValueField& rField );
424 public:
425 virtual ~SwValueField() override;
427 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
428 virtual void SetLanguage(LanguageType nLng) override;
430 SwDoc* GetDoc() const {
431 return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
434 virtual double GetValue() const;
435 virtual void SetValue( const double& rVal );
437 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
438 return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
441 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
444 class SW_DLLPUBLIC SwFormulaField : public SwValueField
446 private:
447 OUString m_sFormula;
449 protected:
450 SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal = 0.0 );
451 SwFormulaField( const SwFormulaField& rField );
453 public:
454 virtual OUString GetFormula() const override;
455 void SetFormula(const OUString& rStr);
457 void SetExpandedFormula(const OUString& rStr);
458 OUString GetExpandedFormula() const;
461 #endif // INCLUDED_SW_INC_FLDBAS_HXX
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */