lok: Hide file linking in section
[LibreOffice.git] / sw / inc / fldbas.hxx
blob664f74b45242b8053369d5639492b893f936b4a9
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 <cppuhelper/weakref.hxx>
26 #include <editeng/svxenum.hxx>
27 #include <vector>
28 #include <climits>
30 class SwDoc;
31 class SwRootFrame;
32 class SvNumberFormatter;
33 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
34 namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
36 typedef struct _xmlTextWriter* xmlTextWriterPtr;
38 enum class SwFieldIds : sal_uInt16 {
39 /// For old documents the Field-Which IDs must be preserved !!!
40 Database,
41 User,
42 Filename,
43 DatabaseName,
44 Date,
45 Time,
46 PageNumber,
47 Author,
48 Chapter,
49 DocStat,
50 GetExp, // 10
51 SetExp,
52 GetRef,
53 HiddenText,
54 Postit,
55 FixDate,
56 FixTime,
57 Reg,
58 VarReg,
59 SetRef,
60 Input, // 20
61 Macro,
62 Dde,
63 Table,
64 HiddenPara,
65 DocInfo,
66 TemplateName,
67 DbNextSet,
68 DbNumSet,
69 DbSetNumber,
70 ExtUser, // 30
71 RefPageSet,
72 RefPageGet,
73 Internet,
74 JumpEdit,
75 Script,
76 DateTime,
77 TableOfAuthorities,
78 CombinedChars,
79 Dropdown,
80 ParagraphSignature, // 40
81 LAST = ParagraphSignature,
83 Unknown = USHRT_MAX, // used as default value in some method calls
86 /// List of FieldTypes at UI.
87 enum class SwFieldTypesEnum : sal_uInt16 {
88 Begin,
89 Date = Begin, // 0
90 Time,
91 Filename,
92 DatabaseName,
93 Chapter,
94 PageNumber,
95 DocumentStatistics,
96 Author,
97 Set,
98 Get,
99 Formel, // 10
100 HiddenText,
101 SetRef,
102 GetRef,
103 DDE,
104 Macro,
105 Input,
106 HiddenParagraph,
107 DocumentInfo,
108 Database,
109 User, // 20
110 Postit,
111 TemplateName,
112 Sequence,
113 DatabaseNextSet,
114 DatabaseNumberSet,
115 DatabaseSetNumber,
116 ConditionalText,
117 NextPage,
118 PreviousPage,
119 ExtendedUser, // 30
120 FixedDate,
121 FixedTime,
122 SetInput,
123 UserInput,
124 SetRefPage,
125 GetRefPage,
126 Internet,
127 JumpEdit,
128 Script,
129 Authority, // 40
130 CombinedChars,
131 Dropdown,
132 Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
133 ParagraphSignature,
134 LAST,
135 Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
137 enum SwAttrFieldType {
138 ATTR_NONE,
139 ATTR_DATEFLD,
140 ATTR_TIMEFLD,
141 ATTR_PAGENUMBERFLD,
142 ATTR_PAGECOOUNTFLD,
143 ATTR_BOOKMARKFLD,
144 ATTR_SETREFATTRFLD
146 enum SwFileNameFormat {
147 FF_BEGIN,
148 FF_NAME = FF_BEGIN,
149 FF_PATHNAME,
150 FF_PATH,
151 FF_NAME_NOEXT,
152 FF_UI_NAME,
153 FF_UI_RANGE,
154 FF_END,
155 FF_FIXED = 0x8000
158 enum SwVarFormat {
159 VVF_CMD = 0x0010, ///< Show command.
160 VVF_INVISIBLE = 0x0040, ///< Invisible.
161 VVF_XXP = 0x0400, ///< 1234%
162 VVF_XX_XXP = 0x0800, ///< 1.234,56%
163 VVF_CLEAR = 0x000f,
165 // From here new formats:
166 VVF_SYS = 0x2000, ///< Format for numbers from system.
167 VVF_X = 0x2100, ///< 1234
168 VVF_X_X = 0x2200, ///< 1234.5
169 VVF_X_XX = 0x2300, ///< 1245.56
170 VVF_XX_X = 0x2400, ///< 1.234.5
171 VVF_XX_XX = 0x2500, ///< 1.234.56
172 VVF_XX_XXX = 0x2600, ///< 1.234.567
173 VVF_SYS_CUR = 0x2700, ///< Format for currency from system.
174 VVF_CUR_X = 0x2800, ///< EUR 1234
175 VVF_CUR_XX_XX = 0x2900, ///< EUR 1234.56 EUR 1234.00
176 VVF_CUR_XX_X0 = 0x2a00, ///< EUR 1234.56 EUR 1234.--
177 VVF_X_CUR = 0x2b00, ///< 1234 EUR
178 VVF_XX_XX_CUR = 0x2c00, ///< 1234.56 EUR 1234.00 EUR
179 VVF_XX_X0_CUR = 0x2d00, ///< 1234.56 EUR 1234.-- EUR
180 /// Compatibility:
181 VF_CMD = VVF_CMD,
182 VF_INVISIBLE = VVF_INVISIBLE,
183 VF_XXP = VVF_XXP,
184 VF_XX_XXP = VVF_XX_XXP,
185 VF_VISIBLE = VVF_SYS,
186 VF_XX = VVF_X,
187 VF_XX_XX = VVF_XX_XX,
188 VF_XX_XX_CUR = VVF_SYS_CUR,
189 VF_CLEAR = VVF_CLEAR
193 typedef sal_uInt16 SwGetSetExpType;
194 namespace nsSwGetSetExpType
196 const SwGetSetExpType GSE_STRING = 0x0001; ///< String
197 const SwGetSetExpType GSE_EXPR = 0x0002; ///< Expression
198 const SwGetSetExpType GSE_SEQ = 0x0008; ///< Sequence
199 const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
202 typedef sal_uInt16 SwExtendedSubType;
203 namespace nsSwExtendedSubType
205 const SwExtendedSubType SUB_CMD = 0x0100; ///< Show command.
206 const SwExtendedSubType SUB_INVISIBLE = 0x0200; ///< Invisible.
207 const SwExtendedSubType SUB_OWN_FMT = 0x0400; ///< SwDBField: Don't accept formatting from database.
210 enum SwInputFieldSubType {
211 INP_TXT = 0x01,
212 INP_USR = 0x02,
213 INP_VAR = 0x03
216 enum SwUserType {
217 UF_STRING = 0x01,
218 UF_EXPR = 0x02
221 enum SwDateTimeSubType {
222 FIXEDFLD = 1,
223 DATEFLD = 2,
224 TIMEFLD = 4
227 /// General tools.
228 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
230 /** Instances of SwFields and those derived from it occur 0 to n times.
231 For each class there is one instance of the associated type class.
232 Base class of all field types is SwFieldType. */
234 class SW_DLLPUBLIC SwFieldType : public SwModify, public sw::BroadcasterMixin
236 css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
238 SwFieldIds const m_nWhich;
240 friend void FinitUI(); ///< In order to delete pointer!
241 static std::vector<OUString>* s_pFieldNames;
243 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
245 protected:
246 /// Single argument ctors shall be explicit.
247 explicit SwFieldType( SwFieldIds nWhichId );
249 public:
251 SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
252 return m_wXFieldMaster;
254 SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
255 m_wXFieldMaster = xFieldMaster;
258 static OUString GetTypeStr( SwFieldTypesEnum nTypeId );
260 /// Only in derived classes.
261 virtual OUString GetName() const;
262 virtual std::unique_ptr<SwFieldType> Copy() const = 0;
263 virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
264 virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
266 SwFieldIds Which() const { return m_nWhich; }
268 inline void UpdateFields() const;
269 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
272 inline void SwFieldType::UpdateFields() const
274 const_cast<SwFieldType*>(this)->ModifyNotification( nullptr, nullptr );
277 /** Base class of all fields.
278 Type of field is queried via Which.
279 Expanded content of field is queried via ExpandField(). */
280 class SW_DLLPUBLIC SwField
282 private:
283 mutable OUString m_Cache; ///< Cached expansion (for clipboard).
284 bool m_bUseFieldValueCache; /// control the usage of the cached field value
285 LanguageType m_nLang; ///< Always change via SetLanguage!
286 bool m_bIsAutomaticLanguage;
287 sal_uInt32 m_nFormat; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
288 SwFieldType* m_pType;
290 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
291 virtual std::unique_ptr<SwField> Copy() const = 0;
293 protected:
294 void SetFormat(sal_uInt32 const nSet) {
295 m_nFormat = nSet;
298 SwField( SwFieldType* pTyp,
299 sal_uInt32 nFormat = 0,
300 LanguageType nLang = LANGUAGE_SYSTEM,
301 bool m_bUseFieldValueCache = true );
303 public:
304 virtual ~SwField();
306 SwField(SwField const &) = default;
307 SwField(SwField &&) = default;
308 SwField & operator =(SwField const &) = default;
309 SwField & operator =(SwField &&) = default;
311 inline SwFieldType* GetTyp() const;
313 /// Set new type (used for copying among documents).
314 virtual SwFieldType* ChgTyp( SwFieldType* );
316 /** expand the field.
317 @param bCached return cached field value.
318 @remark most callers should use the cached field value.
319 this is because various fields need special handing
320 (ChangeExpansion()) to return correct values, and only
321 SwTextFormatter::NewFieldPortion() sets things up properly.
322 @param pLayout the layout to use for expansion; there are a few
323 fields that expand differently via layout mode.
324 @return the generated text (suitable for display)
326 OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
328 /// @return name or content.
329 virtual OUString GetFieldName() const;
331 std::unique_ptr<SwField> CopyField() const;
333 /// ResId
334 SwFieldIds Which() const
335 #ifdef DBG_UTIL
336 ; // implemented in fldbas.cxx
337 #else
339 return m_pType->Which();
341 #endif
343 // TYP_ID
344 SwFieldTypesEnum GetTypeId() const;
345 virtual sal_uInt16 GetSubType() const;
346 virtual void SetSubType(sal_uInt16);
348 /// Language at field position.
349 inline LanguageType GetLanguage() const;
350 virtual void SetLanguage(LanguageType nLng);
352 /// Query parameters for dialog and for BASIC.
353 inline sal_uInt32 GetFormat() const;
354 virtual OUString GetPar1() const;
355 virtual OUString GetPar2() const;
357 virtual OUString GetFormula() const;
359 void ChangeFormat(sal_uInt32 n);
360 virtual void SetPar1(const OUString& rStr);
361 virtual void SetPar2(const OUString& rStr);
363 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
364 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
366 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
367 bool HasClickHdl() const;
368 bool IsFixed() const;
370 bool IsAutomaticLanguage() const {
371 return m_bIsAutomaticLanguage;
373 void SetAutomaticLanguage(bool const bSet) {
374 m_bIsAutomaticLanguage = bSet;
377 virtual OUString GetDescription() const;
378 /// Is this field clickable?
379 bool IsClickable() const;
380 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
383 inline SwFieldType* SwField::GetTyp() const
385 return m_pType;
388 inline sal_uInt32 SwField::GetFormat() const
390 return m_nFormat;
393 inline LanguageType SwField::GetLanguage() const
395 return m_nLang;
398 /// Fields containing values that have to be formatted via number formatter.
399 class SwValueFieldType : public SwFieldType
401 private:
402 SwDoc* m_pDoc;
403 bool m_bUseFormat; ///< Use number formatter.
405 protected:
406 SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
407 SwValueFieldType( const SwValueFieldType& rTyp );
409 public:
410 SwDoc* GetDoc() const {
411 return m_pDoc;
413 void SetDoc(SwDoc* pNewDoc) {
414 m_pDoc = pNewDoc;
417 bool UseFormat() const {
418 return m_bUseFormat;
420 void EnableFormat(bool bFormat = true) {
421 m_bUseFormat = bFormat;
424 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
425 OUString DoubleToString(const double &rVal, LanguageType eLng) const;
426 OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
429 class SW_DLLPUBLIC SwValueField : public SwField
431 private:
432 double m_fValue;
434 protected:
435 SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
436 SwValueField( const SwValueField& rField );
438 public:
439 virtual ~SwValueField() override;
441 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
442 virtual void SetLanguage(LanguageType nLng) override;
444 SwDoc* GetDoc() const {
445 return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
448 virtual double GetValue() const;
449 virtual void SetValue( const double& rVal );
451 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
452 return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
455 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
456 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
459 class SW_DLLPUBLIC SwFormulaField : public SwValueField
461 private:
462 OUString m_sFormula;
464 protected:
465 SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
466 SwFormulaField( const SwFormulaField& rField );
468 public:
469 virtual OUString GetFormula() const override;
470 void SetFormula(const OUString& rStr);
472 void SetExpandedFormula(const OUString& rStr);
473 OUString GetExpandedFormula() const;
476 #endif // INCLUDED_SW_INC_FLDBAS_HXX
478 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */