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 <cppuhelper/weakref.hxx>
28 #include <editeng/svxenum.hxx>
29 #include <tools/solar.h>
30 #include <vector>
31 #include <climits>
32 
33 class SwDoc;
34 class SwField;
35 class SwFormatField;
36 class SwRootFrame;
37 class SvNumberFormatter;
39 class SwGetRefField;
40 namespace com::sun::star::beans { class XPropertySet; }
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 UpdateFields() const;
276  void PrintHiddenPara();
277  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
278  SwFormatField* FindFormatForField(const SwField*) const;
279  SwFormatField* FindFormatForPostItId(sal_uInt32 nPostItId) const;
280  void CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, bool HideRedlines);
281  bool HasHiddenInformationNotes() const;
282  void GatherNodeIndex(std::vector<SwNodeOffset>& rvNodeIndex);
283  void GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp);
284  void GatherFields(std::vector<SwFormatField*>& rvFormatFields, bool bCollectOnlyInDocNodes=true) const;
285 };
286 
291 {
292 private:
293  mutable OUString m_Cache;
295  sal_uInt32 m_nFormat;
299 
300  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
301  virtual std::unique_ptr<SwField> Copy() const = 0;
302 
303 protected:
304  void SetFormat(sal_uInt32 const nSet) {
305  m_nFormat = nSet;
306  }
307 
308  SwField( SwFieldType* pTyp,
309  sal_uInt32 nFormat = 0,
310  LanguageType nLang = LANGUAGE_SYSTEM,
311  bool m_bUseFieldValueCache = true );
312 
313 public:
314  virtual ~SwField();
315 
316  SwField(SwField const &) = default;
317  SwField(SwField &&) = default;
318  SwField & operator =(SwField const &) = default;
319  SwField & operator =(SwField &&) = default;
320 
321  inline SwFieldType* GetTyp() const;
322 
324  virtual SwFieldType* ChgTyp( SwFieldType* );
325 
336  OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
337 
339  virtual OUString GetFieldName() const;
340 
341  std::unique_ptr<SwField> CopyField() const;
342 
344  SwFieldIds Which() const
345 #ifdef DBG_UTIL
346  ; // implemented in fldbas.cxx
347 #else
348  {
349  return m_pType->Which();
350  }
351 #endif
352 
353  // TYP_ID
354  SwFieldTypesEnum GetTypeId() const;
355  virtual sal_uInt16 GetSubType() const;
356  virtual void SetSubType(sal_uInt16);
357 
359  inline LanguageType GetLanguage() const;
360  virtual void SetLanguage(LanguageType nLng);
361 
363  inline sal_uInt32 GetFormat() const;
364  virtual OUString GetPar1() const;
365  virtual OUString GetPar2() const;
366 
367  virtual OUString GetFormula() const;
368 
369  void ChangeFormat(sal_uInt32 n);
370  virtual void SetPar1(const OUString& rStr);
371  virtual void SetPar2(const OUString& rStr);
372 
373  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
374  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
375 
377  bool HasClickHdl() const;
378  bool IsFixed() const;
379 
380  bool IsAutomaticLanguage() const {
381  return m_bIsAutomaticLanguage;
382  }
383  void SetAutomaticLanguage(bool const bSet) {
384  m_bIsAutomaticLanguage = bSet;
385  }
386 
387  virtual OUString GetDescription() const;
389  bool IsClickable() const;
390  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
391 };
392 
394 {
395  return m_pType;
396 }
397 
398 inline sal_uInt32 SwField::GetFormat() const
399 {
400  return m_nFormat;
401 }
402 
404 {
405  return m_nLang;
406 }
407 
410 {
411 private:
414 
415 protected:
416  SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
417  SwValueFieldType( const SwValueFieldType& rTyp );
418 
419 public:
420  SwDoc* GetDoc() const {
421  return m_pDoc;
422  }
423  void SetDoc(SwDoc* pNewDoc) {
424  m_pDoc = pNewDoc;
425  }
426 
427  bool UseFormat() const {
428  return m_bUseFormat;
429  }
430  void EnableFormat(bool bFormat = true) {
431  m_bUseFormat = bFormat;
432  }
433 
434  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
435  OUString DoubleToString(const double &rVal, LanguageType eLng) const;
436  OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
437 };
438 
440 {
441 private:
442  double m_fValue;
443 
444 protected:
445  SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
446  SwValueField( const SwValueField& rField );
447 
448 public:
449  virtual ~SwValueField() override;
450 
451  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
452  virtual void SetLanguage(LanguageType nLng) override;
453 
454  SwDoc* GetDoc() const {
455  return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
456  }
457 
458  virtual double GetValue() const;
459  virtual void SetValue( const double& rVal );
460 
461  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
462  return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
463  }
464 
465  static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
466  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
467 };
468 
470 {
471 private:
472  OUString m_sFormula;
473 
474 protected:
475  SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
476  SwFormulaField( const SwFormulaField& rField );
477 
478 public:
479  virtual OUString GetFormula() const override;
480  void SetFormula(const OUString& rStr);
481 
482  void SetExpandedFormula(const OUString& rStr);
483  OUString GetExpandedFormula() const;
484 };
485 
486 #endif // INCLUDED_SW_INC_FLDBAS_HXX
487 
488 /* 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:413
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:834
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:293
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:403
1234%
Definition: fldbas.hxx:168
1.234,56%
Definition: fldbas.hxx:169
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:430
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:398
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:290
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
Definition: doc.hxx:188
SwVarFormat
Definition: fldbas.hxx:165
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:200
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:513
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:296
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:298
1245.56
Definition: fldbas.hxx:176
SwUserType
Definition: fldbas.hxx:223
SwDoc * GetDoc() const
Definition: fldbas.hxx:454
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:82
For old documents the Field-Which IDs must be preserved !!!
EUR 1234.
Definition: fldbas.hxx:181
SwFieldType * m_pType
Definition: fldbas.hxx:294
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:383
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:383
struct _xmlTextWriter * xmlTextWriterPtr
SwFileNameFormat
Definition: fldbas.hxx:153
bool m_bUseFieldValueCache
Definition: fldbas.hxx:297
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:212
class SAL_NO_VTABLE XPropertySet
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:497
sal_uInt32 m_nFormat
Definition: fldbas.hxx:295
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:304
OUString m_sFormula
Definition: fldbas.hxx:472
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc * GetDoc() const
Definition: fldbas.hxx:420
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:380
SwDateTimeSubType
Definition: fldbas.hxx:228
bool UseFormat() const
Definition: fldbas.hxx:427
SwFieldType * GetTyp() const
Definition: fldbas.hxx:393
SwFieldIds m_nWhich
Definition: fldbas.hxx:245
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:409
1.234.567
Definition: fldbas.hxx:179
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:205
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:423
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:528
1234.56 EUR 1234.
Definition: fldbas.hxx:186
EUR 1234.56 EUR 1234.–.
Definition: fldbas.hxx:183
Format for numbers from system.
Definition: fldbas.hxx:173
double m_fValue
Definition: fldbas.hxx:442
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
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:589
void SetLanguage(SwWrtShell &rWrtSh, std::u16string_view rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:214
virtual OUString GetFormula() const
Definition: fldbas.cxx:326
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:461
Format for currency from system.
Definition: fldbas.hxx:180
SwDoc * m_pDoc
Definition: fldbas.hxx:412
SwFieldIds Which() const
Definition: fldbas.hxx:273
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:423