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 
109  TYP_USERFLD, // 20
132  TYP_CUSTOM, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
135 };
144 };
154  FF_FIXED = 0x8000
155 };
156 
158  VVF_CMD = 0x0010,
159  VVF_INVISIBLE = 0x0040,
160  VVF_XXP = 0x0400,
161  VVF_XX_XXP = 0x0800,
162  VVF_CLEAR = 0x000f,
163 
164 // From here new formats:
165  VVF_SYS = 0x2000,
166  VVF_X = 0x2100,
167  VVF_X_X = 0x2200,
168  VVF_X_XX = 0x2300,
169  VVF_XX_X = 0x2400,
170  VVF_XX_XX = 0x2500,
171  VVF_XX_XXX = 0x2600,
172  VVF_SYS_CUR = 0x2700,
173  VVF_CUR_X = 0x2800,
174  VVF_CUR_XX_XX = 0x2900,
175  VVF_CUR_XX_X0 = 0x2a00,
176  VVF_X_CUR = 0x2b00,
177  VVF_XX_XX_CUR = 0x2c00,
178  VVF_XX_X0_CUR = 0x2d00,
179  VF_CMD = VVF_CMD,
189 
190 };
191 
192 typedef sal_uInt16 SwGetSetExpType;
194 {
195 const SwGetSetExpType GSE_STRING = 0x0001;
196 const SwGetSetExpType GSE_EXPR = 0x0002;
197 const SwGetSetExpType GSE_SEQ = 0x0008;
198 const SwGetSetExpType GSE_FORMULA = 0x0010;
199 }
200 
201 typedef sal_uInt16 SwExtendedSubType;
203 {
204 const SwExtendedSubType SUB_CMD = 0x0100;
207 }
208 
210  INP_TXT = 0x01,
211  INP_USR = 0x02,
212  INP_VAR = 0x03
213 };
214 
216  UF_STRING = 0x01,
217  UF_EXPR = 0x02
218 };
219 
221  FIXEDFLD = 1,
222  DATEFLD = 2,
224 };
225 
227 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang = LANGUAGE_NONE);
228 
234 {
235  css::uno::WeakReference<css::beans::XPropertySet> m_wXFieldMaster;
236 
238 
239  friend void FinitUI();
240  static std::vector<OUString>* s_pFieldNames;
241 
242  static void GetFieldName_();
243 
244 protected:
246  explicit SwFieldType( SwFieldIds nWhichId );
247 
248 public:
249 
250  SAL_DLLPRIVATE css::uno::WeakReference<css::beans::XPropertySet> const& GetXObject() const {
251  return m_wXFieldMaster;
252  }
253  SAL_DLLPRIVATE void SetXObject(css::uno::Reference<css::beans::XPropertySet> const& xFieldMaster) {
254  m_wXFieldMaster = xFieldMaster;
255  }
256 
257  static OUString GetTypeStr( sal_uInt16 nTypeId );
258 
260  virtual OUString GetName() const;
261  virtual std::unique_ptr<SwFieldType> Copy() const = 0;
262  virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const;
263  virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich );
264 
265  SwFieldIds Which() const { return m_nWhich; }
266 
267  inline void UpdateFields() const;
268  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
269 };
270 
271 inline void SwFieldType::UpdateFields() const
272 {
273  const_cast<SwFieldType*>(this)->ModifyNotification( nullptr, nullptr );
274 }
275 
280 {
281 private:
282  mutable OUString m_Cache;
286  sal_uInt32 m_nFormat;
288 
289  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const = 0;
290  virtual std::unique_ptr<SwField> Copy() const = 0;
291 
292 protected:
293  void SetFormat(sal_uInt32 const nSet) {
294  m_nFormat = nSet;
295  }
296 
297  SwField( SwFieldType* pTyp,
298  sal_uInt32 nFormat = 0,
299  LanguageType nLang = LANGUAGE_SYSTEM,
300  bool m_bUseFieldValueCache = true );
301 
302 public:
303  virtual ~SwField();
304 
305  SwField(SwField const &) = default;
306  SwField(SwField &&) = default;
307  SwField & operator =(SwField const &) = default;
308  SwField & operator =(SwField &&) = default;
309 
310  inline SwFieldType* GetTyp() const;
311 
313  virtual SwFieldType* ChgTyp( SwFieldType* );
314 
325  OUString ExpandField(bool bCached, SwRootFrame const* pLayout) const;
326 
328  virtual OUString GetFieldName() const;
329 
330  std::unique_ptr<SwField> CopyField() const;
331 
333  SwFieldIds Which() const
334 #ifdef DBG_UTIL
335  ; // implemented in fldbas.cxx
336 #else
337  {
338  return m_pType->Which();
339  }
340 #endif
341 
342  // TYP_ID
343  sal_uInt16 GetTypeId() const;
344  virtual sal_uInt16 GetSubType() const;
345  virtual void SetSubType(sal_uInt16);
346 
348  inline LanguageType GetLanguage() const;
349  virtual void SetLanguage(LanguageType nLng);
350 
352  inline sal_uInt32 GetFormat() const;
353  virtual OUString GetPar1() const;
354  virtual OUString GetPar2() const;
355 
356  virtual OUString GetFormula() const;
357 
358  void ChangeFormat(sal_uInt32 n);
359  virtual void SetPar1(const OUString& rStr);
360  virtual void SetPar2(const OUString& rStr);
361 
362  virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const;
363  virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId );
364 
366  bool HasClickHdl() const;
367  bool IsFixed() const;
368 
369  bool IsAutomaticLanguage() const {
370  return m_bIsAutomaticLanguage;
371  }
372  void SetAutomaticLanguage(bool const bSet) {
373  m_bIsAutomaticLanguage = bSet;
374  }
375 
376  virtual OUString GetDescription() const;
378  bool IsClickable() const;
379  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const;
380 };
381 
383 {
384  return m_pType;
385 }
386 
387 inline sal_uInt32 SwField::GetFormat() const
388 {
389  return m_nFormat;
390 }
391 
393 {
394  return m_nLang;
395 }
396 
399 {
400 private:
403 
404 protected:
405  SwValueFieldType( SwDoc* pDocPtr, SwFieldIds nWhichId );
406  SwValueFieldType( const SwValueFieldType& rTyp );
407 
408 public:
409  SwDoc* GetDoc() const {
410  return m_pDoc;
411  }
412  void SetDoc(SwDoc* pNewDoc) {
413  m_pDoc = pNewDoc;
414  }
415 
416  bool UseFormat() const {
417  return m_bUseFormat;
418  }
419  void EnableFormat(bool bFormat = true) {
420  m_bUseFormat = bFormat;
421  }
422 
423  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const;
424  OUString DoubleToString(const double &rVal, LanguageType eLng) const;
425  OUString DoubleToString(const double &rVal, sal_uInt32 nFormat) const;
426 };
427 
429 {
430 private:
431  double m_fValue;
432 
433 protected:
434  SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, LanguageType nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
435  SwValueField( const SwValueField& rField );
436 
437 public:
438  virtual ~SwValueField() override;
439 
440  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
441  virtual void SetLanguage(LanguageType nLng) override;
442 
443  SwDoc* GetDoc() const {
444  return static_cast<const SwValueFieldType*>(GetTyp())->GetDoc();
445  }
446 
447  virtual double GetValue() const;
448  virtual void SetValue( const double& rVal );
449 
450  OUString ExpandValue(const double& rVal, sal_uInt32 nFormat, LanguageType nLng) const {
451  return static_cast<SwValueFieldType*>(GetTyp())->ExpandValue(rVal, nFormat, nLng);
452  }
453 
454  static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat);
455  void dumpAsXml(xmlTextWriterPtr pWriter) const override;
456 };
457 
459 {
460 private:
461  OUString m_sFormula;
462 
463 protected:
464  SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal );
465  SwFormulaField( const SwFormulaField& rField );
466 
467 public:
468  virtual OUString GetFormula() const override;
469  void SetFormula(const OUString& rStr);
470 
471  void SetExpandedFormula(const OUString& rStr);
472  OUString GetExpandedFormula() const;
473 };
474 
475 #endif // INCLUDED_SW_INC_FLDBAS_HXX
476 
477 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
Show command.
Definition: fldbas.hxx:158
bool m_bUseFormat
Use number formatter.
Definition: fldbas.hxx:402
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:782
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:282
LanguageType GetLanguage() const
Language at field position.
Definition: fldbas.hxx:392
1234%
Definition: fldbas.hxx:160
1.234,56%
Definition: fldbas.hxx:161
void EnableFormat(bool bFormat=true)
Definition: fldbas.hxx:419
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:387
std::string GetValue
const SwExtendedSubType SUB_INVISIBLE
Invisible.
Definition: fldbas.hxx:205
1.234.5
Definition: fldbas.hxx:169
Base class of all fields.
Definition: fldbas.hxx:279
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:402
Definition: doc.hxx:185
SwVarFormat
Definition: fldbas.hxx:157
sal_uInt16 SwGetSetExpType
Definition: fldbas.hxx:192
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:460
LanguageType m_nLang
control the usage of the cached field value
Definition: fldbas.hxx:284
css::uno::WeakReference< css::beans::XPropertySet > m_wXFieldMaster
Definition: fldbas.hxx:235
bool m_bIsAutomaticLanguage
Definition: fldbas.hxx:285
1245.56
Definition: fldbas.hxx:168
SwUserType
Definition: fldbas.hxx:215
SwDoc * GetDoc() const
Definition: fldbas.hxx:443
SAL_DLLPRIVATE css::uno::WeakReference< css::beans::XPropertySet > const & GetXObject() const
Definition: fldbas.hxx:250
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:173
SwFieldType * m_pType
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:287
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:58
void UpdateFields() const
Definition: fldbas.hxx:271
1234 EUR
Definition: fldbas.hxx:176
Compatibility:
Definition: fldbas.hxx:180
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:240
1.234.56
Definition: fldbas.hxx:170
void SetAutomaticLanguage(bool const bSet)
Definition: fldbas.hxx:372
SwInputFieldSubType
Definition: fldbas.hxx:209
const SwGetSetExpType GSE_EXPR
Expression.
Definition: fldbas.hxx:196
virtual void ModifyNotification(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.hxx:154
1234.5
Definition: fldbas.hxx:167
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:338
struct _xmlTextWriter * xmlTextWriterPtr
SwFileNameFormat
Definition: fldbas.hxx:145
bool m_bUseFieldValueCache
Definition: fldbas.hxx:283
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:204
class SAL_NO_VTABLE XPropertySet
Invisible.
Definition: fldbas.hxx:159
sal_uInt16 SwExtendedSubType
Definition: fldbas.hxx:201
SAL_DLLPRIVATE void SetXObject(css::uno::Reference< css::beans::XPropertySet > const &xFieldMaster)
Definition: fldbas.hxx:253
SwFieldIds
Definition: fldbas.hxx:38
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang=LANGUAGE_NONE)
General tools.
Definition: fldbas.cxx:444
sal_uInt32 m_nFormat
Definition: fldbas.hxx:286
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:293
OUString m_sFormula
Definition: fldbas.hxx:461
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwDoc * GetDoc() const
Definition: fldbas.hxx:409
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:369
SwDateTimeSubType
Definition: fldbas.hxx:220
bool UseFormat() const
Definition: fldbas.hxx:416
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:398
1.234.567
Definition: fldbas.hxx:171
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:197
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:370
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:475
1234.56 EUR 1234.
Definition: fldbas.hxx:178
EUR 1234.56 EUR 1234.–.
Definition: fldbas.hxx:175
Format for numbers from system.
Definition: fldbas.hxx:165
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
Definition: unosett.cxx:259
double m_fValue
Definition: fldbas.hxx:431
const SwExtendedSubType SUB_OWN_FMT
SwDBField: Don't accept formatting from database.
Definition: fldbas.hxx:206
1234
Definition: fldbas.hxx:166
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:198
1234.56 EUR 1234.00 EUR
Definition: fldbas.hxx:177
void SetLanguage(SwWrtShell &rWrtSh, const OUString &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet)
Definition: langhelper.cxx:223
EUR 1234.56 EUR 1234.00.
Definition: fldbas.hxx:174
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:87
SwAttrFieldType
Definition: fldbas.hxx:136
void FinitUI()
Definition: initui.cxx:72
SwFieldIds const m_nWhich
Definition: fldbas.hxx:237
const SwGetSetExpType GSE_STRING
String.
Definition: fldbas.hxx:195
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:538
virtual OUString GetFormula() const
Definition: fldbas.cxx:281
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
Definition: fldbas.hxx:450
Format for currency from system.
Definition: fldbas.hxx:172
SwDoc * m_pDoc
Definition: fldbas.hxx:401
SwFieldIds Which() const
Definition: fldbas.hxx:265
void SetDoc(SwDoc *pNewDoc)
Definition: fldbas.hxx:412