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 <com/sun/star/beans/XPropertySet.hpp>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <cppuhelper/weakref.hxx>
28 #include <editeng/svxenum.hxx>
33 class SvNumberFormatter
;
35 enum class SwFieldIds
: sal_uInt16
{
36 /// For old documents the Field-Which IDs must be preserved !!!
79 Unknown
= USHRT_MAX
, // used as default value in some method calls
82 /// List of FieldTypes at UI.
83 enum SwFieldTypesEnum
{
85 TYP_DATEFLD
= TYP_BEGIN
, // 0
115 TYP_EXTUSERFLD
, // 30
130 enum SwAttrFieldTYpe
{
139 enum SwFileNameFormat
{
152 VVF_CMD
= 0x0010, ///< Show command.
153 VVF_INVISIBLE
= 0x0040, ///< Invisible.
154 VVF_XXP
= 0x0400, ///< 1234%
155 VVF_XX_XXP
= 0x0800, ///< 1.234,56%
158 // From here new formats:
159 VVF_SYS
= 0x2000, ///< Format for numbers from system.
160 VVF_X
= 0x2100, ///< 1234
161 VVF_X_X
= 0x2200, ///< 1234.5
162 VVF_X_XX
= 0x2300, ///< 1245.56
163 VVF_XX_X
= 0x2400, ///< 1.234.5
164 VVF_XX_XX
= 0x2500, ///< 1.234.56
165 VVF_XX_XXX
= 0x2600, ///< 1.234.567
166 VVF_SYS_CUR
= 0x2700, ///< Format for currency from system.
167 VVF_CUR_X
= 0x2800, ///< EUR 1234
168 VVF_CUR_XX_XX
= 0x2900, ///< EUR 1234.56 EUR 1234.00
169 VVF_CUR_XX_X0
= 0x2a00, ///< EUR 1234.56 EUR 1234.--
170 VVF_X_CUR
= 0x2b00, ///< 1234 EUR
171 VVF_XX_XX_CUR
= 0x2c00, ///< 1234.56 EUR 1234.00 EUR
172 VVF_XX_X0_CUR
= 0x2d00, ///< 1234.56 EUR 1234.-- EUR
175 VF_INVISIBLE
= VVF_INVISIBLE
,
177 VF_XX_XXP
= VVF_XX_XXP
,
178 VF_VISIBLE
= VVF_SYS
,
180 VF_XX_XX
= VVF_XX_XX
,
181 VF_XX_XX_CUR
= VVF_SYS_CUR
,
186 typedef sal_uInt16 SwGetSetExpType
;
187 namespace nsSwGetSetExpType
189 const SwGetSetExpType GSE_STRING
= 0x0001; ///< String
190 const SwGetSetExpType GSE_EXPR
= 0x0002; ///< Expression
191 const SwGetSetExpType GSE_INP
= 0x0004; ///< InputField
192 const SwGetSetExpType GSE_SEQ
= 0x0008; ///< Sequence
193 const SwGetSetExpType GSE_FORMULA
= 0x0010; ///< Formula
196 typedef sal_uInt16 SwExtendedSubType
;
197 namespace nsSwExtendedSubType
199 const SwExtendedSubType SUB_CMD
= 0x0100; ///< Show command.
200 const SwExtendedSubType SUB_INVISIBLE
= 0x0200; ///< Invisible.
201 const SwExtendedSubType SUB_OWN_FMT
= 0x0400; ///< SwDBField: Don't accept formatting from database.
204 enum SwInputFieldSubType
{
215 enum SwDateTimeSubType
{
222 OUString
FormatNumber(sal_uInt32 nNum
, SvxNumType nFormat
);
224 /** Instances of SwFields and those derived from it occur 0 to n times.
225 For each class there is one instance of the associated type class.
226 Base class of all field types is SwFieldType. */
228 class SW_DLLPUBLIC SwFieldType
: public SwModify
230 css::uno::WeakReference
<css::beans::XPropertySet
> m_wXFieldMaster
;
234 friend void FinitUI(); ///< In order to delete pointer!
235 static std::vector
<OUString
>* s_pFieldNames
;
237 static void GetFieldName_(); ///< Sets up FieldNames; fldmgr.cxx!
240 /// Single argument ctors shall be explicit.
241 explicit SwFieldType( SwFieldIds nWhichId
);
245 SAL_DLLPRIVATE
css::uno::WeakReference
<css::beans::XPropertySet
> const& GetXObject() const {
246 return m_wXFieldMaster
;
248 SAL_DLLPRIVATE
void SetXObject(css::uno::Reference
<css::beans::XPropertySet
> const& xFieldMaster
) {
249 m_wXFieldMaster
= xFieldMaster
;
252 static OUString
GetTypeStr( sal_uInt16 nTypeId
);
254 /// Only in derived classes.
255 virtual OUString
GetName() const;
256 virtual SwFieldType
* Copy() const = 0;
257 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const;
258 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
);
260 SwFieldIds
Which() const { return m_nWhich
; }
262 inline void UpdateFields() const;
265 inline void SwFieldType::UpdateFields() const
267 const_cast<SwFieldType
*>(this)->ModifyNotification( nullptr, nullptr );
270 /** Base class of all fields.
271 Type of field is queried via Which.
272 Expanded content of field is queried via Expand(). */
273 class SW_DLLPUBLIC SwField
276 mutable OUString m_Cache
; ///< Cached expansion (for clipboard).
277 bool m_bUseFieldValueCache
; /// control the usage of the cached field value
278 LanguageType m_nLang
; ///< Always change via SetLanguage!
279 bool m_bIsAutomaticLanguage
;
280 sal_uInt32 m_nFormat
; /// this can be either SvxNumType or SwChapterFormat depending on the subtype
281 SwFieldType
* m_pType
;
283 virtual OUString
Expand() const = 0;
284 virtual SwField
* Copy() const = 0;
287 void SetFormat(sal_uInt32
const nSet
) {
291 SwField( SwFieldType
* pTyp
,
292 sal_uInt32 nFormat
= 0,
293 LanguageType nLang
= LANGUAGE_SYSTEM
,
294 bool m_bUseFieldValueCache
= true );
299 inline SwFieldType
* GetTyp() const;
301 /// Set new type (used for copying among documents).
302 virtual SwFieldType
* ChgTyp( SwFieldType
* );
304 /** expand the field.
305 @param bCached return cached field value.
306 @remark most callers should use the cached field value.
307 this is because various fields need special handing
308 (ChangeExpansion()) to return correct values, and only
309 SwTextFormatter::NewFieldPortion() sets things up properly.
310 @return the generated text (suitable for display)
312 OUString
ExpandField(bool const bCached
) const;
314 /// @return name or content.
315 virtual OUString
GetFieldName() const;
317 SwField
* CopyField() const;
320 SwFieldIds
Which() const
322 ; // implemented in fldbas.cxx
325 return m_pType
->Which();
330 sal_uInt16
GetTypeId() const;
331 virtual sal_uInt16
GetSubType() const;
332 virtual void SetSubType(sal_uInt16
);
334 /// Language at field position.
335 inline LanguageType
GetLanguage() const;
336 virtual void SetLanguage(LanguageType nLng
);
338 /// Query parameters for dialog and for BASIC.
339 inline sal_uInt32
GetFormat() const;
340 virtual OUString
GetPar1() const;
341 virtual OUString
GetPar2() const;
343 virtual OUString
GetFormula() const;
345 void ChangeFormat(sal_uInt32 n
);
346 virtual void SetPar1(const OUString
& rStr
);
347 virtual void SetPar2(const OUString
& rStr
);
349 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhichId
) const;
350 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhichId
);
352 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
353 bool HasClickHdl() const;
354 bool IsFixed() const;
356 bool IsAutomaticLanguage() const {
357 return m_bIsAutomaticLanguage
;
359 void SetAutomaticLanguage(bool const bSet
) {
360 m_bIsAutomaticLanguage
= bSet
;
363 virtual OUString
GetDescription() const;
364 /// Is this field clickable?
365 bool IsClickable() const;
366 virtual void dumpAsXml(struct _xmlTextWriter
* pWriter
) const;
369 inline SwFieldType
* SwField::GetTyp() const
374 inline sal_uInt32
SwField::GetFormat() const
379 inline LanguageType
SwField::GetLanguage() const
384 /// Fields containing values that have to be formatted via number formatter.
385 class SwValueFieldType
: public SwFieldType
389 bool m_bUseFormat
; ///< Use number formatter.
392 SwValueFieldType( SwDoc
* pDocPtr
, SwFieldIds nWhichId
);
393 SwValueFieldType( const SwValueFieldType
& rTyp
);
396 SwDoc
* GetDoc() const {
399 void SetDoc(SwDoc
* pNewDoc
) {
403 bool UseFormat() const {
406 void EnableFormat(bool bFormat
= true) {
407 m_bUseFormat
= bFormat
;
410 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const;
411 OUString
DoubleToString(const double &rVal
, LanguageType eLng
) const;
412 OUString
DoubleToString(const double &rVal
, sal_uInt32 nFormat
) const;
415 class SW_DLLPUBLIC SwValueField
: public SwField
421 SwValueField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, LanguageType nLang
= LANGUAGE_SYSTEM
, const double fVal
= 0.0 );
422 SwValueField( const SwValueField
& rField
);
425 virtual ~SwValueField() override
;
427 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
428 virtual void SetLanguage(LanguageType nLng
) override
;
430 SwDoc
* GetDoc() const {
431 return static_cast<const SwValueFieldType
*>(GetTyp())->GetDoc();
434 virtual double GetValue() const;
435 virtual void SetValue( const double& rVal
);
437 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, LanguageType nLng
) const {
438 return static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, nFormat
, nLng
);
441 static sal_uInt32
GetSystemFormat(SvNumberFormatter
* pFormatter
, sal_uInt32 nFormat
);
444 class SW_DLLPUBLIC SwFormulaField
: public SwValueField
450 SwFormulaField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
, const double fVal
= 0.0 );
451 SwFormulaField( const SwFormulaField
& rField
);
454 virtual OUString
GetFormula() const override
;
455 void SetFormula(const OUString
& rStr
);
457 void SetExpandedFormula(const OUString
& rStr
);
458 OUString
GetExpandedFormula() const;
461 #endif // INCLUDED_SW_INC_FLDBAS_HXX
463 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */