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 "ndindex.hxx"
26 
27 #include <cppuhelper/weakref.hxx>
28 #include <editeng/svxenum.hxx>
29 #include <vector>
30 #include <climits>
31 
32 class SwDoc;
33 class SwField;
34 class SwFormatField;
35 class SwRootFrame;
36 class SvNumberFormatter;
38 class SwGetRefField;
39 namespace com::sun::star::beans { class XPropertySet; }
40 namespace com::sun::star::uno { class Any; }
41 
42 typedef struct _xmlTextWriter* xmlTextWriterPtr;
43 
44 enum class SwFieldIds : sal_uInt16 {
46  Database,
47  User,
48  Filename,
50  Date,
51  Time,
52  PageNumber,
53  Author,
54  Chapter,
55  DocStat,
56  GetExp, // 10
57  SetExp,
58  GetRef,
59  HiddenText,
60  Postit,
61  FixDate,
62  FixTime,
63  Reg,
64  VarReg,
65  SetRef,
66  Input, // 20
67  Macro,
68  Dde,
69  Table,
70  HiddenPara,
71  DocInfo,
73  DbNextSet,
74  DbNumSet,
76  ExtUser, // 30
77  RefPageSet,
78  RefPageGet,
79  Internet,
80  JumpEdit,
81  Script,
82  DateTime,
85  Dropdown,
86  ParagraphSignature, // 40
88 
89  Unknown = USHRT_MAX, // used as default value in some method calls
90 };
91 
93 enum class SwFieldTypesEnum : sal_uInt16 {
94  Begin,
95  Date = Begin, // 0
96  Time,
97  Filename,
99  Chapter,
100  PageNumber,
102  Author,
103  Set,
104  Get,
105  Formel, // 10
106  HiddenText,
107  SetRef,
108  GetRef,
109  DDE,
110  Macro,
111  Input,
113  DocumentInfo,
114  Database,
115  User, // 20
116  Postit,
117  TemplateName,
118  Sequence,
123  NextPage,
124  PreviousPage,
125  ExtendedUser, // 30
126  FixedDate,
127  FixedTime,
128  SetInput,
129  UserInput,
130  SetRefPage,
131  GetRefPage,
132  Internet,
133  JumpEdit,
134  Script,
135  Authority, // 40
137  Dropdown,
138  Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
140  LAST,
141  Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
142 };
151 };
161  FF_FIXED = 0x8000
162 };
163 
165  VVF_CMD = 0x0010,
166  VVF_INVISIBLE = 0x0040,
167  VVF_XXP = 0x0400,
168  VVF_XX_XXP = 0x0800,
169  VVF_CLEAR = 0x000f,
170 
171 // From here new formats:
172  VVF_SYS = 0x2000,
173  VVF_X = 0x2100,
174  VVF_X_X = 0x2200,
175  VVF_X_XX = 0x2300,
176  VVF_XX_X = 0x2400,
177  VVF_XX_XX = 0x2500,
178  VVF_XX_XXX = 0x2600,
179  VVF_SYS_CUR = 0x2700,
180  VVF_CUR_X = 0x2800,
181  VVF_CUR_XX_XX = 0x2900,
182  VVF_CUR_XX_X0 = 0x2a00,
183  VVF_X_CUR = 0x2b00,
184  VVF_XX_XX_CUR = 0x2c00,
185  VVF_XX_X0_CUR = 0x2d00,
186  VF_CMD = VVF_CMD,
196 
197 };
198 
199 typedef sal_uInt16 SwGetSetExpType;
201 {
202 const SwGetSetExpType GSE_STRING = 0x0001;
203 const SwGetSetExpType GSE_EXPR = 0x0002;
204 const SwGetSetExpType GSE_SEQ = 0x0008;
205 const SwGetSetExpType GSE_FORMULA = 0x0010;
206 }
207 
208 typedef sal_uInt16 SwExtendedSubType;
210 {
211 const SwExtendedSubType SUB_CMD = 0x0100;
214 }
215 
217  INP_TXT = 0x01,
218  INP_USR = 0x02,
219  INP_VAR = 0x03
220 };
221 
223  UF_STRING = 0x01,
224  UF_EXPR = 0x02
225 };
226 
228  FIXEDFLD = 1,
229  DATEFLD = 2,
231 };
232 
234 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
235 
241 {
242  css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
243 
245 
246  friend void FinitUI();
247  static std::vector<OUString>* s_pFieldNames;
248 
249  static void GetFieldName_();
250 
251 protected:
253  explicit SwFieldType( SwFieldIds nWhichId );
254 
255 public:
256 
257  SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
258  return m_wXFieldMaster;
259  }
260  SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
261  m_wXFieldMaster = xFieldMaster;
262  }
263 
264  static OUString GetTypeStr( SwFieldTypesEnum nTypeId );
265 
267  virtual OUString GetName() const;
268  virtual std::unique_ptr<SwFieldType> Copy() const = 0;
269  virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
270  virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
271 
272  SwFieldIds Which() const { return m_nWhich; }
273 
274  inline void UpdateFields() const;
275  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
276  SwFormatField* FindFormatForField(const SwField*) const;
277  SwFormatField* FindFormatForPostItId(sal_uInt32 nPostItId) const;
278  void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
279  bool HasHiddenInformationNotes() const;
280  void GatherNodeIndex(std::vector<sal_uLong>& rvNodeIndex);
281  void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
282  void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
283 };
284 
285 inline void SwFieldType::UpdateFields() const
286 {
287  const_cast<SwFieldType*>(this)->ModifyNotification( nullptr, nullptr );
288 }
289 
294 {
295 private:
296  mutable OUString m_Cache;
298  sal_uInt32 m_nFormat;
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 };
395 
397 {
398  return m_pType;
399 }
400 
401 inline sal_uInt32 SwField::GetFormat() const
402 {
403  return m_nFormat;
404 }
405 
407 {
408  return m_nLang;
409 }
410 
413 {
414 private:
417 
418 protected:
419  SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
420  SwValueFieldType( const SwValueFieldType& rTyp );
421 
422 public:
423  SwDoc* GetDoc() const {
424  return m_pDoc;
425  }
426  void SetDoc(SwDoc* pNewDoc) {
427  m_pDoc = pNewDoc;
428  }
429 
430  bool UseFormat() const {
431  return m_bUseFormat;
432  }
433  void EnableFormat(bool bFormat = true) {
434  m_bUseFormat = bFormat;
435  }
436 
437  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
438  OUString DoubleToString(const double &rVal, LanguageType eLng) const;
439  OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
440 };
441 
443 {
444 private:
445  double m_fValue;
446 
447 protected:
448  SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
449  SwValueField( const SwValueField& rField );
450 
451 public:
452  virtual ~SwValueField() override;
453 
454  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
455  virtual void SetLanguage(LanguageType nLng) override;
456 
457  SwDoc* GetDoc() const {
458  return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
459  }
460 
461  virtual double GetValue() const;
462  virtual void SetValue( const double& rVal );
463 
464  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
465  return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
466  }
467 
468  static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
469  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
470 };
471 
473 {
474 private:
475  OUString m_sFormula;
476 
477 protected:
478  SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
479  SwFormulaField( const SwFormulaField& rField );
480 
481 public:
482  virtual OUString GetFormula() const override;
483  void SetFormula(const OUString& rStr);
484 
485  void SetExpandedFormula(const OUString& rStr);
486  OUString GetExpandedFormula() const;
487 };
488 
489 #endif // INCLUDED_SW_INC_FLDBAS_HXX
490 
491 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:240
Show command.
Definition: fldbas.hxx:165
bool m_bUseFormat
Use number formatter.
Definition: fldbas.hxx:416
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:811
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:296
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:406
1234%
Definition: fldbas.hxx:167
1.234,56%
Definition: fldbas.hxx:168
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:433
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:401
std::string GetValue
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:212
1.234.5
Definition: fldbas.hxx:176
Base class of all fields.
Definition: fldbas.hxx:293
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:399
Definition: doc.hxx:184
SwVarFormat
Definition: fldbas.hxx:164
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:199
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:491
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:299
css::uno::WeakReference< css::beans::XPropertySet > m_wXFieldMaster
Definition: fldbas.hxx:242
bool m_bIsAutomaticLanguage
control the usage of the cached field value
Definition: fldbas.hxx:301
1245.56
Definition: fldbas.hxx:175
SwUserType
Definition: fldbas.hxx:222
SwDoc * GetDoc() const
Definition: fldbas.hxx:457
SAL_DLLPRIVATE css::uno::WeakReference< css::beans::XPropertySet > const & GetXObject() const
Definition: fldbas.hxx:257
struct _xmlTextWriter * xmlTextWriterPtr
Definition: fldbas.hxx:42
The root element of a Writer document layout.
Definition: rootfrm.hxx:80
For old documents the Field-Which IDs must be preserved !!!
EUR 1234.
Definition: fldbas.hxx:180
SwFieldType * m_pType
Definition: fldbas.hxx:297
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:51
void UpdateFields() const
Definition: fldbas.hxx:285
1234 EUR
Definition: fldbas.hxx:183
Compatibility:
Definition: fldbas.hxx:187
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:247
1.234.56
Definition: fldbas.hxx:177
void SetAutomaticLanguage(bool const bSet)
Definition: fldbas.hxx:386
SwInputFieldSubType
Definition: fldbas.hxx:216
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:203
virtual void ModifyNotification(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:156
1234.5
Definition: fldbas.hxx:174
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:369
struct _xmlTextWriter * xmlTextWriterPtr
SwFileNameFormat
Definition: fldbas.hxx:152
bool m_bUseFieldValueCache
Definition: fldbas.hxx:300
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:211
class SAL_NO_VTABLE XPropertySet
Invisible.
Definition: fldbas.hxx:166
sal_uInt16 SwExtendedSubType
Definition: fldbas.hxx:208
SAL_DLLPRIVATE void SetXObject(css::uno::Reference< css::beans::XPropertySet > const &xFieldMaster)
Definition: fldbas.hxx:260
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:93
SwFieldIds
Definition: fldbas.hxx:44
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang=LANGUAGE_NONE)
General tools.
Definition: fldbas.cxx:475
sal_uInt32 m_nFormat
Definition: fldbas.hxx:298
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:307
OUString m_sFormula
Definition: fldbas.hxx:475
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc * GetDoc() const
Definition: fldbas.hxx:423
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:383
SwDateTimeSubType
Definition: fldbas.hxx:227
bool UseFormat() const
Definition: fldbas.hxx:430
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
SwFieldIds m_nWhich
Definition: fldbas.hxx:244
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:412
1.234.567
Definition: fldbas.hxx:178
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:204
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:401
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:506
1234.56 EUR 1234.
Definition: fldbas.hxx:185
EUR 1234.56 EUR 1234.–.
Definition: fldbas.hxx:182
Format for numbers from system.
Definition: fldbas.hxx:172
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:254
double m_fValue
Definition: fldbas.hxx:445
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:213
1234
Definition: fldbas.hxx:173
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:205
1234.56 EUR 1234.00 EUR
Definition: fldbas.hxx:184
void SetLanguage(SwWrtShell &rWrtSh, const OUString &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:220
EUR 1234.56 EUR 1234.00.
Definition: fldbas.hxx:181
SwAttrFieldType
Definition: fldbas.hxx:143
void FinitUI()
Definition: initui.cxx:66
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:202
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:567
virtual OUString GetFormula() const
Definition: fldbas.cxx:312
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:464
Format for currency from system.
Definition: fldbas.hxx:179
SwDoc * m_pDoc
Definition: fldbas.hxx:415
SwFieldIds Which() const
Definition: fldbas.hxx:272
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:426