LibreOffice Module sw (master) 1
fldbas.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SW_INC_FLDBAS_HXX
20#define INCLUDED_SW_INC_FLDBAS_HXX
21
22#include <i18nlangtag/lang.h>
23#include "swdllapi.h"
24#include "swtypes.hxx"
25#include "calbck.hxx"
26#include "nodeoffset.hxx"
27
28#include <com/sun/star/beans/XPropertySet.hpp>
30#include <editeng/svxenum.hxx>
31#include <unotools/weakref.hxx>
32#include <rtl/ref.hxx>
33#include <vector>
34#include <climits>
35
36class SwDoc;
37class SwField;
38class SwFormatField;
39class SwDDETable;
40class SwRootFrame;
43class SwGetRefField;
44class SwXFieldMaster;
45namespace com::sun::star::uno { class Any; }
46
47typedef struct _xmlTextWriter* xmlTextWriterPtr;
48
49enum class SwFieldIds : sal_uInt16 {
52 User,
55 Date,
56 Time,
58 Author,
59 Chapter,
60 DocStat,
61 GetExp, // 10
62 SetExp,
63 GetRef,
65 Postit,
66 FixDate,
67 FixTime,
68 Reg,
69 VarReg,
70 SetRef,
71 Input, // 20
72 Macro,
73 Dde,
74 Table,
76 DocInfo,
81 ExtUser, // 30
86 Script,
93
94 Unknown = USHRT_MAX, // used as default value in some method calls
95};
96
98enum class SwFieldTypesEnum : sal_uInt16 {
99 Begin,
100 Date = Begin, // 0
101 Time,
102 Filename,
104 Chapter,
107 Author,
108 Set,
109 Get,
110 Formel, // 10
112 SetRef,
113 GetRef,
114 DDE,
115 Macro,
116 Input,
119 Database,
120 User, // 20
121 Postit,
123 Sequence,
128 NextPage,
130 ExtendedUser, // 30
131 FixedDate,
132 FixedTime,
133 SetInput,
134 UserInput,
137 Internet,
138 JumpEdit,
139 Script,
140 Authority, // 40
142 Dropdown,
143 Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
145 LAST,
146 Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
147};
166 FF_FIXED = 0x8000
168
170 VVF_CMD = 0x0010,
171 VVF_INVISIBLE = 0x0040,
172 VVF_XXP = 0x0400,
173 VVF_XX_XXP = 0x0800,
174 VVF_CLEAR = 0x000f,
175
176// From here new formats:
177 VVF_SYS = 0x2000,
178 VVF_X = 0x2100,
179 VVF_X_X = 0x2200,
180 VVF_X_XX = 0x2300,
181 VVF_XX_X = 0x2400,
182 VVF_XX_XX = 0x2500,
183 VVF_XX_XXX = 0x2600,
184 VVF_SYS_CUR = 0x2700,
185 VVF_CUR_X = 0x2800,
186 VVF_CUR_XX_XX = 0x2900,
187 VVF_CUR_XX_X0 = 0x2a00,
188 VVF_X_CUR = 0x2b00,
189 VVF_XX_XX_CUR = 0x2c00,
190 VVF_XX_X0_CUR = 0x2d00,
201
203
204typedef sal_uInt16 SwGetSetExpType;
206{
208const SwGetSetExpType GSE_EXPR = 0x0002;
209const SwGetSetExpType GSE_SEQ = 0x0008;
211}
212
213typedef sal_uInt16 SwExtendedSubType;
215{
219}
220
222 INP_TXT = 0x01,
223 INP_USR = 0x02,
224 INP_VAR = 0x03
226
228 UF_STRING = 0x01,
229 UF_EXPR = 0x02
231
235 TIMEFLD = 4
237
239OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
240SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString);
241
246class SW_DLLPUBLIC SwFieldType : public sw::BroadcastingModify
247{
249
251
252 friend void FinitUI();
253 static std::vector<OUString>* s_pFieldNames;
254
255 static void GetFieldName_();
256
257protected:
259 explicit SwFieldType( SwFieldIds nWhichId );
260
261public:
262
264 return m_wXFieldMaster;
265 }
266 void SetXObject(rtl::Reference<SwXFieldMaster> const& xFieldMaster);
267
268 static const OUString & GetTypeStr( SwFieldTypesEnum nTypeId );
269
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 );
275
276 SwFieldIds Which() const { return m_nWhich; }
277
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();
290};
291
296{
297private:
298 mutable OUString m_Cache;
300 sal_uInt32 m_nFormat;
305 OUString m_aTitle;
306
307 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
308 virtual std::unique_ptr<SwField> Copy() const = 0;
309
310protected:
311 void SetFormat(sal_uInt32 const nSet) {
312 m_nFormat = nSet;
313 }
314
315 SwField( SwFieldType* pTyp,
316 sal_uInt32 nFormat = 0,
317 LanguageType nLang = LANGUAGE_SYSTEM,
318 bool m_bUseFieldValueCache = true );
319
320public:
321 virtual ~SwField();
322
323 SwField(SwField const &) = default;
324 SwField(SwField &&) = default;
325 SwField & operator =(SwField const &) = default;
326 SwField & operator =(SwField &&) = default;
327
328 inline SwFieldType* GetTyp() const;
329
331 virtual SwFieldType* ChgTyp( SwFieldType* );
332
343 OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
344
346 virtual OUString GetFieldName() const;
347
348 std::unique_ptr<SwField> CopyField() const;
349
351 SwFieldIds Which() const
352#ifdef DBG_UTIL
353 ; // implemented in fldbas.cxx
354#else
355 {
356 return m_pType->Which();
357 }
358#endif
359
360 // TYP_ID
361 SwFieldTypesEnum GetTypeId() const;
362 virtual sal_uInt16 GetSubType() const;
363 virtual void SetSubType(sal_uInt16);
364
366 inline LanguageType GetLanguage() const;
367 virtual void SetLanguage(LanguageType nLng);
368
370 inline sal_uInt32 GetFormat() const;
371 virtual OUString GetPar1() const;
372 virtual OUString GetPar2() const;
373
374 virtual OUString GetFormula() const;
375
376 void ChangeFormat(sal_uInt32 n);
377 virtual void SetPar1(const OUString& rStr);
378 virtual void SetPar2(const OUString& rStr);
379
380 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
381 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
382
384 bool HasClickHdl() const;
385 bool IsFixed() const;
386
387 bool IsAutomaticLanguage() const {
388 return m_bIsAutomaticLanguage;
389 }
390 void SetAutomaticLanguage(bool const bSet) {
391 m_bIsAutomaticLanguage = bSet;
392 }
393
394 virtual OUString GetDescription() const;
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; }
400};
401
403{
404 return m_pType;
405}
406
407inline sal_uInt32 SwField::GetFormat() const
408{
409 return m_nFormat;
410}
411
413{
414 return m_nLang;
415}
416
419{
420private:
423
424protected:
425 SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
426 SwValueFieldType( const SwValueFieldType& rTyp );
427
428public:
429 SwDoc* GetDoc() const {
430 return m_pDoc;
431 }
432 void SetDoc(SwDoc* pNewDoc) {
433 m_pDoc = pNewDoc;
434 }
435
436 bool UseFormat() const {
437 return m_bUseFormat;
438 }
439 void EnableFormat(bool bFormat = true) {
440 m_bUseFormat = bFormat;
441 }
442
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;
447 OUString GetInputOrDateTime( const OUString& rInput, const double& rVal, sal_uInt32 nFormat ) const;
448};
449
451{
452private:
453 double m_fValue;
454
455protected:
456 SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
457 SwValueField( const SwValueField& rField );
458
459public:
460 virtual ~SwValueField() override;
461
462 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
463 virtual void SetLanguage(LanguageType nLng) override;
464
465 SwDoc* GetDoc() const {
466 return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
467 }
468
469 virtual double GetValue() const;
470 virtual void SetValue( const double& rVal );
471
472 OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
473 return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
474 }
475
476 static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
477 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
478};
479
481{
482private:
483 OUString m_sFormula;
484
485protected:
486 SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
487 SwFormulaField( const SwFormulaField& rField );
488
489public:
490 virtual OUString GetFormula() const override;
491 void SetFormula(const OUString& rStr);
492
493 void SetExpandedFormula(const OUString& rStr);
494 OUString GetExpandedFormula() const;
495
497 OUString GetInputOrDateTime() const;
498};
499
500#endif // INCLUDED_SW_INC_FLDBAS_HXX
501
502/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOUser User
Definition: doc.hxx:197
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
SwFieldIds Which() const
Definition: fldbas.hxx:276
unotools::WeakReference< SwXFieldMaster > const & GetXObject() const
Definition: fldbas.hxx:263
SwFieldIds m_nWhich
Definition: fldbas.hxx:250
virtual std::unique_ptr< SwFieldType > Copy() const =0
unotools::WeakReference< SwXFieldMaster > m_wXFieldMaster
Definition: fldbas.hxx:248
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:253
Base class of all fields.
Definition: fldbas.hxx:296
SwFieldType * m_pType
Definition: fldbas.hxx:299
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:387
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:298
OUString m_aTitle
Used for tooltip purposes when it's not-empty.
Definition: fldbas.hxx:305
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:311
sal_uInt32 m_nFormat
Definition: fldbas.hxx:300
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:301
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:407
SwField(SwField &&)=default
bool m_bIsAutomaticLanguage
control the usage of the cached field value
Definition: fldbas.hxx:303
void SetTitle(const OUString &rTitle)
Definition: fldbas.hxx:399
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:412
virtual std::unique_ptr< SwField > Copy() const =0
void SetAutomaticLanguage(bool const bSet)
Definition: fldbas.hxx:390
bool m_bUseFieldValueCache
Definition: fldbas.hxx:302
const OUString & GetTitle() const
Definition: fldbas.hxx:398
SwField(SwField const &)=default
OUString m_sFormula
Definition: fldbas.hxx:483
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:419
bool UseFormat() const
Definition: fldbas.hxx:436
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:585
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:570
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:432
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:646
SwDoc * m_pDoc
Definition: fldbas.hxx:421
SwDoc * GetDoc() const
Definition: fldbas.hxx:429
OUString GetInputOrDateTime(const OUString &rInput, const double &rVal, sal_uInt32 nFormat) const
Query input or formatted value for dialog.
Definition: fldbas.cxx:660
bool m_bUseFormat
Use number formatter.
Definition: fldbas.hxx:422
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:439
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:472
SwDoc * GetDoc() const
Definition: fldbas.hxx:465
double m_fValue
Definition: fldbas.hxx:453
struct _xmlTextWriter * xmlTextWriterPtr
virtual OUString GetName() const override
virtual void GetDescription(OUString &rName) override
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
virtual void SetValue(tools::Long nNew) override
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:98
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang=LANGUAGE_NONE)
General tools.
Definition: fldbas.cxx:523
SwAttrFieldType
Definition: fldbas.hxx:148
@ ATTR_PAGENUMBERFLD
Definition: fldbas.hxx:152
@ ATTR_DATEFLD
Definition: fldbas.hxx:150
@ ATTR_BOOKMARKFLD
Definition: fldbas.hxx:154
@ ATTR_NONE
Definition: fldbas.hxx:149
@ ATTR_SETREFATTRFLD
Definition: fldbas.hxx:155
@ ATTR_PAGECOUNTFLD
Definition: fldbas.hxx:153
@ ATTR_TIMEFLD
Definition: fldbas.hxx:151
SwUserType
Definition: fldbas.hxx:227
@ UF_STRING
Definition: fldbas.hxx:228
@ UF_EXPR
Definition: fldbas.hxx:229
SwFileNameFormat
Definition: fldbas.hxx:157
@ FF_UI_RANGE
Definition: fldbas.hxx:164
@ FF_UI_NAME
Definition: fldbas.hxx:163
@ FF_FIXED
Definition: fldbas.hxx:166
@ FF_NAME_NOEXT
Definition: fldbas.hxx:162
@ FF_BEGIN
Definition: fldbas.hxx:158
@ FF_PATH
Definition: fldbas.hxx:161
@ FF_END
Definition: fldbas.hxx:165
@ FF_NAME
Definition: fldbas.hxx:159
@ FF_PATHNAME
Definition: fldbas.hxx:160
SwDateTimeSubType
Definition: fldbas.hxx:232
@ FIXEDFLD
Definition: fldbas.hxx:233
@ DATEFLD
Definition: fldbas.hxx:234
@ TIMEFLD
Definition: fldbas.hxx:235
sal_uInt16 SwExtendedSubType
Definition: fldbas.hxx:213
struct _xmlTextWriter * xmlTextWriterPtr
Definition: fldbas.hxx:47
SwVarFormat
Definition: fldbas.hxx:169
@ VVF_XX_XXX
1.234.567
Definition: fldbas.hxx:183
@ VVF_CUR_XX_X0
EUR 1234.56 EUR 1234.–.
Definition: fldbas.hxx:187
@ VVF_XX_X0_CUR
1234.56 EUR 1234.
Definition: fldbas.hxx:190
@ VF_XX_XX
Definition: fldbas.hxx:198
@ VF_CMD
Compatibility:
Definition: fldbas.hxx:192
@ VVF_XX_XX
1.234.56
Definition: fldbas.hxx:182
@ VVF_CMD
Show command.
Definition: fldbas.hxx:170
@ VF_CLEAR
Definition: fldbas.hxx:200
@ VVF_SYS_CUR
Format for currency from system.
Definition: fldbas.hxx:184
@ VF_XXP
Definition: fldbas.hxx:194
@ VVF_X
1234
Definition: fldbas.hxx:178
@ VVF_INVISIBLE
Invisible.
Definition: fldbas.hxx:171
@ VVF_X_CUR
1234 EUR
Definition: fldbas.hxx:188
@ VVF_SYS
Format for numbers from system.
Definition: fldbas.hxx:177
@ VF_XX_XX_CUR
Definition: fldbas.hxx:199
@ VF_XX
Definition: fldbas.hxx:197
@ VVF_CUR_X
EUR 1234.
Definition: fldbas.hxx:185
@ VVF_X_XX
1245.56
Definition: fldbas.hxx:180
@ VVF_XX_XX_CUR
1234.56 EUR 1234.00 EUR
Definition: fldbas.hxx:189
@ VF_INVISIBLE
Definition: fldbas.hxx:193
@ VVF_CLEAR
Definition: fldbas.hxx:174
@ VVF_CUR_XX_XX
EUR 1234.56 EUR 1234.00.
Definition: fldbas.hxx:186
@ VF_XX_XXP
Definition: fldbas.hxx:195
@ VVF_X_X
1234.5
Definition: fldbas.hxx:179
@ VF_VISIBLE
Definition: fldbas.hxx:196
@ VVF_XX_XXP
1.234,56%
Definition: fldbas.hxx:173
@ VVF_XXP
1234%
Definition: fldbas.hxx:172
@ VVF_XX_X
1.234.5
Definition: fldbas.hxx:181
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:204
SwInputFieldSubType
Definition: fldbas.hxx:221
@ INP_VAR
Definition: fldbas.hxx:224
@ INP_USR
Definition: fldbas.hxx:223
@ INP_TXT
Definition: fldbas.hxx:222
SwFieldIds
Definition: fldbas.hxx:49
@ ParagraphSignature
@ TableOfAuthorities
SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString)
Definition: fldbas.cxx:539
void FinitUI()
Definition: initui.cxx:68
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
def Input(s)
void SetLanguage(SwWrtShell &rWrtSh, std::u16string_view rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:192
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:365
@ Sequence
Unknown
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:216
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:217
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:218
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:209
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:208
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:210
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:207
sal_uInt16 const m_nFormat
const char GetValue[]
static LanguageType nLang
Definition: srtdlg.cxx:51
SvxNumType
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
tools::Long SwTwips
Definition: swtypes.hxx:51