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 <cppuhelper/weakref.hxx>
26 #include <editeng/svxenum.hxx>
27 #include <vector>
28 #include <climits>
29 
30 class SwDoc;
31 class SwRootFrame;
32 class SvNumberFormatter;
33 namespace com { namespace sun { namespace star { namespace beans { class XPropertySet; } } } }
34 namespace com { namespace sun { namespace star { namespace uno { class Any; } } } }
35 
36 typedef struct _xmlTextWriter* xmlTextWriterPtr;
37 
38 enum class SwFieldIds : sal_uInt16 {
40  Database,
41  User,
42  Filename,
44  Date,
45  Time,
46  PageNumber,
47  Author,
48  Chapter,
49  DocStat,
50  GetExp, // 10
51  SetExp,
52  GetRef,
53  HiddenText,
54  Postit,
55  FixDate,
56  FixTime,
57  Reg,
58  VarReg,
59  SetRef,
60  Input, // 20
61  Macro,
62  Dde,
63  Table,
64  HiddenPara,
65  DocInfo,
67  DbNextSet,
68  DbNumSet,
70  ExtUser, // 30
71  RefPageSet,
72  RefPageGet,
73  Internet,
74  JumpEdit,
75  Script,
76  DateTime,
79  Dropdown,
80  ParagraphSignature, // 40
82 
83  Unknown = USHRT_MAX, // used as default value in some method calls
84 };
85 
87 enum class SwFieldTypesEnum : sal_uInt16 {
88  Begin,
89  Date = Begin, // 0
90  Time,
91  Filename,
93  Chapter,
94  PageNumber,
96  Author,
97  Set,
98  Get,
99  Formel, // 10
100  HiddenText,
101  SetRef,
102  GetRef,
103  DDE,
104  Macro,
105  Input,
107  DocumentInfo,
108  Database,
109  User, // 20
110  Postit,
111  TemplateName,
112  Sequence,
117  NextPage,
118  PreviousPage,
119  ExtendedUser, // 30
120  FixedDate,
121  FixedTime,
122  SetInput,
123  UserInput,
124  SetRefPage,
125  GetRefPage,
126  Internet,
127  JumpEdit,
128  Script,
129  Authority, // 40
131  Dropdown,
132  Custom, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
134  LAST,
135  Unknown = USHRT_MAX // used by SwFieldMgr::GetCurTypeId
136 };
145 };
155  FF_FIXED = 0x8000
156 };
157 
159  VVF_CMD = 0x0010,
160  VVF_INVISIBLE = 0x0040,
161  VVF_XXP = 0x0400,
162  VVF_XX_XXP = 0x0800,
163  VVF_CLEAR = 0x000f,
164 
165 // From here new formats:
166  VVF_SYS = 0x2000,
167  VVF_X = 0x2100,
168  VVF_X_X = 0x2200,
169  VVF_X_XX = 0x2300,
170  VVF_XX_X = 0x2400,
171  VVF_XX_XX = 0x2500,
172  VVF_XX_XXX = 0x2600,
173  VVF_SYS_CUR = 0x2700,
174  VVF_CUR_X = 0x2800,
175  VVF_CUR_XX_XX = 0x2900,
176  VVF_CUR_XX_X0 = 0x2a00,
177  VVF_X_CUR = 0x2b00,
178  VVF_XX_XX_CUR = 0x2c00,
179  VVF_XX_X0_CUR = 0x2d00,
180  VF_CMD = VVF_CMD,
190 
191 };
192 
193 typedef sal_uInt16 SwGetSetExpType;
195 {
196 const SwGetSetExpType GSE_STRING = 0x0001;
197 const SwGetSetExpType GSE_EXPR = 0x0002;
198 const SwGetSetExpType GSE_SEQ = 0x0008;
199 const SwGetSetExpType GSE_FORMULA = 0x0010;
200 }
201 
202 typedef sal_uInt16 SwExtendedSubType;
204 {
205 const SwExtendedSubType SUB_CMD = 0x0100;
208 }
209 
211  INP_TXT = 0x01,
212  INP_USR = 0x02,
213  INP_VAR = 0x03
214 };
215 
217  UF_STRING = 0x01,
218  UF_EXPR = 0x02
219 };
220 
222  FIXEDFLD = 1,
223  DATEFLD = 2,
225 };
226 
228 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
229 
235 {
236  css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
237 
239 
240  friend void FinitUI();
241  static std::vector<OUString>* s_pFieldNames;
242 
243  static void GetFieldName_();
244 
245 protected:
247  explicit SwFieldType( SwFieldIds nWhichId );
248 
249 public:
250 
251  SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
252  return m_wXFieldMaster;
253  }
254  SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
255  m_wXFieldMaster = xFieldMaster;
256  }
257 
258  static OUString GetTypeStr( SwFieldTypesEnum nTypeId );
259 
261  virtual OUString GetName() const;
262  virtual std::unique_ptr<SwFieldType> Copy() const = 0;
263  virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
264  virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
265 
266  SwFieldIds Which() const { return m_nWhich; }
267 
268  inline void UpdateFields() const;
269  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
270 };
271 
272 inline void SwFieldType::UpdateFields() const
273 {
274  const_cast<SwFieldType*>(this)->ModifyNotification( nullptr, nullptr );
275 }
276 
281 {
282 private:
283  mutable OUString m_Cache;
287  sal_uInt32 m_nFormat;
289 
290  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
291  virtual std::unique_ptr<SwField> Copy() const = 0;
292 
293 protected:
294  void SetFormat(sal_uInt32 const nSet) {
295  m_nFormat = nSet;
296  }
297 
298  SwField( SwFieldType* pTyp,
299  sal_uInt32 nFormat = 0,
300  LanguageType nLang = LANGUAGE_SYSTEM,
301  bool m_bUseFieldValueCache = true );
302 
303 public:
304  virtual ~SwField();
305 
306  SwField(SwField const &) = default;
307  SwField(SwField &&) = default;
308  SwField & operator =(SwField const &) = default;
309  SwField & operator =(SwField &&) = default;
310 
311  inline SwFieldType* GetTyp() const;
312 
314  virtual SwFieldType* ChgTyp( SwFieldType* );
315 
326  OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
327 
329  virtual OUString GetFieldName() const;
330 
331  std::unique_ptr<SwField> CopyField() const;
332 
334  SwFieldIds Which() const
335 #ifdef DBG_UTIL
336  ; // implemented in fldbas.cxx
337 #else
338  {
339  return m_pType->Which();
340  }
341 #endif
342 
343  // TYP_ID
344  SwFieldTypesEnum GetTypeId() const;
345  virtual sal_uInt16 GetSubType() const;
346  virtual void SetSubType(sal_uInt16);
347 
349  inline LanguageType GetLanguage() const;
350  virtual void SetLanguage(LanguageType nLng);
351 
353  inline sal_uInt32 GetFormat() const;
354  virtual OUString GetPar1() const;
355  virtual OUString GetPar2() const;
356 
357  virtual OUString GetFormula() const;
358 
359  void ChangeFormat(sal_uInt32 n);
360  virtual void SetPar1(const OUString& rStr);
361  virtual void SetPar2(const OUString& rStr);
362 
363  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
364  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
365 
367  bool HasClickHdl() const;
368  bool IsFixed() const;
369 
370  bool IsAutomaticLanguage() const {
371  return m_bIsAutomaticLanguage;
372  }
373  void SetAutomaticLanguage(bool const bSet) {
374  m_bIsAutomaticLanguage = bSet;
375  }
376 
377  virtual OUString GetDescription() const;
379  bool IsClickable() const;
380  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
381 };
382 
384 {
385  return m_pType;
386 }
387 
388 inline sal_uInt32 SwField::GetFormat() const
389 {
390  return m_nFormat;
391 }
392 
394 {
395  return m_nLang;
396 }
397 
400 {
401 private:
404 
405 protected:
406  SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
407  SwValueFieldType( const SwValueFieldType& rTyp );
408 
409 public:
410  SwDoc* GetDoc() const {
411  return m_pDoc;
412  }
413  void SetDoc(SwDoc* pNewDoc) {
414  m_pDoc = pNewDoc;
415  }
416 
417  bool UseFormat() const {
418  return m_bUseFormat;
419  }
420  void EnableFormat(bool bFormat = true) {
421  m_bUseFormat = bFormat;
422  }
423 
424  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
425  OUString DoubleToString(const double &rVal, LanguageType eLng) const;
426  OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
427 };
428 
430 {
431 private:
432  double m_fValue;
433 
434 protected:
435  SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
436  SwValueField( const SwValueField& rField );
437 
438 public:
439  virtual ~SwValueField() override;
440 
441  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
442  virtual void SetLanguage(LanguageType nLng) override;
443 
444  SwDoc* GetDoc() const {
445  return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
446  }
447 
448  virtual double GetValue() const;
449  virtual void SetValue( const double& rVal );
450 
451  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
452  return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
453  }
454 
455  static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
456  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
457 };
458 
460 {
461 private:
462  OUString m_sFormula;
463 
464 protected:
465  SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
466  SwFormulaField( const SwFormulaField& rField );
467 
468 public:
469  virtual OUString GetFormula() const override;
470  void SetFormula(const OUString& rStr);
471 
472  void SetExpandedFormula(const OUString& rStr);
473  OUString GetExpandedFormula() const;
474 };
475 
476 #endif // INCLUDED_SW_INC_FLDBAS_HXX
477 
478 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:234
Show command.
Definition: fldbas.hxx:159
bool m_bUseFormat
Use number formatter.
Definition: fldbas.hxx:403
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:774
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:283
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:393
1234%
Definition: fldbas.hxx:161
1.234,56%
Definition: fldbas.hxx:162
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:420
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:388
std::string GetValue
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:206
1.234.5
Definition: fldbas.hxx:170
Base class of all fields.
Definition: fldbas.hxx:280
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:402
Definition: doc.hxx:185
SwVarFormat
Definition: fldbas.hxx:158
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:193
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:452
LanguageType m_nLang
control the usage of the cached field value
Definition: fldbas.hxx:285
css::uno::WeakReference< css::beans::XPropertySet > m_wXFieldMaster
Definition: fldbas.hxx:236
bool m_bIsAutomaticLanguage
Definition: fldbas.hxx:286
1245.56
Definition: fldbas.hxx:169
SwUserType
Definition: fldbas.hxx:216
SwDoc * GetDoc() const
Definition: fldbas.hxx:444
SAL_DLLPRIVATE css::uno::WeakReference< css::beans::XPropertySet > const & GetXObject() const
Definition: fldbas.hxx:251
struct _xmlTextWriter * xmlTextWriterPtr
Definition: fldbas.hxx:36
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
For old documents the Field-Which IDs must be preserved !!!
EUR 1234.
Definition: fldbas.hxx:174
SwFieldType * m_pType
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:288
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:60
void UpdateFields() const
Definition: fldbas.hxx:272
1234 EUR
Definition: fldbas.hxx:177
Compatibility:
Definition: fldbas.hxx:181
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:241
1.234.56
Definition: fldbas.hxx:171
void SetAutomaticLanguage(bool const bSet)
Definition: fldbas.hxx:373
SwInputFieldSubType
Definition: fldbas.hxx:210
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:197
virtual void ModifyNotification(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:154
1234.5
Definition: fldbas.hxx:168
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:330
struct _xmlTextWriter * xmlTextWriterPtr
SwFileNameFormat
Definition: fldbas.hxx:146
bool m_bUseFieldValueCache
Definition: fldbas.hxx:284
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:205
class SAL_NO_VTABLE XPropertySet
Invisible.
Definition: fldbas.hxx:160
sal_uInt16 SwExtendedSubType
Definition: fldbas.hxx:202
SAL_DLLPRIVATE void SetXObject(css::uno::Reference< css::beans::XPropertySet > const &xFieldMaster)
Definition: fldbas.hxx:254
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:87
SwFieldIds
Definition: fldbas.hxx:38
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang=LANGUAGE_NONE)
General tools.
Definition: fldbas.cxx:436
sal_uInt32 m_nFormat
Definition: fldbas.hxx:287
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:294
OUString m_sFormula
Definition: fldbas.hxx:462
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc * GetDoc() const
Definition: fldbas.hxx:410
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:370
SwDateTimeSubType
Definition: fldbas.hxx:221
bool UseFormat() const
Definition: fldbas.hxx:417
SwFieldType * GetTyp() const
Definition: fldbas.hxx:383
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:399
1.234.567
Definition: fldbas.hxx:172
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:198
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:362
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:467
1234.56 EUR 1234.
Definition: fldbas.hxx:179
EUR 1234.56 EUR 1234.–.
Definition: fldbas.hxx:176
Format for numbers from system.
Definition: fldbas.hxx:166
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:261
double m_fValue
Definition: fldbas.hxx:432
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:207
1234
Definition: fldbas.hxx:167
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:199
1234.56 EUR 1234.00 EUR
Definition: fldbas.hxx:178
void SetLanguage(SwWrtShell &rWrtSh, const OUString &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:223
EUR 1234.56 EUR 1234.00.
Definition: fldbas.hxx:175
SwAttrFieldType
Definition: fldbas.hxx:137
void FinitUI()
Definition: initui.cxx:71
SwFieldIds const m_nWhich
Definition: fldbas.hxx:238
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:196
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:530
virtual OUString GetFormula() const
Definition: fldbas.cxx:273
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:451
Format for currency from system.
Definition: fldbas.hxx:173
SwDoc * m_pDoc
Definition: fldbas.hxx:402
SwFieldIds Which() const
Definition: fldbas.hxx:266
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:413