android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / inc / fldbas.hxx
blob4aa874c3021d9282b8fecd48c3c6b45e0ddfdcc3
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 "swtypes.hxx"
25 #include "calbck.hxx"
26 #include "nodeoffset.hxx"
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <cppuhelper/weakref.hxx>
30 #include <editeng/svxenum.hxx>
31 #include <unotools/weakref.hxx>
32 #include <rtl/ref.hxx>
33 #include <vector>
34 #include <climits>
36 class SwDoc;
37 class SwField;
38 class SwFormatField;
39 class SwDDETable;
40 class SwRootFrame;
41 class SvNumberFormatter;
42 class IDocumentRedlineAccess;
43 class SwGetRefField;
44 class SwXFieldMaster;
45 namespace com::sun::star::uno { class Any; }
47 typedef struct _xmlTextWriter* xmlTextWriterPtr;
49 enum class SwFieldIds : sal_uInt16 {
50 /// For old documents the Field-Which IDs must be preserved !!!
51 Database,
52 User,
53 Filename,
54 DatabaseName,
55 Date,
56 Time,
57 PageNumber,
58 Author,
59 Chapter,
60 DocStat,
61 GetExp, // 10
62 SetExp,
63 GetRef,
64 HiddenText,
65 Postit,
66 FixDate,
67 FixTime,
68 Reg,
69 VarReg,
70 SetRef,
71 Input, // 20
72 Macro,
73 Dde,
74 Table,
75 HiddenPara,
76 DocInfo,
77 TemplateName,
78 DbNextSet,
79 DbNumSet,
80 DbSetNumber,
81 ExtUser, // 30
82 RefPageSet,
83 RefPageGet,
84 Internet,
85 JumpEdit,
86 Script,
87 DateTime,
88 TableOfAuthorities,
89 CombinedChars,
90 Dropdown,
91 ParagraphSignature, // 40
92 LAST = ParagraphSignature,
94 Unknown = USHRT_MAX, // used as default value in some method calls
97 /// List of FieldTypes at UI.
98 enum class SwFieldTypesEnum : sal_uInt16 {
99 Begin,
100 Date = Begin, // 0
101 Time,
102 Filename,
103 DatabaseName,
104 Chapter,
105 PageNumber,
106 DocumentStatistics,
107 Author,
108 Set,
109 Get,
110 Formel, // 10
111 HiddenText,
112 SetRef,
113 GetRef,
114 DDE,
115 Macro,
116 Input,
117 HiddenParagraph,
118 DocumentInfo,
119 Database,
120 User, // 20
121 Postit,
122 TemplateName,
123 Sequence,
124 DatabaseNextSet,
125 DatabaseNumberSet,
126 DatabaseSetNumber,
127 ConditionalText,
128 NextPage,
129 PreviousPage,
130 ExtendedUser, // 30
131 FixedDate,
132 FixedTime,
133 SetInput,
134 UserInput,
135 SetRefPage,
136 GetRefPage,
137 Internet,
138 JumpEdit,
139 Script,
140 Authority, // 40
141 CombinedChars,
142 Dropdown,
143 Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
144 ParagraphSignature,
145 LAST,
146 Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
148 enum SwAttrFieldType {
149 ATTR_NONE,
150 ATTR_DATEFLD,
151 ATTR_TIMEFLD,
152 ATTR_PAGENUMBERFLD,
153 ATTR_PAGECOUNTFLD,
154 ATTR_BOOKMARKFLD,
155 ATTR_SETREFATTRFLD
157 enum SwFileNameFormat {
158 FF_BEGIN,
159 FF_NAME = FF_BEGIN,
160 FF_PATHNAME,
161 FF_PATH,
162 FF_NAME_NOEXT,
163 FF_UI_NAME,
164 FF_UI_RANGE,
165 FF_END,
166 FF_FIXED = 0x8000
169 enum SwVarFormat {
170 VVF_CMD = 0x0010, ///< Show command.
171 VVF_INVISIBLE = 0x0040, ///< Invisible.
172 VVF_XXP = 0x0400, ///< 1234%
173 VVF_XX_XXP = 0x0800, ///< 1.234,56%
174 VVF_CLEAR = 0x000f,
176 // From here new formats:
177 VVF_SYS = 0x2000, ///< Format for numbers from system.
178 VVF_X = 0x2100, ///< 1234
179 VVF_X_X = 0x2200, ///< 1234.5
180 VVF_X_XX = 0x2300, ///< 1245.56
181 VVF_XX_X = 0x2400, ///< 1.234.5
182 VVF_XX_XX = 0x2500, ///< 1.234.56
183 VVF_XX_XXX = 0x2600, ///< 1.234.567
184 VVF_SYS_CUR = 0x2700, ///< Format for currency from system.
185 VVF_CUR_X = 0x2800, ///< EUR 1234
186 VVF_CUR_XX_XX = 0x2900, ///< EUR 1234.56 EUR 1234.00
187 VVF_CUR_XX_X0 = 0x2a00, ///< EUR 1234.56 EUR 1234.--
188 VVF_X_CUR = 0x2b00, ///< 1234 EUR
189 VVF_XX_XX_CUR = 0x2c00, ///< 1234.56 EUR 1234.00 EUR
190 VVF_XX_X0_CUR = 0x2d00, ///< 1234.56 EUR 1234.-- EUR
191 /// Compatibility:
192 VF_CMD = VVF_CMD,
193 VF_INVISIBLE = VVF_INVISIBLE,
194 VF_XXP = VVF_XXP,
195 VF_XX_XXP = VVF_XX_XXP,
196 VF_VISIBLE = VVF_SYS,
197 VF_XX = VVF_X,
198 VF_XX_XX = VVF_XX_XX,
199 VF_XX_XX_CUR = VVF_SYS_CUR,
200 VF_CLEAR = VVF_CLEAR
204 typedef sal_uInt16 SwGetSetExpType;
205 namespace nsSwGetSetExpType
207 const SwGetSetExpType GSE_STRING = 0x0001; ///< String
208 const SwGetSetExpType GSE_EXPR = 0x0002; ///< Expression
209 const SwGetSetExpType GSE_SEQ = 0x0008; ///< Sequence
210 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
213 typedef sal_uInt16 SwExtendedSubType;
214 namespace nsSwExtendedSubType
216 const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command.
217 const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible.
218 const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formatting from database.
221 enum SwInputFieldSubType {
222 INP_TXT = 0x01,
223 INP_USR = 0x02,
224 INP_VAR = 0x03
227 enum SwUserType {
228 UF_STRING = 0x01,
229 UF_EXPR = 0x02
232 enum SwDateTimeSubType {
233 FIXEDFLD = 1,
234 DATEFLD = 2,
235 TIMEFLD = 4
238 /// General tools.
239 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
240 SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString);
242 /** Instances of SwFields and those derived from it occur 0 to n times.
243 For each class there is one instance of the associated type class.
244 Base class of all field types is SwFieldType. */
246 class SW_DLLPUBLIC SwFieldType : public sw::BroadcastingModify
248 unotools::WeakReference<SwXFieldMaster> m_wXFieldMaster;
250 SwFieldIds m_nWhich;
252 friend void FinitUI(); ///< In order to delete pointer!
253 static std::vector<OUString>* s_pFieldNames;
255 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
257 protected:
258 /// Single argument ctors shall be explicit.
259 explicit SwFieldType( SwFieldIds nWhichId );
261 public:
263 unotools::WeakReference<SwXFieldMaster> const& GetXObject() const {
264 return m_wXFieldMaster;
266 void SetXObject(rtl::Reference<SwXFieldMaster> const& xFieldMaster);
268 static const OUString & GetTypeStr( SwFieldTypesEnum nTypeId );
270 /// Only in derived classes.
271 virtual OUString GetName() const;
272 virtual std::unique_ptr<SwFieldType> Copy() const = 0;
273 virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
274 virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
276 SwFieldIds Which() const { return m_nWhich; }
278 void PrintHiddenPara();
279 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
280 SwFormatField* FindFormatForField(const SwField*) const;
281 SwFormatField* FindFormatForPostItId(sal_uInt32 nPostItId) const;
282 void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
283 bool HasHiddenInformationNotes() const;
284 void GatherNodeIndex(std::vector<SwNodeOffset>& rvNodeIndex);
285 void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
286 void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
287 void GatherDdeTables(std::vector<SwDDETable*>& rvTables) const;
288 void UpdateDocPos(const SwTwips nDocPos);
289 virtual void UpdateFields();
292 /** Base class of all fields.
293 Type of field is queried via Which.
294 Expanded content of field is queried via ExpandField(). */
295 class SW_DLLPUBLIC SwField
297 private:
298 mutable OUString m_Cache; ///< Cached expansion (for clipboard).
299 SwFieldType* m_pType;
300 sal_uInt32 m_nFormat; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
301 LanguageType m_nLang; ///< Always change via SetLanguage!
302 bool m_bUseFieldValueCache; /// control the usage of the cached field value
303 bool m_bIsAutomaticLanguage;
304 /// Used for tooltip purposes when it's not-empty.
305 OUString m_aTitle;
307 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
308 virtual std::unique_ptr<SwField> Copy() const = 0;
310 protected:
311 void SetFormat(sal_uInt32 const nSet) {
312 m_nFormat = nSet;
315 SwField( SwFieldType* pTyp,
316 sal_uInt32 nFormat = 0,
317 LanguageType nLang = LANGUAGE_SYSTEM,
318 bool m_bUseFieldValueCache = true );
320 public:
321 virtual ~SwField();
323 SwField(SwField const &) = default;
324 SwField(SwField &&) = default;
325 SwField & operator =(SwField const &) = default;
326 SwField & operator =(SwField &&) = default;
328 inline SwFieldType* GetTyp() const;
330 /// Set new type (used for copying among documents).
331 virtual SwFieldType* ChgTyp( SwFieldType* );
333 /** expand the field.
334 @param bCached return cached field value.
335 @remark most callers should use the cached field value.
336 this is because various fields need special handing
337 (ChangeExpansion()) to return correct values, and only
338 SwTextFormatter::NewFieldPortion() sets things up properly.
339 @param pLayout the layout to use for expansion; there are a few
340 fields that expand differently via layout mode.
341 @return the generated text (suitable for display)
343 OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
345 /// @return name or content.
346 virtual OUString GetFieldName() const;
348 std::unique_ptr<SwField> CopyField() const;
350 /// ResId
351 SwFieldIds Which() const
352 #ifdef DBG_UTIL
353 ; // implemented in fldbas.cxx
354 #else
356 return m_pType->Which();
358 #endif
360 // TYP_ID
361 SwFieldTypesEnum GetTypeId() const;
362 virtual sal_uInt16 GetSubType() const;
363 virtual void SetSubType(sal_uInt16);
365 /// Language at field position.
366 inline LanguageType GetLanguage() const;
367 virtual void SetLanguage(LanguageType nLng);
369 /// Query parameters for dialog and for BASIC.
370 inline sal_uInt32 GetFormat() const;
371 virtual OUString GetPar1() const;
372 virtual OUString GetPar2() const;
374 virtual OUString GetFormula() const;
376 void ChangeFormat(sal_uInt32 n);
377 virtual void SetPar1(const OUString& rStr);
378 virtual void SetPar2(const OUString& rStr);
380 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
381 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
383 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
384 bool HasClickHdl() const;
385 bool IsFixed() const;
387 bool IsAutomaticLanguage() const {
388 return m_bIsAutomaticLanguage;
390 void SetAutomaticLanguage(bool const bSet) {
391 m_bIsAutomaticLanguage = bSet;
394 virtual OUString GetDescription() const;
395 /// Is this field clickable?
396 bool IsClickable() const;
397 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
398 const OUString & GetTitle() const { return m_aTitle; }
399 void SetTitle(const OUString& rTitle) { m_aTitle = rTitle; }
402 inline SwFieldType* SwField::GetTyp() const
404 return m_pType;
407 inline sal_uInt32 SwField::GetFormat() const
409 return m_nFormat;
412 inline LanguageType SwField::GetLanguage() const
414 return m_nLang;
417 /// Fields containing values that have to be formatted via number formatter.
418 class SwValueFieldType : public SwFieldType
420 private:
421 SwDoc* m_pDoc;
422 bool m_bUseFormat; ///< Use number formatter.
424 protected:
425 SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
426 SwValueFieldType( const SwValueFieldType& rTyp );
428 public:
429 SwDoc* GetDoc() const {
430 return m_pDoc;
432 void SetDoc(SwDoc* pNewDoc) {
433 m_pDoc = pNewDoc;
436 bool UseFormat() const {
437 return m_bUseFormat;
439 void EnableFormat(bool bFormat = true) {
440 m_bUseFormat = bFormat;
443 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
444 OUString DoubleToString(const double &rVal, LanguageType eLng) const;
445 OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
446 /// Query input or formatted value for dialog.
447 OUString GetInputOrDateTime( const OUString& rInput, const double& rVal, sal_uInt32 nFormat ) const;
450 class SW_DLLPUBLIC SwValueField : public SwField
452 private:
453 double m_fValue;
455 protected:
456 SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
457 SwValueField( const SwValueField& rField );
459 public:
460 virtual ~SwValueField() override;
462 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
463 virtual void SetLanguage(LanguageType nLng) override;
465 SwDoc* GetDoc() const {
466 return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
469 virtual double GetValue() const;
470 virtual void SetValue( const double& rVal );
472 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
473 return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
476 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
477 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
480 class SW_DLLPUBLIC SwFormulaField : public SwValueField
482 private:
483 OUString m_sFormula;
485 protected:
486 SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
487 SwFormulaField( const SwFormulaField& rField );
489 public:
490 virtual OUString GetFormula() const override;
491 void SetFormula(const OUString& rStr);
493 void SetExpandedFormula(const OUString& rStr);
494 OUString GetExpandedFormula() const;
496 /// Query formula or formatted value for dialog.
497 OUString GetInputOrDateTime() const;
500 #endif // INCLUDED_SW_INC_FLDBAS_HXX
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */