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 <cppuhelper/weakref.hxx>
26 #include <editeng/svxenum.hxx>
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
; } } } }
36 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
38 enum class SwFieldIds
: sal_uInt16
{
39 /// For old documents the Field-Which IDs must be preserved !!!
80 ParagraphSignature
, // 40
81 LAST
= ParagraphSignature
,
83 Unknown
= USHRT_MAX
, // used as default value in some method calls
86 /// List of FieldTypes at UI.
87 enum class SwFieldTypesEnum
: sal_uInt16
{
132 Custom
, // Unused - necessary for alignment with aSwFields in fldmgr.cxx
135 Unknown
= USHRT_MAX
// used by SwFieldMgr::GetCurTypeId
137 enum SwAttrFieldType
{
146 enum SwFileNameFormat
{
159 VVF_CMD
= 0x0010, ///< Show command.
160 VVF_INVISIBLE
= 0x0040, ///< Invisible.
161 VVF_XXP
= 0x0400, ///< 1234%
162 VVF_XX_XXP
= 0x0800, ///< 1.234,56%
165 // From here new formats:
166 VVF_SYS
= 0x2000, ///< Format for numbers from system.
167 VVF_X
= 0x2100, ///< 1234
168 VVF_X_X
= 0x2200, ///< 1234.5
169 VVF_X_XX
= 0x2300, ///< 1245.56
170 VVF_XX_X
= 0x2400, ///< 1.234.5
171 VVF_XX_XX
= 0x2500, ///< 1.234.56
172 VVF_XX_XXX
= 0x2600, ///< 1.234.567
173 VVF_SYS_CUR
= 0x2700, ///< Format for currency from system.
174 VVF_CUR_X
= 0x2800, ///< EUR 1234
175 VVF_CUR_XX_XX
= 0x2900, ///< EUR 1234.56 EUR 1234.00
176 VVF_CUR_XX_X0
= 0x2a00, ///< EUR 1234.56 EUR 1234.--
177 VVF_X_CUR
= 0x2b00, ///< 1234 EUR
178 VVF_XX_XX_CUR
= 0x2c00, ///< 1234.56 EUR 1234.00 EUR
179 VVF_XX_X0_CUR
= 0x2d00, ///< 1234.56 EUR 1234.-- EUR
182 VF_INVISIBLE
= VVF_INVISIBLE
,
184 VF_XX_XXP
= VVF_XX_XXP
,
185 VF_VISIBLE
= VVF_SYS
,
187 VF_XX_XX
= VVF_XX_XX
,
188 VF_XX_XX_CUR
= VVF_SYS_CUR
,
193 typedef sal_uInt16 SwGetSetExpType
;
194 namespace nsSwGetSetExpType
196 const SwGetSetExpType GSE_STRING
= 0x0001; ///< String
197 const SwGetSetExpType GSE_EXPR
= 0x0002; ///< Expression
198 const SwGetSetExpType GSE_SEQ
= 0x0008; ///< Sequence
199 const SwGetSetExpType GSE_FORMULA
= 0x0010; ///< Formula
202 typedef sal_uInt16 SwExtendedSubType
;
203 namespace nsSwExtendedSubType
205 const SwExtendedSubType SUB_CMD
= 0x0100; ///< Show command.
206 const SwExtendedSubType SUB_INVISIBLE
= 0x0200; ///< Invisible.
207 const SwExtendedSubType SUB_OWN_FMT
= 0x0400; ///< SwDBField: Don't accept formatting from database.
210 enum SwInputFieldSubType
{
221 enum SwDateTimeSubType
{
228 OUString
FormatNumber(sal_uInt32 nNum
, SvxNumType nFormat
, LanguageType nLang
= LANGUAGE_NONE
);
230 /** Instances of SwFields and those derived from it occur 0 to n times.
231 For each class there is one instance of the associated type class.
232 Base class of all field types is SwFieldType. */
234 class SW_DLLPUBLIC SwFieldType
: public SwModify
, public sw::BroadcasterMixin
236 css::uno::WeakReference
<css::beans::XPropertySet
> m_wXFieldMaster
;
238 SwFieldIds
const m_nWhich
;
240 friend void FinitUI(); ///< In order to delete pointer!
241 static std::vector
<OUString
>* s_pFieldNames
;
243 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
246 /// Single argument ctors shall be explicit.
247 explicit SwFieldType( SwFieldIds nWhichId
);
251 SAL_DLLPRIVATE
css::uno::WeakReference
<css::beans::XPropertySet
> const& GetXObject() const {
252 return m_wXFieldMaster
;
254 SAL_DLLPRIVATE
void SetXObject(css::uno::Reference
<css::beans::XPropertySet
> const& xFieldMaster
) {
255 m_wXFieldMaster
= xFieldMaster
;
258 static OUString
GetTypeStr( SwFieldTypesEnum nTypeId
);
260 /// Only in derived classes.
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
);
266 SwFieldIds
Which() const { return m_nWhich
; }
268 inline void UpdateFields() const;
269 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
272 inline void SwFieldType::UpdateFields() const
274 const_cast<SwFieldType
*>(this)->ModifyNotification( nullptr, nullptr );
277 /** Base class of all fields.
278 Type of field is queried via Which.
279 Expanded content of field is queried via ExpandField(). */
280 class SW_DLLPUBLIC SwField
283 mutable OUString m_Cache
; ///< Cached expansion (for clipboard).
284 bool m_bUseFieldValueCache
; /// control the usage of the cached field value
285 LanguageType m_nLang
; ///< Always change via SetLanguage!
286 bool m_bIsAutomaticLanguage
;
287 sal_uInt32 m_nFormat
; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
288 SwFieldType
* m_pType
;
290 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const = 0;
291 virtual std::unique_ptr
<SwField
> Copy() const = 0;
294 void SetFormat(sal_uInt32
const nSet
) {
298 SwField( SwFieldType
* pTyp
,
299 sal_uInt32 nFormat
= 0,
300 LanguageType nLang
= LANGUAGE_SYSTEM
,
301 bool m_bUseFieldValueCache
= true );
306 SwField(SwField
const &) = default;
307 SwField(SwField
&&) = default;
308 SwField
& operator =(SwField
const &) = default;
309 SwField
& operator =(SwField
&&) = default;
311 inline SwFieldType
* GetTyp() const;
313 /// Set new type (used for copying among documents).
314 virtual SwFieldType
* ChgTyp( SwFieldType
* );
316 /** expand the field.
317 @param bCached return cached field value.
318 @remark most callers should use the cached field value.
319 this is because various fields need special handing
320 (ChangeExpansion()) to return correct values, and only
321 SwTextFormatter::NewFieldPortion() sets things up properly.
322 @param pLayout the layout to use for expansion; there are a few
323 fields that expand differently via layout mode.
324 @return the generated text (suitable for display)
326 OUString
ExpandField(bool bCached
, SwRootFrame
const* pLayout
) const;
328 /// @return name or content.
329 virtual OUString
GetFieldName() const;
331 std::unique_ptr
<SwField
> CopyField() const;
334 SwFieldIds
Which() const
336 ; // implemented in fldbas.cxx
339 return m_pType
->Which();
344 SwFieldTypesEnum
GetTypeId() const;
345 virtual sal_uInt16
GetSubType() const;
346 virtual void SetSubType(sal_uInt16
);
348 /// Language at field position.
349 inline LanguageType
GetLanguage() const;
350 virtual void SetLanguage(LanguageType nLng
);
352 /// Query parameters for dialog and for BASIC.
353 inline sal_uInt32
GetFormat() const;
354 virtual OUString
GetPar1() const;
355 virtual OUString
GetPar2() const;
357 virtual OUString
GetFormula() const;
359 void ChangeFormat(sal_uInt32 n
);
360 virtual void SetPar1(const OUString
& rStr
);
361 virtual void SetPar2(const OUString
& rStr
);
363 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const;
364 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
);
366 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
367 bool HasClickHdl() const;
368 bool IsFixed() const;
370 bool IsAutomaticLanguage() const {
371 return m_bIsAutomaticLanguage
;
373 void SetAutomaticLanguage(bool const bSet
) {
374 m_bIsAutomaticLanguage
= bSet
;
377 virtual OUString
GetDescription() const;
378 /// Is this field clickable?
379 bool IsClickable() const;
380 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const;
383 inline SwFieldType
* SwField::GetTyp() const
388 inline sal_uInt32
SwField::GetFormat() const
393 inline LanguageType
SwField::GetLanguage() const
398 /// Fields containing values that have to be formatted via number formatter.
399 class SwValueFieldType
: public SwFieldType
403 bool m_bUseFormat
; ///< Use number formatter.
406 SwValueFieldType( SwDoc
* pDocPtr
, SwFieldIds nWhichId
);
407 SwValueFieldType( const SwValueFieldType
& rTyp
);
410 SwDoc
* GetDoc() const {
413 void SetDoc(SwDoc
* pNewDoc
) {
417 bool UseFormat() const {
420 void EnableFormat(bool bFormat
= true) {
421 m_bUseFormat
= bFormat
;
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;
429 class SW_DLLPUBLIC SwValueField
: public SwField
435 SwValueField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, LanguageType nLang
= LANGUAGE_SYSTEM
, const double fVal
= 0.0 );
436 SwValueField( const SwValueField
& rField
);
439 virtual ~SwValueField() override
;
441 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
442 virtual void SetLanguage(LanguageType nLng
) override
;
444 SwDoc
* GetDoc() const {
445 return static_cast<const SwValueFieldType
*>(GetTyp())->GetDoc();
448 virtual double GetValue() const;
449 virtual void SetValue( const double& rVal
);
451 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const {
452 return static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, nFormat
, nLng
);
455 static sal_uInt32
GetSystemFormat(SvNumberFormatter
* pFormatter
, sal_uInt32 nFormat
);
456 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
459 class SW_DLLPUBLIC SwFormulaField
: public SwValueField
465 SwFormulaField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, const double fVal
);
466 SwFormulaField( const SwFormulaField
& rField
);
469 virtual OUString
GetFormula() const override
;
470 void SetFormula(const OUString
& rStr
);
472 void SetExpandedFormula(const OUString
& rStr
);
473 OUString
GetExpandedFormula() const;
476 #endif // INCLUDED_SW_INC_FLDBAS_HXX
478 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */