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 
26 #include <cppuhelper/weakref.hxx>
27 #include <editeng/svxenum.hxx>
28 #include <tools/solar.h>
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 const 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  void UpdateFields() const;
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<sal_uLong>& rvNodeIndex);
282  void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
283  void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
284 };
285 
290 {
291 private:
292  mutable OUString m_Cache;
294  sal_uInt32 m_nFormat;
298 
299  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
300  virtual std::unique_ptr<SwField> Copy() const = 0;
301 
302 protected:
303  void SetFormat(sal_uInt32 const nSet) {
304  m_nFormat = nSet;
305  }
306 
307  SwField( SwFieldType* pTyp,
308  sal_uInt32 nFormat = 0,
309  LanguageType nLang = LANGUAGE_SYSTEM,
310  bool m_bUseFieldValueCache = true );
311 
312 public:
313  virtual ~SwField();
314 
315  SwField(SwField const &) = default;
316  SwField(SwField &&) = default;
317  SwField & operator =(SwField const &) = default;
318  SwField & operator =(SwField &&) = default;
319 
320  inline SwFieldType* GetTyp() const;
321 
323  virtual SwFieldType* ChgTyp( SwFieldType* );
324 
335  OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
336 
338  virtual OUString GetFieldName() const;
339 
340  std::unique_ptr<SwField> CopyField() const;
341 
343  SwFieldIds Which() const
344 #ifdef DBG_UTIL
345  ; // implemented in fldbas.cxx
346 #else
347  {
348  return m_pType->Which();
349  }
350 #endif
351 
352  // TYP_ID
353  SwFieldTypesEnum GetTypeId() const;
354  virtual sal_uInt16 GetSubType() const;
355  virtual void SetSubType(sal_uInt16);
356 
358  inline LanguageType GetLanguage() const;
359  virtual void SetLanguage(LanguageType nLng);
360 
362  inline sal_uInt32 GetFormat() const;
363  virtual OUString GetPar1() const;
364  virtual OUString GetPar2() const;
365 
366  virtual OUString GetFormula() const;
367 
368  void ChangeFormat(sal_uInt32 n);
369  virtual void SetPar1(const OUString& rStr);
370  virtual void SetPar2(const OUString& rStr);
371 
372  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
373  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
374 
376  bool HasClickHdl() const;
377  bool IsFixed() const;
378 
379  bool IsAutomaticLanguage() const {
380  return m_bIsAutomaticLanguage;
381  }
382  void SetAutomaticLanguage(bool const bSet) {
383  m_bIsAutomaticLanguage = bSet;
384  }
385 
386  virtual OUString GetDescription() const;
388  bool IsClickable() const;
389  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
390 };
391 
393 {
394  return m_pType;
395 }
396 
397 inline sal_uInt32 SwField::GetFormat() const
398 {
399  return m_nFormat;
400 }
401 
403 {
404  return m_nLang;
405 }
406 
409 {
410 private:
413 
414 protected:
415  SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
416  SwValueFieldType( const SwValueFieldType& rTyp );
417 
418 public:
419  SwDoc* GetDoc() const {
420  return m_pDoc;
421  }
422  void SetDoc(SwDoc* pNewDoc) {
423  m_pDoc = pNewDoc;
424  }
425 
426  bool UseFormat() const {
427  return m_bUseFormat;
428  }
429  void EnableFormat(bool bFormat = true) {
430  m_bUseFormat = bFormat;
431  }
432 
433  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
434  OUString DoubleToString(const double &rVal, LanguageType eLng) const;
435  OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
436 };
437 
439 {
440 private:
441  double m_fValue;
442 
443 protected:
444  SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
445  SwValueField( const SwValueField& rField );
446 
447 public:
448  virtual ~SwValueField() override;
449 
450  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
451  virtual void SetLanguage(LanguageType nLng) override;
452 
453  SwDoc* GetDoc() const {
454  return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
455  }
456 
457  virtual double GetValue() const;
458  virtual void SetValue( const double& rVal );
459 
460  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
461  return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
462  }
463 
464  static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
465  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
466 };
467 
469 {
470 private:
471  OUString m_sFormula;
472 
473 protected:
474  SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
475  SwFormulaField( const SwFormulaField& rField );
476 
477 public:
478  virtual OUString GetFormula() const override;
479  void SetFormula(const OUString& rStr);
480 
481  void SetExpandedFormula(const OUString& rStr);
482  OUString GetExpandedFormula() const;
483 };
484 
485 #endif // INCLUDED_SW_INC_FLDBAS_HXX
486 
487 /* 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:412
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:832
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:292
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:402
1234%
Definition: fldbas.hxx:167
1.234,56%
Definition: fldbas.hxx:168
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:429
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:397
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:289
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
Definition: doc.hxx:187
SwVarFormat
Definition: fldbas.hxx:164
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:199
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:511
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:295
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:297
1245.56
Definition: fldbas.hxx:175
SwUserType
Definition: fldbas.hxx:222
SwDoc * GetDoc() const
Definition: fldbas.hxx:453
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:82
For old documents the Field-Which IDs must be preserved !!!
EUR 1234.
Definition: fldbas.hxx:180
SwFieldType * m_pType
Definition: fldbas.hxx:293
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:51
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:382
SwInputFieldSubType
Definition: fldbas.hxx:216
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:203
1234.5
Definition: fldbas.hxx:174
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:381
struct _xmlTextWriter * xmlTextWriterPtr
SwFileNameFormat
Definition: fldbas.hxx:152
bool m_bUseFieldValueCache
Definition: fldbas.hxx:296
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:495
sal_uInt32 m_nFormat
Definition: fldbas.hxx:294
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:303
OUString m_sFormula
Definition: fldbas.hxx:471
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc * GetDoc() const
Definition: fldbas.hxx:419
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:379
SwDateTimeSubType
Definition: fldbas.hxx:227
bool UseFormat() const
Definition: fldbas.hxx:426
SwFieldType * GetTyp() const
Definition: fldbas.hxx:392
SwFieldIds m_nWhich
Definition: fldbas.hxx:244
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:408
1.234.567
Definition: fldbas.hxx:178
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:204
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:421
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:526
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:441
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
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:587
void SetLanguage(SwWrtShell &rWrtSh, std::u16string_view rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:214
virtual OUString GetFormula() const
Definition: fldbas.cxx:324
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:460
Format for currency from system.
Definition: fldbas.hxx:179
SwDoc * m_pDoc
Definition: fldbas.hxx:411
SwFieldIds Which() const
Definition: fldbas.hxx:272
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:422