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>
25 #include "ndindex.hxx"
27 #include <cppuhelper/weakref.hxx>
28 #include <editeng/svxenum.hxx>
37 class SvNumberFormatter
;
38 class IDocumentRedlineAccess
;
40 namespace com::sun::star::beans
{ class XPropertySet
; }
41 namespace com::sun::star::uno
{ class Any
; }
43 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
45 enum class SwFieldIds
: sal_uInt16
{
46 /// For old documents the Field-Which IDs must be preserved !!!
87 ParagraphSignature
, // 40
88 LAST
= ParagraphSignature
,
90 Unknown
= USHRT_MAX
, // used as default value in some method calls
93 /// List of FieldTypes at UI.
94 enum class SwFieldTypesEnum
: sal_uInt16
{
139 Custom
, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
142 Unknown
= USHRT_MAX
// used by SwFieldMgr::GetCurTypeId
144 enum SwAttrFieldType
{
153 enum SwFileNameFormat
{
166 VVF_CMD
= 0x0010, ///< Show command.
167 VVF_INVISIBLE
= 0x0040, ///< Invisible.
168 VVF_XXP
= 0x0400, ///< 1234%
169 VVF_XX_XXP
= 0x0800, ///< 1.234,56%
172 // From here new formats:
173 VVF_SYS
= 0x2000, ///< Format for numbers from system.
174 VVF_X
= 0x2100, ///< 1234
175 VVF_X_X
= 0x2200, ///< 1234.5
176 VVF_X_XX
= 0x2300, ///< 1245.56
177 VVF_XX_X
= 0x2400, ///< 1.234.5
178 VVF_XX_XX
= 0x2500, ///< 1.234.56
179 VVF_XX_XXX
= 0x2600, ///< 1.234.567
180 VVF_SYS_CUR
= 0x2700, ///< Format for currency from system.
181 VVF_CUR_X
= 0x2800, ///< EUR 1234
182 VVF_CUR_XX_XX
= 0x2900, ///< EUR 1234.56 EUR 1234.00
183 VVF_CUR_XX_X0
= 0x2a00, ///< EUR 1234.56 EUR 1234.--
184 VVF_X_CUR
= 0x2b00, ///< 1234 EUR
185 VVF_XX_XX_CUR
= 0x2c00, ///< 1234.56 EUR 1234.00 EUR
186 VVF_XX_X0_CUR
= 0x2d00, ///< 1234.56 EUR 1234.-- EUR
189 VF_INVISIBLE
= VVF_INVISIBLE
,
191 VF_XX_XXP
= VVF_XX_XXP
,
192 VF_VISIBLE
= VVF_SYS
,
194 VF_XX_XX
= VVF_XX_XX
,
195 VF_XX_XX_CUR
= VVF_SYS_CUR
,
200 typedef sal_uInt16 SwGetSetExpType
;
201 namespace nsSwGetSetExpType
203 const SwGetSetExpType GSE_STRING
= 0x0001; ///< String
204 const SwGetSetExpType GSE_EXPR
= 0x0002; ///< Expression
205 const SwGetSetExpType GSE_SEQ
= 0x0008; ///< Sequence
206 const SwGetSetExpType GSE_FORMULA
= 0x0010; ///< Formula
209 typedef sal_uInt16 SwExtendedSubType
;
210 namespace nsSwExtendedSubType
212 const SwExtendedSubType SUB_CMD
= 0x0100; ///< Show command.
213 const SwExtendedSubType SUB_INVISIBLE
= 0x0200; ///< Invisible.
214 const SwExtendedSubType SUB_OWN_FMT
= 0x0400; ///< SwDBField: Don't accept formatting from database.
217 enum SwInputFieldSubType
{
228 enum SwDateTimeSubType
{
235 OUString
FormatNumber(sal_uInt32 nNum
, SvxNumType nFormat
, LanguageType nLang
= LANGUAGE_NONE
);
237 /** Instances of SwFields and those derived from it occur 0 to n times.
238 For each class there is one instance of the associated type class.
239 Base class of all field types is SwFieldType. */
241 class SW_DLLPUBLIC SwFieldType
: public sw::BroadcastingModify
243 css::uno::WeakReference
<css::beans::XPropertySet
> m_wXFieldMaster
;
247 friend void FinitUI(); ///< In order to delete pointer!
248 static std::vector
<OUString
>* s_pFieldNames
;
250 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
253 /// Single argument ctors shall be explicit.
254 explicit SwFieldType( SwFieldIds nWhichId
);
258 SAL_DLLPRIVATE
css::uno::WeakReference
<css::beans::XPropertySet
> const& GetXObject() const {
259 return m_wXFieldMaster
;
261 SAL_DLLPRIVATE
void SetXObject(css::uno::Reference
<css::beans::XPropertySet
> const& xFieldMaster
) {
262 m_wXFieldMaster
= xFieldMaster
;
265 static OUString
GetTypeStr( SwFieldTypesEnum nTypeId
);
267 /// Only in derived classes.
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
);
273 SwFieldIds
Which() const { return m_nWhich
; }
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
<sal_uLong
>& rvNodeIndex
);
283 void GatherRefFields(std::vector
<SwGetRefField
*>& rvRFields
, const sal_uInt16 nTyp
);
284 void GatherFields(std::vector
<SwFormatField
*>& rvFormatFields
, bool bCollectOnlyInDocNodes
=true) const;
285 void GatherDdeTables(std::vector
<SwDDETable
*>& rvTables
) const;
288 /** Base class of all fields.
289 Type of field is queried via Which.
290 Expanded content of field is queried via ExpandField(). */
291 class SW_DLLPUBLIC SwField
294 mutable OUString m_Cache
; ///< Cached expansion (for clipboard).
295 SwFieldType
* m_pType
;
296 sal_uInt32 m_nFormat
; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
297 LanguageType m_nLang
; ///< Always change via SetLanguage!
298 bool m_bUseFieldValueCache
; /// control the usage of the cached field value
299 bool m_bIsAutomaticLanguage
;
301 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const = 0;
302 virtual std::unique_ptr
<SwField
> Copy() const = 0;
305 void SetFormat(sal_uInt32
const nSet
) {
309 SwField( SwFieldType
* pTyp
,
310 sal_uInt32 nFormat
= 0,
311 LanguageType nLang
= LANGUAGE_SYSTEM
,
312 bool m_bUseFieldValueCache
= true );
317 SwField(SwField
const &) = default;
318 SwField(SwField
&&) = default;
319 SwField
& operator =(SwField
const &) = default;
320 SwField
& operator =(SwField
&&) = default;
322 inline SwFieldType
* GetTyp() const;
324 /// Set new type (used for copying among documents).
325 virtual SwFieldType
* ChgTyp( SwFieldType
* );
327 /** expand the field.
328 @param bCached return cached field value.
329 @remark most callers should use the cached field value.
330 this is because various fields need special handing
331 (ChangeExpansion()) to return correct values, and only
332 SwTextFormatter::NewFieldPortion() sets things up properly.
333 @param pLayout the layout to use for expansion; there are a few
334 fields that expand differently via layout mode.
335 @return the generated text (suitable for display)
337 OUString
ExpandField(bool bCached
, SwRootFrame
const* pLayout
) const;
339 /// @return name or content.
340 virtual OUString
GetFieldName() const;
342 std::unique_ptr
<SwField
> CopyField() const;
345 SwFieldIds
Which() const
347 ; // implemented in fldbas.cxx
350 return m_pType
->Which();
355 SwFieldTypesEnum
GetTypeId() const;
356 virtual sal_uInt16
GetSubType() const;
357 virtual void SetSubType(sal_uInt16
);
359 /// Language at field position.
360 inline LanguageType
GetLanguage() const;
361 virtual void SetLanguage(LanguageType nLng
);
363 /// Query parameters for dialog and for BASIC.
364 inline sal_uInt32
GetFormat() const;
365 virtual OUString
GetPar1() const;
366 virtual OUString
GetPar2() const;
368 virtual OUString
GetFormula() const;
370 void ChangeFormat(sal_uInt32 n
);
371 virtual void SetPar1(const OUString
& rStr
);
372 virtual void SetPar2(const OUString
& rStr
);
374 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const;
375 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
);
377 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
378 bool HasClickHdl() const;
379 bool IsFixed() const;
381 bool IsAutomaticLanguage() const {
382 return m_bIsAutomaticLanguage
;
384 void SetAutomaticLanguage(bool const bSet
) {
385 m_bIsAutomaticLanguage
= bSet
;
388 virtual OUString
GetDescription() const;
389 /// Is this field clickable?
390 bool IsClickable() const;
391 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
394 inline SwFieldType
* SwField::GetTyp() const
399 inline sal_uInt32
SwField::GetFormat() const
404 inline LanguageType
SwField::GetLanguage() const
409 /// Fields containing values that have to be formatted via number formatter.
410 class SwValueFieldType
: public SwFieldType
414 bool m_bUseFormat
; ///< Use number formatter.
417 SwValueFieldType( SwDoc
* pDocPtr
, SwFieldIds nWhichId
);
418 SwValueFieldType( const SwValueFieldType
& rTyp
);
421 SwDoc
* GetDoc() const {
424 void SetDoc(SwDoc
* pNewDoc
) {
428 bool UseFormat() const {
431 void EnableFormat(bool bFormat
= true) {
432 m_bUseFormat
= bFormat
;
435 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const;
436 OUString
DoubleToString(const double &rVal
, LanguageType eLng
) const;
437 OUString
DoubleToString(const double &rVal
, sal_uInt32 nFormat
) const;
440 class SW_DLLPUBLIC SwValueField
: public SwField
446 SwValueField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, LanguageType nLang
= LANGUAGE_SYSTEM
, const double fVal
= 0.0 );
447 SwValueField( const SwValueField
& rField
);
450 virtual ~SwValueField() override
;
452 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
453 virtual void SetLanguage(LanguageType nLng
) override
;
455 SwDoc
* GetDoc() const {
456 return static_cast<const SwValueFieldType
*>(GetTyp())->GetDoc();
459 virtual double GetValue() const;
460 virtual void SetValue( const double& rVal
);
462 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const {
463 return static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, nFormat
, nLng
);
466 static sal_uInt32
GetSystemFormat(SvNumberFormatter
* pFormatter
, sal_uInt32 nFormat
);
467 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
470 class SW_DLLPUBLIC SwFormulaField
: public SwValueField
476 SwFormulaField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, const double fVal
);
477 SwFormulaField( const SwFormulaField
& rField
);
480 virtual OUString
GetFormula() const override
;
481 void SetFormula(const OUString
& rStr
);
483 void SetExpandedFormula(const OUString
& rStr
);
484 OUString
GetExpandedFormula() const;
487 #endif // INCLUDED_SW_INC_FLDBAS_HXX
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */