Bump version to 21.06.18.1
[LibreOffice.git] / sw / inc / fldbas.hxx
blobc13cff3e2a2344c7c16ecbba5ff359da9403db5f
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 "ndindex.hxx"
27 #include <cppuhelper/weakref.hxx>
28 #include <editeng/svxenum.hxx>
29 #include <vector>
30 #include <climits>
32 class SwDoc;
33 class SwField;
34 class SwFormatField;
35 class SwDDETable;
36 class SwRootFrame;
37 class SvNumberFormatter;
38 class IDocumentRedlineAccess;
39 class SwGetRefField;
40 namespace com::sun::star::beans { class XPropertySet; }
41 namespace com::sun::star::uno { class Any; }
43 typedef struct _xmlTextWriter* xmlTextWriterPtr;
45 enum class SwFieldIds : sal_uInt16 {
46 /// For old documents the Field-Which IDs must be preserved !!!
47 Database,
48 User,
49 Filename,
50 DatabaseName,
51 Date,
52 Time,
53 PageNumber,
54 Author,
55 Chapter,
56 DocStat,
57 GetExp, // 10
58 SetExp,
59 GetRef,
60 HiddenText,
61 Postit,
62 FixDate,
63 FixTime,
64 Reg,
65 VarReg,
66 SetRef,
67 Input, // 20
68 Macro,
69 Dde,
70 Table,
71 HiddenPara,
72 DocInfo,
73 TemplateName,
74 DbNextSet,
75 DbNumSet,
76 DbSetNumber,
77 ExtUser, // 30
78 RefPageSet,
79 RefPageGet,
80 Internet,
81 JumpEdit,
82 Script,
83 DateTime,
84 TableOfAuthorities,
85 CombinedChars,
86 Dropdown,
87 ParagraphSignature, // 40
88 LAST = ParagraphSignature,
90 Unknown = USHRT_MAX, // used as default value in some method calls
93 /// List of FieldTypes at UI.
94 enum class SwFieldTypesEnum : sal_uInt16 {
95 Begin,
96 Date = Begin, // 0
97 Time,
98 Filename,
99 DatabaseName,
100 Chapter,
101 PageNumber,
102 DocumentStatistics,
103 Author,
104 Set,
105 Get,
106 Formel, // 10
107 HiddenText,
108 SetRef,
109 GetRef,
110 DDE,
111 Macro,
112 Input,
113 HiddenParagraph,
114 DocumentInfo,
115 Database,
116 User, // 20
117 Postit,
118 TemplateName,
119 Sequence,
120 DatabaseNextSet,
121 DatabaseNumberSet,
122 DatabaseSetNumber,
123 ConditionalText,
124 NextPage,
125 PreviousPage,
126 ExtendedUser, // 30
127 FixedDate,
128 FixedTime,
129 SetInput,
130 UserInput,
131 SetRefPage,
132 GetRefPage,
133 Internet,
134 JumpEdit,
135 Script,
136 Authority, // 40
137 CombinedChars,
138 Dropdown,
139 Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
140 ParagraphSignature,
141 LAST,
142 Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
144 enum SwAttrFieldType {
145 ATTR_NONE,
146 ATTR_DATEFLD,
147 ATTR_TIMEFLD,
148 ATTR_PAGENUMBERFLD,
149 ATTR_PAGECOUNTFLD,
150 ATTR_BOOKMARKFLD,
151 ATTR_SETREFATTRFLD
153 enum SwFileNameFormat {
154 FF_BEGIN,
155 FF_NAME = FF_BEGIN,
156 FF_PATHNAME,
157 FF_PATH,
158 FF_NAME_NOEXT,
159 FF_UI_NAME,
160 FF_UI_RANGE,
161 FF_END,
162 FF_FIXED = 0x8000
165 enum SwVarFormat {
166 VVF_CMD = 0x0010, ///< Show command.
167 VVF_INVISIBLE = 0x0040, ///< Invisible.
168 VVF_XXP = 0x0400, ///< 1234%
169 VVF_XX_XXP = 0x0800, ///< 1.234,56%
170 VVF_CLEAR = 0x000f,
172 // From here new formats:
173 VVF_SYS = 0x2000, ///< Format for numbers from system.
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, ///< Format for currency from system.
181 VVF_CUR_X = 0x2800, ///< EUR 1234
182 VVF_CUR_XX_XX = 0x2900, ///< EUR 1234.56 EUR 1234.00
183 VVF_CUR_XX_X0 = 0x2a00, ///< EUR 1234.56 EUR 1234.--
184 VVF_X_CUR = 0x2b00, ///< 1234 EUR
185 VVF_XX_XX_CUR = 0x2c00, ///< 1234.56 EUR 1234.00 EUR
186 VVF_XX_X0_CUR = 0x2d00, ///< 1234.56 EUR 1234.-- EUR
187 /// Compatibility:
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
200 typedef sal_uInt16 SwGetSetExpType;
201 namespace nsSwGetSetExpType
203 const SwGetSetExpType GSE_STRING = 0x0001; ///< String
204 const SwGetSetExpType GSE_EXPR = 0x0002; ///< Expression
205 const SwGetSetExpType GSE_SEQ = 0x0008; ///< Sequence
206 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
209 typedef sal_uInt16 SwExtendedSubType;
210 namespace nsSwExtendedSubType
212 const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command.
213 const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible.
214 const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formatting from database.
217 enum SwInputFieldSubType {
218 INP_TXT = 0x01,
219 INP_USR = 0x02,
220 INP_VAR = 0x03
223 enum SwUserType {
224 UF_STRING = 0x01,
225 UF_EXPR = 0x02
228 enum SwDateTimeSubType {
229 FIXEDFLD = 1,
230 DATEFLD = 2,
231 TIMEFLD = 4
234 /// General tools.
235 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
237 /** Instances of SwFields and those derived from it occur 0 to n times.
238 For each class there is one instance of the associated type class.
239 Base class of all field types is SwFieldType. */
241 class SW_DLLPUBLIC SwFieldType : public sw::BroadcastingModify
243 css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
245 SwFieldIds m_nWhich;
247 friend void FinitUI(); ///< In order to delete pointer!
248 static std::vector<OUString>* s_pFieldNames;
250 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
252 protected:
253 /// Single argument ctors shall be explicit.
254 explicit SwFieldType( SwFieldIds nWhichId );
256 public:
258 SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
259 return m_wXFieldMaster;
261 SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
262 m_wXFieldMaster = xFieldMaster;
265 static OUString GetTypeStr( SwFieldTypesEnum nTypeId );
267 /// Only in derived classes.
268 virtual OUString GetName() const;
269 virtual std::unique_ptr<SwFieldType> Copy() const = 0;
270 virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
271 virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
273 SwFieldIds Which() const { return m_nWhich; }
275 void UpdateFields() const;
276 void PrintHiddenPara();
277 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
278 SwFormatField* FindFormatForField(const SwField*) const;
279 SwFormatField* FindFormatForPostItId(sal_uInt32 nPostItId) const;
280 void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
281 bool HasHiddenInformationNotes() const;
282 void GatherNodeIndex(std::vector<sal_uLong>& rvNodeIndex);
283 void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
284 void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
285 void GatherDdeTables(std::vector<SwDDETable*>& rvTables) const;
288 /** Base class of all fields.
289 Type of field is queried via Which.
290 Expanded content of field is queried via ExpandField(). */
291 class SW_DLLPUBLIC SwField
293 private:
294 mutable OUString m_Cache; ///< Cached expansion (for clipboard).
295 SwFieldType* m_pType;
296 sal_uInt32 m_nFormat; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
297 LanguageType m_nLang; ///< Always change via SetLanguage!
298 bool m_bUseFieldValueCache; /// control the usage of the cached field value
299 bool m_bIsAutomaticLanguage;
301 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
302 virtual std::unique_ptr<SwField> Copy() const = 0;
304 protected:
305 void SetFormat(sal_uInt32 const nSet) {
306 m_nFormat = nSet;
309 SwField( SwFieldType* pTyp,
310 sal_uInt32 nFormat = 0,
311 LanguageType nLang = LANGUAGE_SYSTEM,
312 bool m_bUseFieldValueCache = true );
314 public:
315 virtual ~SwField();
317 SwField(SwField const &) = default;
318 SwField(SwField &&) = default;
319 SwField & operator =(SwField const &) = default;
320 SwField & operator =(SwField &&) = default;
322 inline SwFieldType* GetTyp() const;
324 /// Set new type (used for copying among documents).
325 virtual SwFieldType* ChgTyp( SwFieldType* );
327 /** expand the field.
328 @param bCached return cached field value.
329 @remark most callers should use the cached field value.
330 this is because various fields need special handing
331 (ChangeExpansion()) to return correct values, and only
332 SwTextFormatter::NewFieldPortion() sets things up properly.
333 @param pLayout the layout to use for expansion; there are a few
334 fields that expand differently via layout mode.
335 @return the generated text (suitable for display)
337 OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
339 /// @return name or content.
340 virtual OUString GetFieldName() const;
342 std::unique_ptr<SwField> CopyField() const;
344 /// ResId
345 SwFieldIds Which() const
346 #ifdef DBG_UTIL
347 ; // implemented in fldbas.cxx
348 #else
350 return m_pType->Which();
352 #endif
354 // TYP_ID
355 SwFieldTypesEnum GetTypeId() const;
356 virtual sal_uInt16 GetSubType() const;
357 virtual void SetSubType(sal_uInt16);
359 /// Language at field position.
360 inline LanguageType GetLanguage() const;
361 virtual void SetLanguage(LanguageType nLng);
363 /// Query parameters for dialog and for BASIC.
364 inline sal_uInt32 GetFormat() const;
365 virtual OUString GetPar1() const;
366 virtual OUString GetPar2() const;
368 virtual OUString GetFormula() const;
370 void ChangeFormat(sal_uInt32 n);
371 virtual void SetPar1(const OUString& rStr);
372 virtual void SetPar2(const OUString& rStr);
374 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
375 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
377 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
378 bool HasClickHdl() const;
379 bool IsFixed() const;
381 bool IsAutomaticLanguage() const {
382 return m_bIsAutomaticLanguage;
384 void SetAutomaticLanguage(bool const bSet) {
385 m_bIsAutomaticLanguage = bSet;
388 virtual OUString GetDescription() const;
389 /// Is this field clickable?
390 bool IsClickable() const;
391 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
394 inline SwFieldType* SwField::GetTyp() const
396 return m_pType;
399 inline sal_uInt32 SwField::GetFormat() const
401 return m_nFormat;
404 inline LanguageType SwField::GetLanguage() const
406 return m_nLang;
409 /// Fields containing values that have to be formatted via number formatter.
410 class SwValueFieldType : public SwFieldType
412 private:
413 SwDoc* m_pDoc;
414 bool m_bUseFormat; ///< Use number formatter.
416 protected:
417 SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
418 SwValueFieldType( const SwValueFieldType& rTyp );
420 public:
421 SwDoc* GetDoc() const {
422 return m_pDoc;
424 void SetDoc(SwDoc* pNewDoc) {
425 m_pDoc = pNewDoc;
428 bool UseFormat() const {
429 return m_bUseFormat;
431 void EnableFormat(bool bFormat = true) {
432 m_bUseFormat = bFormat;
435 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
436 OUString DoubleToString(const double &rVal, LanguageType eLng) const;
437 OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
440 class SW_DLLPUBLIC SwValueField : public SwField
442 private:
443 double m_fValue;
445 protected:
446 SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
447 SwValueField( const SwValueField& rField );
449 public:
450 virtual ~SwValueField() override;
452 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
453 virtual void SetLanguage(LanguageType nLng) override;
455 SwDoc* GetDoc() const {
456 return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
459 virtual double GetValue() const;
460 virtual void SetValue( const double& rVal );
462 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
463 return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
466 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
467 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
470 class SW_DLLPUBLIC SwFormulaField : public SwValueField
472 private:
473 OUString m_sFormula;
475 protected:
476 SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
477 SwFormulaField( const SwFormulaField& rField );
479 public:
480 virtual OUString GetFormula() const override;
481 void SetFormula(const OUString& rStr);
483 void SetExpandedFormula(const OUString& rStr);
484 OUString GetExpandedFormula() const;
487 #endif // INCLUDED_SW_INC_FLDBAS_HXX
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */