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>
31 class SvNumberFormatter
;
35 /// For old documents the Field-Which IDs must be preserved !!!
37 RES_DBFLD
= RES_FIELDS_BEGIN
,
74 RES_AUTHORITY
, ///< Table of authorities
80 /// List of FieldTypes at UI.
84 TYP_DATEFLD
= TYP_BEGIN
, // 0
114 TYP_EXTUSERFLD
, // 30
139 enum SwFileNameFormat
154 VVF_CMD
= 0x0010, ///< Show command.
155 VVF_INVISIBLE
= 0x0040, ///< Invisible.
156 VVF_XXP
= 0x0400, ///< 1234%
157 VVF_XX_XXP
= 0x0800, ///< 1.234,56%
160 // From here new formats:
161 VVF_SYS
= 0x2000, ///< Format for numbers from system.
162 VVF_X
= 0x2100, ///< 1234
163 VVF_X_X
= 0x2200, ///< 1234.5
164 VVF_X_XX
= 0x2300, ///< 1245.56
165 VVF_XX_X
= 0x2400, ///< 1.234.5
166 VVF_XX_XX
= 0x2500, ///< 1.234.56
167 VVF_XX_XXX
= 0x2600, ///< 1.234.567
168 VVF_SYS_CUR
= 0x2700, ///< Format for currency from system.
169 VVF_CUR_X
= 0x2800, ///< EUR 1234
170 VVF_CUR_XX_XX
= 0x2900, ///< EUR 1234.56 EUR 1234.00
171 VVF_CUR_XX_X0
= 0x2a00, ///< EUR 1234.56 EUR 1234.--
172 VVF_X_CUR
= 0x2b00, ///< 1234 EUR
173 VVF_XX_XX_CUR
= 0x2c00, ///< 1234.56 EUR 1234.00 EUR
174 VVF_XX_X0_CUR
= 0x2d00, ///< 1234.56 EUR 1234.-- EUR
177 VF_INVISIBLE
= VVF_INVISIBLE
,
179 VF_XX_XXP
= VVF_XX_XXP
,
180 VF_VISIBLE
= VVF_SYS
,
182 VF_XX_XX
= VVF_XX_XX
,
183 VF_XX_XX_CUR
= VVF_SYS_CUR
,
188 typedef sal_uInt16 SwGetSetExpType
;
189 namespace nsSwGetSetExpType
191 const SwGetSetExpType GSE_STRING
= 0x0001; ///< String
192 const SwGetSetExpType GSE_EXPR
= 0x0002; ///< Expression
193 const SwGetSetExpType GSE_INP
= 0x0004; ///< InputField
194 const SwGetSetExpType GSE_SEQ
= 0x0008; ///< Sequence
195 const SwGetSetExpType GSE_FORMULA
= 0x0010; ///< Formula
198 typedef sal_uInt16 SwExtendedSubType
;
199 namespace nsSwExtendedSubType
201 const SwExtendedSubType SUB_CMD
= 0x0100; ///< Show command.
202 const SwExtendedSubType SUB_INVISIBLE
= 0x0200; ///< Invisible.
203 const SwExtendedSubType SUB_OWN_FMT
= 0x0400; ///< SwDBField: Don't accept formatting from database.
206 enum SwInputFieldSubType
219 enum SwDateTimeSubType
227 OUString
GetResult(double nVal
, sal_uInt32 nNumFormat
, sal_uInt16 nLang
= LANGUAGE_SYSTEM
);
228 void SetErrorStr(const OUString
& rStr
);
229 OUString
FormatNumber(sal_uInt32 nNum
, sal_uInt32 nFormat
);
231 /** Instances of SwFields and those derived from it occur 0 to n times.
232 For each class there is one instance of the associated type class.
233 Base class of all field types is SwFieldType. */
235 class SW_DLLPUBLIC SwFieldType
: public SwModify
237 ::com::sun::star::uno::WeakReference
<
238 ::com::sun::star::beans::XPropertySet
> m_wXFieldMaster
;
242 friend void _FinitUI(); ///< In order to delete pointer!
243 static std::vector
<OUString
>* s_pFieldNames
;
245 static void _GetFieldName(); ///< Sets up FieldNames; fldmgr.cxx!
248 /// Single argument ctors shall be explicit.
249 explicit SwFieldType( sal_uInt16 nWhichId
);
253 SAL_DLLPRIVATE ::com::sun::star::uno::WeakReference
<
254 ::com::sun::star::beans::XPropertySet
> const& GetXObject() const
255 { return m_wXFieldMaster
; }
256 SAL_DLLPRIVATE
void SetXObject(::com::sun::star::uno::Reference
<
257 ::com::sun::star::beans::XPropertySet
> const& xFieldMaster
)
258 { m_wXFieldMaster
= xFieldMaster
; }
260 static OUString
GetTypeStr( sal_uInt16 nTypeId
);
262 /// Only in derived classes.
263 virtual OUString
GetName() const;
264 virtual SwFieldType
* Copy() const = 0;
265 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const;
266 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
);
268 sal_uInt16
Which() const { return m_nWhich
; }
270 inline void UpdateFields() const;
273 inline void SwFieldType::UpdateFields() const
275 const_cast<SwFieldType
*>(this)->ModifyNotification( 0, 0 );
278 /** Base class of all fields.
279 Type of field is queried via Which.
280 Expanded content of field is queried via Expand(). */
281 class SW_DLLPUBLIC SwField
284 mutable OUString m_Cache
; ///< Cached expansion (for clipboard).
285 bool m_bUseFieldValueCache
; /// control the usage of the cached field value
287 sal_uInt16 m_nLang
; ///< Always change via SetLanguage!
288 bool m_bIsAutomaticLanguage
;
289 sal_uInt32 m_nFormat
;
291 SwFieldType
* m_pType
;
293 virtual OUString
Expand() const = 0;
294 virtual SwField
* Copy() const = 0;
297 void SetFormat(sal_uInt32
const nSet
) { m_nFormat
= nSet
; }
299 SwField( SwFieldType
* pTyp
,
300 sal_uInt32 nFormat
= 0,
301 sal_uInt16 nLang
= LANGUAGE_SYSTEM
,
302 bool m_bUseFieldValueCache
= true );
307 inline SwFieldType
* GetTyp() const;
309 /// Set new type (used for copying among documents).
310 virtual SwFieldType
* ChgTyp( SwFieldType
* );
312 /** expand the field.
313 @param bCached return cached field value.
314 @remark most callers should use the cached field value.
315 this is because various fields need special handing
316 (ChangeExpansion()) to return correct values, and only
317 SwTextFormatter::NewFieldPortion() sets things up properly.
318 @return the generated text (suitable for display)
320 OUString
ExpandField(bool const bCached
, ToxAuthorityField eField
= AUTH_FIELD_IDENTIFIER
) const;
322 /// @return name or content.
323 virtual OUString
GetFieldName() const;
325 SwField
* CopyField() const;
328 sal_uInt16
Which() const
330 ; // implemented in fldbas.cxx
332 { return m_pType
->Which(); }
336 sal_uInt16
GetTypeId() const;
337 virtual sal_uInt16
GetSubType() const;
338 virtual void SetSubType(sal_uInt16
);
340 /// Language at field position.
341 inline sal_uInt16
GetLanguage() const;
342 virtual void SetLanguage(sal_uInt16 nLng
);
344 /// Query parameters for dialog and for BASIC.
345 inline sal_uInt32
GetFormat() const;
346 virtual OUString
GetPar1() const;
347 virtual OUString
GetPar2() const;
349 virtual OUString
GetFormula() const;
351 void ChangeFormat(sal_uInt32 n
);
352 virtual void SetPar1(const OUString
& rStr
);
353 virtual void SetPar2(const OUString
& rStr
);
355 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
) const;
356 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
);
358 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
359 bool HasClickHdl() const;
360 bool IsFixed() const;
362 bool IsAutomaticLanguage() const { return m_bIsAutomaticLanguage
;}
363 void SetAutomaticLanguage(bool const bSet
) {m_bIsAutomaticLanguage
= bSet
;}
365 virtual OUString
GetDescription() const;
366 /// Is this field clickable?
367 bool IsClickable() const;
370 inline SwFieldType
* SwField::GetTyp() const
373 inline sal_uInt32
SwField::GetFormat() const
374 { return m_nFormat
; }
376 inline sal_uInt16
SwField::GetLanguage() const
379 /// Fields containing values that have to be formatted via number formatter.
380 class SwValueFieldType
: public SwFieldType
384 bool m_bUseFormat
; ///< Use number formatter.
387 SwValueFieldType( SwDoc
* pDocPtr
, sal_uInt16 nWhichId
);
388 SwValueFieldType( const SwValueFieldType
& rTyp
);
391 inline SwDoc
* GetDoc() const { return m_pDoc
; }
392 inline void SetDoc(SwDoc
* pNewDoc
) { m_pDoc
= pNewDoc
; }
394 inline bool UseFormat() const { return m_bUseFormat
; }
395 inline void EnableFormat(bool bFormat
= true) { m_bUseFormat
= bFormat
; }
397 OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, sal_uInt16 nLng
=0) const;
398 OUString
DoubleToString(const double &rVal
, LanguageType eLng
) const;
399 OUString
DoubleToString(const double &rVal
, sal_uInt32 nFormat
) const;
402 class SW_DLLPUBLIC SwValueField
: public SwField
408 SwValueField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
= 0, sal_uInt16 nLang
= LANGUAGE_SYSTEM
, const double fVal
= 0.0 );
409 SwValueField( const SwValueField
& rField
);
412 virtual ~SwValueField();
414 virtual SwFieldType
* ChgTyp( SwFieldType
* ) SAL_OVERRIDE
;
415 virtual void SetLanguage(sal_uInt16 nLng
) SAL_OVERRIDE
;
417 inline SwDoc
* GetDoc() const { return static_cast<const SwValueFieldType
*>(GetTyp())->GetDoc(); }
419 virtual double GetValue() const;
420 virtual void SetValue( const double& rVal
);
422 inline OUString
ExpandValue(const double& rVal
, sal_uInt32 nFormat
, sal_uInt16 nLng
=0) const
423 { return static_cast<SwValueFieldType
*>(GetTyp())->ExpandValue(rVal
, nFormat
, nLng
); }
425 static sal_uInt32
GetSystemFormat(SvNumberFormatter
* pFormatter
, sal_uInt32 nFormat
);
428 class SW_DLLPUBLIC SwFormulaField
: public SwValueField
434 SwFormulaField( SwValueFieldType
* pFieldType
, sal_uInt32 nFormat
= 0, const double fVal
= 0.0 );
435 SwFormulaField( const SwFormulaField
& rField
);
438 virtual OUString
GetFormula() const SAL_OVERRIDE
;
439 void SetFormula(const OUString
& rStr
);
441 void SetExpandedFormula(const OUString
& rStr
);
442 OUString
GetExpandedFormula() const;
445 #endif // INCLUDED_SW_INC_FLDBAS_HXX
447 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */