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 "calbck.hxx"
25 #include "nodeoffset.hxx"
26 
27 #include <com/sun/star/beans/XPropertySet.hpp>
28 #include <cppuhelper/weakref.hxx>
29 #include <editeng/svxenum.hxx>
30 #include <vector>
31 #include <climits>
32 
33 class SwDoc;
34 class SwField;
35 class SwFormatField;
36 class SwDDETable;
37 class SwRootFrame;
38 class SvNumberFormatter;
40 class SwGetRefField;
41 namespace com::sun::star::uno { class Any; }
42 
43 typedef struct _xmlTextWriter* xmlTextWriterPtr;
44 
45 enum class SwFieldIds : sal_uInt16 {
47  Database,
48  User,
49  Filename,
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,
74  DbNextSet,
75  DbNumSet,
77  ExtUser, // 30
78  RefPageSet,
79  RefPageGet,
80  Internet,
81  JumpEdit,
82  Script,
83  DateTime,
86  Dropdown,
87  ParagraphSignature, // 40
89 
90  Unknown = USHRT_MAX, // used as default value in some method calls
91 };
92 
94 enum class SwFieldTypesEnum : sal_uInt16 {
95  Begin,
96  Date = Begin, // 0
97  Time,
98  Filename,
100  Chapter,
101  PageNumber,
103  Author,
104  Set,
105  Get,
106  Formel, // 10
107  HiddenText,
108  SetRef,
109  GetRef,
110  DDE,
111  Macro,
112  Input,
114  DocumentInfo,
115  Database,
116  User, // 20
117  Postit,
118  TemplateName,
119  Sequence,
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
138  Dropdown,
139  Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
141  LAST,
142  Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
143 };
152 };
162  FF_FIXED = 0x8000
163 };
164 
166  VVF_CMD = 0x0010,
167  VVF_INVISIBLE = 0x0040,
168  VVF_XXP = 0x0400,
169  VVF_XX_XXP = 0x0800,
170  VVF_CLEAR = 0x000f,
171 
172 // From here new formats:
173  VVF_SYS = 0x2000,
174  VVF_X = 0x2100,
175  VVF_X_X = 0x2200,
176  VVF_X_XX = 0x2300,
177  VVF_XX_X = 0x2400,
178  VVF_XX_XX = 0x2500,
179  VVF_XX_XXX = 0x2600,
180  VVF_SYS_CUR = 0x2700,
181  VVF_CUR_X = 0x2800,
182  VVF_CUR_XX_XX = 0x2900,
183  VVF_CUR_XX_X0 = 0x2a00,
184  VVF_X_CUR = 0x2b00,
185  VVF_XX_XX_CUR = 0x2c00,
186  VVF_XX_X0_CUR = 0x2d00,
187  VF_CMD = VVF_CMD,
197 
198 };
199 
200 typedef sal_uInt16 SwGetSetExpType;
202 {
203 const SwGetSetExpType GSE_STRING = 0x0001;
204 const SwGetSetExpType GSE_EXPR = 0x0002;
205 const SwGetSetExpType GSE_SEQ = 0x0008;
206 const SwGetSetExpType GSE_FORMULA = 0x0010;
207 }
208 
209 typedef sal_uInt16 SwExtendedSubType;
211 {
212 const SwExtendedSubType SUB_CMD = 0x0100;
215 }
216 
218  INP_TXT = 0x01,
219  INP_USR = 0x02,
220  INP_VAR = 0x03
221 };
222 
224  UF_STRING = 0x01,
225  UF_EXPR = 0x02
226 };
227 
229  FIXEDFLD = 1,
230  DATEFLD = 2,
232 };
233 
235 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
236 
242 {
243  css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
244 
246 
247  friend void FinitUI();
248  static std::vector<OUString>* s_pFieldNames;
249 
250  static void GetFieldName_();
251 
252 protected:
254  explicit SwFieldType( SwFieldIds nWhichId );
255 
256 public:
257 
258  SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
259  return m_wXFieldMaster;
260  }
261  SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
262  m_wXFieldMaster = xFieldMaster;
263  }
264 
265  static const OUString & GetTypeStr( SwFieldTypesEnum nTypeId );
266 
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 );
272 
273  SwFieldIds Which() const { return m_nWhich; }
274 
275  void PrintHiddenPara();
276  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
277  SwFormatField* FindFormatForField(const SwField*) const;
278  SwFormatField* FindFormatForPostItId(sal_uInt32 nPostItId) const;
279  void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
280  bool HasHiddenInformationNotes() const;
281  void GatherNodeIndex(std::vector<SwNodeOffset>& rvNodeIndex);
282  void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
283  void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
284  void GatherDdeTables(std::vector<SwDDETable*>& rvTables) const;
285  virtual void UpdateFields();
286 };
287 
292 {
293 private:
294  mutable OUString m_Cache;
296  sal_uInt32 m_nFormat;
301  OUString m_aTitle;
302 
303  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
304  virtual std::unique_ptr<SwField> Copy() const = 0;
305 
306 protected:
307  void SetFormat(sal_uInt32 const nSet) {
308  m_nFormat = nSet;
309  }
310 
311  SwField( SwFieldType* pTyp,
312  sal_uInt32 nFormat = 0,
313  LanguageType nLang = LANGUAGE_SYSTEM,
314  bool m_bUseFieldValueCache = true );
315 
316 public:
317  virtual ~SwField();
318 
319  SwField(SwField const &) = default;
320  SwField(SwField &&) = default;
321  SwField & operator =(SwField const &) = default;
322  SwField & operator =(SwField &&) = default;
323 
324  inline SwFieldType* GetTyp() const;
325 
327  virtual SwFieldType* ChgTyp( SwFieldType* );
328 
339  OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
340 
342  virtual OUString GetFieldName() const;
343 
344  std::unique_ptr<SwField> CopyField() const;
345 
347  SwFieldIds Which() const
348 #ifdef DBG_UTIL
349  ; // implemented in fldbas.cxx
350 #else
351  {
352  return m_pType->Which();
353  }
354 #endif
355 
356  // TYP_ID
357  SwFieldTypesEnum GetTypeId() const;
358  virtual sal_uInt16 GetSubType() const;
359  virtual void SetSubType(sal_uInt16);
360 
362  inline LanguageType GetLanguage() const;
363  virtual void SetLanguage(LanguageType nLng);
364 
366  inline sal_uInt32 GetFormat() const;
367  virtual OUString GetPar1() const;
368  virtual OUString GetPar2() const;
369 
370  virtual OUString GetFormula() const;
371 
372  void ChangeFormat(sal_uInt32 n);
373  virtual void SetPar1(const OUString& rStr);
374  virtual void SetPar2(const OUString& rStr);
375 
376  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
377  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
378 
380  bool HasClickHdl() const;
381  bool IsFixed() const;
382 
383  bool IsAutomaticLanguage() const {
384  return m_bIsAutomaticLanguage;
385  }
386  void SetAutomaticLanguage(bool const bSet) {
387  m_bIsAutomaticLanguage = bSet;
388  }
389 
390  virtual OUString GetDescription() const;
392  bool IsClickable() const;
393  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
394  const OUString & GetTitle() const { return m_aTitle; }
395  void SetTitle(const OUString& rTitle) { m_aTitle = rTitle; }
396 };
397 
399 {
400  return m_pType;
401 }
402 
403 inline sal_uInt32 SwField::GetFormat() const
404 {
405  return m_nFormat;
406 }
407 
409 {
410  return m_nLang;
411 }
412 
415 {
416 private:
419 
420 protected:
421  SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
422  SwValueFieldType( const SwValueFieldType& rTyp );
423 
424 public:
425  SwDoc* GetDoc() const {
426  return m_pDoc;
427  }
428  void SetDoc(SwDoc* pNewDoc) {
429  m_pDoc = pNewDoc;
430  }
431 
432  bool UseFormat() const {
433  return m_bUseFormat;
434  }
435  void EnableFormat(bool bFormat = true) {
436  m_bUseFormat = bFormat;
437  }
438 
439  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
440  OUString DoubleToString(const double &rVal, LanguageType eLng) const;
441  OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
442 };
443 
445 {
446 private:
447  double m_fValue;
448 
449 protected:
450  SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
451  SwValueField( const SwValueField& rField );
452 
453 public:
454  virtual ~SwValueField() override;
455 
456  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
457  virtual void SetLanguage(LanguageType nLng) override;
458 
459  SwDoc* GetDoc() const {
460  return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
461  }
462 
463  virtual double GetValue() const;
464  virtual void SetValue( const double& rVal );
465 
466  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
467  return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
468  }
469 
470  static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
471  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
472 };
473 
475 {
476 private:
477  OUString m_sFormula;
478 
479 protected:
480  SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
481  SwFormulaField( const SwFormulaField& rField );
482 
483 public:
484  virtual OUString GetFormula() const override;
485  void SetFormula(const OUString& rStr);
486 
487  void SetExpandedFormula(const OUString& rStr);
488  OUString GetExpandedFormula() const;
489 };
490 
491 #endif // INCLUDED_SW_INC_FLDBAS_HXX
492 
493 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:241
Show command.
Definition: fldbas.hxx:166
bool m_bUseFormat
Use number formatter.
Definition: fldbas.hxx:418
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:853
void SetTitle(const OUString &rTitle)
Definition: fldbas.hxx:395
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:294
OUString m_aTitle
Used for tooltip purposes when it's not-empty.
Definition: fldbas.hxx:301
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:408
1234%
Definition: fldbas.hxx:168
1.234,56%
Definition: fldbas.hxx:169
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:435
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:403
std::string GetValue
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:213
1.234.5
Definition: fldbas.hxx:177
Base class of all fields.
Definition: fldbas.hxx:291
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
Definition: doc.hxx:187
SwVarFormat
Definition: fldbas.hxx:165
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:200
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:532
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:297
css::uno::WeakReference< css::beans::XPropertySet > m_wXFieldMaster
Definition: fldbas.hxx:243
bool m_bIsAutomaticLanguage
control the usage of the cached field value
Definition: fldbas.hxx:299
1245.56
Definition: fldbas.hxx:176
SwUserType
Definition: fldbas.hxx:223
SwDoc * GetDoc() const
Definition: fldbas.hxx:459
SAL_DLLPRIVATE css::uno::WeakReference< css::beans::XPropertySet > const & GetXObject() const
Definition: fldbas.hxx:258
struct _xmlTextWriter * xmlTextWriterPtr
Definition: fldbas.hxx:43
The root element of a Writer document layout.
Definition: rootfrm.hxx:81
For old documents the Field-Which IDs must be preserved !!!
EUR 1234.
Definition: fldbas.hxx:181
SwFieldType * m_pType
Definition: fldbas.hxx:295
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:51
1234 EUR
Definition: fldbas.hxx:184
Compatibility:
Definition: fldbas.hxx:188
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:248
1.234.56
Definition: fldbas.hxx:178
void SetAutomaticLanguage(bool const bSet)
Definition: fldbas.hxx:386
virtual OUString GetName() const override
SwInputFieldSubType
Definition: fldbas.hxx:217
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:204
1234.5
Definition: fldbas.hxx:175
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:402
const OUString & GetTitle() const
Definition: fldbas.hxx:394
SwFileNameFormat
Definition: fldbas.hxx:153
bool m_bUseFieldValueCache
Definition: fldbas.hxx:298
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:212
Invisible.
Definition: fldbas.hxx:167
sal_uInt16 SwExtendedSubType
Definition: fldbas.hxx:209
SAL_DLLPRIVATE void SetXObject(css::uno::Reference< css::beans::XPropertySet > const &xFieldMaster)
Definition: fldbas.hxx:261
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:94
SwFieldIds
Definition: fldbas.hxx:45
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang=LANGUAGE_NONE)
General tools.
Definition: fldbas.cxx:516
sal_uInt32 m_nFormat
Definition: fldbas.hxx:296
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:307
OUString m_sFormula
Definition: fldbas.hxx:477
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc * GetDoc() const
Definition: fldbas.hxx:425
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:383
SwDateTimeSubType
Definition: fldbas.hxx:228
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
bool UseFormat() const
Definition: fldbas.hxx:432
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
SwFieldIds m_nWhich
Definition: fldbas.hxx:245
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:414
1.234.567
Definition: fldbas.hxx:179
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:205
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:442
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:547
1234.56 EUR 1234.
Definition: fldbas.hxx:186
EUR 1234.56 EUR 1234.–.
Definition: fldbas.hxx:183
virtual void GetDescription(OUString &rName) override
Format for numbers from system.
Definition: fldbas.hxx:173
double m_fValue
Definition: fldbas.hxx:447
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:214
1234
Definition: fldbas.hxx:174
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:206
1234.56 EUR 1234.00 EUR
Definition: fldbas.hxx:185
EUR 1234.56 EUR 1234.00.
Definition: fldbas.hxx:182
SwAttrFieldType
Definition: fldbas.hxx:144
struct _xmlTextWriter * xmlTextWriterPtr
void FinitUI()
Definition: initui.cxx:68
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:203
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:608
void SetLanguage(SwWrtShell &rWrtSh, std::u16string_view rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:214
virtual OUString GetFormula() const
Definition: fldbas.cxx:331
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:466
Format for currency from system.
Definition: fldbas.hxx:180
SwDoc * m_pDoc
Definition: fldbas.hxx:417
SwFieldIds Which() const
Definition: fldbas.hxx:273
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:428
virtual void SetValue(tools::Long nNew) override