1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_INC_FLDBAS_HXX
20 #define INCLUDED_SW_INC_FLDBAS_HXX
22 #include <i18nlangtag/lang.h>
24 #include "swtypes.hxx"
26 #include "nodeoffset.hxx"
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <cppuhelper/weakref.hxx>
30 #include <editeng/svxenum.hxx>
31 #include <unotools/weakref.hxx>
32 #include <rtl/ref.hxx>
41 class SvNumberFormatter
;
42 class IDocumentRedlineAccess
;
45 namespace com::sun::star::uno
{ class Any
; }
47 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
49 enum class SwFieldIds
: sal_uInt16
{
50 /// For old documents the Field-Which IDs must be preserved !!!
91 ParagraphSignature
, // 40
92 LAST
= ParagraphSignature
,
94 Unknown
= USHRT_MAX
, // used as default value in some method calls
97 /// List of FieldTypes at UI.
98 enum class SwFieldTypesEnum
: sal_uInt16
{
143 Custom
, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
146 Unknown
= USHRT_MAX
// used by SwFieldMgr::GetCurTypeId
148 enum SwAttrFieldType
{
157 enum SwFileNameFormat
{
170 VVF_CMD
= 0x0010, ///< Show command.
171 VVF_INVISIBLE
= 0x0040, ///< Invisible.
172 VVF_XXP
= 0x0400, ///< 1234%
173 VVF_XX_XXP
= 0x0800, ///< 1.234,56%
176 // From here new formats:
177 VVF_SYS
= 0x2000, ///< Format for numbers from system.
178 VVF_X
= 0x2100, ///< 1234
179 VVF_X_X
= 0x2200, ///< 1234.5
180 VVF_X_XX
= 0x2300, ///< 1245.56
181 VVF_XX_X
= 0x2400, ///< 1.234.5
182 VVF_XX_XX
= 0x2500, ///< 1.234.56
183 VVF_XX_XXX
= 0x2600, ///< 1.234.567
184 VVF_SYS_CUR
= 0x2700, ///< Format for currency from system.
185 VVF_CUR_X
= 0x2800, ///< EUR 1234
186 VVF_CUR_XX_XX
= 0x2900, ///< EUR 1234.56 EUR 1234.00
187 VVF_CUR_XX_X0
= 0x2a00, ///< EUR 1234.56 EUR 1234.--
188 VVF_X_CUR
= 0x2b00, ///< 1234 EUR
189 VVF_XX_XX_CUR
= 0x2c00, ///< 1234.56 EUR 1234.00 EUR
190 VVF_XX_X0_CUR
= 0x2d00, ///< 1234.56 EUR 1234.-- EUR
193 VF_INVISIBLE
= VVF_INVISIBLE
,
195 VF_XX_XXP
= VVF_XX_XXP
,
196 VF_VISIBLE
= VVF_SYS
,
198 VF_XX_XX
= VVF_XX_XX
,
199 VF_XX_XX_CUR
= VVF_SYS_CUR
,
204 typedef sal_uInt16 SwGetSetExpType
;
205 namespace nsSwGetSetExpType
207 const SwGetSetExpType GSE_STRING
= 0x0001; ///< String
208 const SwGetSetExpType GSE_EXPR
= 0x0002; ///< Expression
209 const SwGetSetExpType GSE_SEQ
= 0x0008; ///< Sequence
210 const SwGetSetExpType GSE_FORMULA
= 0x0010; ///< Formula
213 typedef sal_uInt16 SwExtendedSubType
;
214 namespace nsSwExtendedSubType
216 const SwExtendedSubType SUB_CMD
= 0x0100; ///< Show command.
217 const SwExtendedSubType SUB_INVISIBLE
= 0x0200; ///< Invisible.
218 const SwExtendedSubType SUB_OWN_FMT
= 0x0400; ///< SwDBField: Don't accept formatting from database.
221 enum SwInputFieldSubType
{
232 enum SwDateTimeSubType
{
239 OUString
FormatNumber(sal_uInt32 nNum
, SvxNumType nFormat
, LanguageType nLang
= LANGUAGE_NONE
);
240 SwFieldTypesEnum
SwFieldTypeFromString(std::u16string_view rString
);
242 /** Instances of SwFields and those derived from it occur 0 to n times.
243 For each class there is one instance of the associated type class.
244 Base class of all field types is SwFieldType. */
246 class SW_DLLPUBLIC SwFieldType
: public sw::BroadcastingModify
248 unotools::WeakReference
<SwXFieldMaster
> m_wXFieldMaster
;
252 friend void FinitUI(); ///< In order to delete pointer!
253 static std::vector
<OUString
>* s_pFieldNames
;
255 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
258 /// Single argument ctors shall be explicit.
259 explicit SwFieldType( SwFieldIds nWhichId
);
263 unotools::WeakReference
<SwXFieldMaster
> const& GetXObject() const {
264 return m_wXFieldMaster
;
266 void SetXObject(rtl::Reference
<SwXFieldMaster
> const& xFieldMaster
);
268 static const OUString
& GetTypeStr( SwFieldTypesEnum nTypeId
);
270 /// Only in derived classes.
271 virtual OUString
GetName() const;
272 virtual std::unique_ptr
<SwFieldType
> Copy() const = 0;
273 virtual void QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const;
274 virtual void PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
);
276 SwFieldIds
Which() const { return m_nWhich
; }
278 void PrintHiddenPara();
279 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
280 SwFormatField
* FindFormatForField(const SwField
*) const;
281 SwFormatField
* FindFormatForPostItId(sal_uInt32 nPostItId
) const;
282 void CollectPostIts(std::vector
<SwFormatField
*>& rvFormatFields
, IDocumentRedlineAccess
const& rIDRA
, bool HideRedlines
);
283 bool HasHiddenInformationNotes() const;
284 void GatherNodeIndex(std::vector
<SwNodeOffset
>& rvNodeIndex
);
285 void GatherRefFields(std::vector
<SwGetRefField
*>& rvRFields
, const sal_uInt16 nTyp
);
286 void GatherFields(std::vector
<SwFormatField
*>& rvFormatFields
, bool bCollectOnlyInDocNodes
=true) const;
287 void GatherDdeTables(std::vector
<SwDDETable
*>& rvTables
) const;
288 void UpdateDocPos(const SwTwips nDocPos
);
289 virtual void UpdateFields();
292 /** Base class of all fields.
293 Type of field is queried via Which.
294 Expanded content of field is queried via ExpandField(). */
295 class SW_DLLPUBLIC SwField
298 mutable OUString m_Cache
; ///< Cached expansion (for clipboard).
299 SwFieldType
* m_pType
;
300 sal_uInt32 m_nFormat
; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
301 LanguageType m_nLang
; ///< Always change via SetLanguage!
302 bool m_bUseFieldValueCache
; /// control the usage of the cached field value
303 bool m_bIsAutomaticLanguage
;
304 /// Used for tooltip purposes when it's not-empty.
307 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const = 0;
308 virtual std::unique_ptr
<SwField
> Copy() const = 0;
311 void SetFormat(sal_uInt32
const nSet
) {
315 SwField( SwFieldType
* pTyp
,
316 sal_uInt32 nFormat
= 0,
317 LanguageType nLang
= LANGUAGE_SYSTEM
,
318 bool m_bUseFieldValueCache
= true );
323 SwField(SwField
const &) = default;
324 SwField(SwField
&&) = default;
325 SwField
& operator =(SwField
const &) = default;
326 SwField
& operator =(SwField
&&) = default;
328 inline SwFieldType
* GetTyp() const;
330 /// Set new type (used for copying among documents).
331 virtual SwFieldType
* ChgTyp( SwFieldType
* );
333 /** expand the field.
334 @param bCached return cached field value.
335 @remark most callers should use the cached field value.
336 this is because various fields need special handing
337 (ChangeExpansion()) to return correct values, and only
338 SwTextFormatter::NewFieldPortion() sets things up properly.
339 @param pLayout the layout to use for expansion; there are a few
340 fields that expand differently via layout mode.
341 @return the generated text (suitable for display)
343 OUString
ExpandField(bool bCached
, SwRootFrame
const* pLayout
) const;
345 /// @return name or content.
346 virtual OUString
GetFieldName() const;
348 std::unique_ptr
<SwField
> CopyField() const;
351 SwFieldIds
Which() const
353 ; // implemented in fldbas.cxx
356 return m_pType
->Which();
361 SwFieldTypesEnum
GetTypeId() const;
362 virtual sal_uInt16
GetSubType() const;
363 virtual void SetSubType(sal_uInt16
);
365 /// Language at field position.
366 inline LanguageType
GetLanguage() const;
367 virtual void SetLanguage(LanguageType nLng
);
369 /// Query parameters for dialog and for BASIC.
370 inline sal_uInt32
GetFormat() const;
371 virtual OUString
GetPar1() const;
372 virtual OUString
GetPar2() const;
374 virtual OUString
GetFormula() const;
376 void ChangeFormat(sal_uInt32 n
);
377 virtual void SetPar1(const OUString
& rStr
);
378 virtual void SetPar2(const OUString
& rStr
);
380 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const;
381 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
);
383 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
384 bool HasClickHdl() const;
385 bool IsFixed() const;
387 bool IsAutomaticLanguage() const {
388 return m_bIsAutomaticLanguage
;
390 void SetAutomaticLanguage(bool const bSet
) {
391 m_bIsAutomaticLanguage
= bSet
;
394 virtual OUString
GetDescription() const;
395 /// Is this field clickable?
396 bool IsClickable() const;
397 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
398 const OUString
& GetTitle() const { return m_aTitle
; }
399 void SetTitle(const OUString
& rTitle
) { m_aTitle
= rTitle
; }
402 inline SwFieldType
* SwField::GetTyp() const
407 inline sal_uInt32
SwField::GetFormat() const
412 inline LanguageType
SwField::GetLanguage() const
417 /// Fields containing values that have to be formatted via number formatter.
418 class SwValueFieldType
: public SwFieldType
422 bool m_bUseFormat
; ///< Use number formatter.
425 SwValueFieldType( SwDoc
* pDocPtr
, SwFieldIds nWhichId
);
426 SwValueFieldType( const SwValueFieldType
& rTyp
);
429 SwDoc
* GetDoc() const {
432 void SetDoc(SwDoc
* pNewDoc
) {
436 bool UseFormat() const {
439 void EnableFormat(bool bFormat
= true) {
440 m_bUseFormat
= bFormat
;
443 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const;
444 OUString
DoubleToString(const double &rVal
, LanguageType eLng
) const;
445 OUString
DoubleToString(const double &rVal
, sal_uInt32 nFormat
) const;
446 /// Query input or formatted value for dialog.
447 OUString
GetInputOrDateTime( const OUString
& rInput
, const double& rVal
, sal_uInt32 nFormat
) const;
450 class SW_DLLPUBLIC SwValueField
: public SwField
456 SwValueField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, LanguageType nLang
= LANGUAGE_SYSTEM
, const double fVal
= 0.0 );
457 SwValueField( const SwValueField
& rField
);
460 virtual ~SwValueField() override
;
462 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
463 virtual void SetLanguage(LanguageType nLng
) override
;
465 SwDoc
* GetDoc() const {
466 return static_cast<const SwValueFieldType
*>(GetTyp())->GetDoc();
469 virtual double GetValue() const;
470 virtual void SetValue( const double& rVal
);
472 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const {
473 return static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, nFormat
, nLng
);
476 static sal_uInt32
GetSystemFormat(SvNumberFormatter
* pFormatter
, sal_uInt32 nFormat
);
477 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
480 class SW_DLLPUBLIC SwFormulaField
: public SwValueField
486 SwFormulaField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, const double fVal
);
487 SwFormulaField( const SwFormulaField
& rField
);
490 virtual OUString
GetFormula() const override
;
491 void SetFormula(const OUString
& rStr
);
493 void SetExpandedFormula(const OUString
& rStr
);
494 OUString
GetExpandedFormula() const;
496 /// Query formula or formatted value for dialog.
497 OUString
GetInputOrDateTime() const;
500 #endif // INCLUDED_SW_INC_FLDBAS_HXX
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */