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 .
22 #include <i18nlangtag/lang.h>
23 #include <tools/string.hxx>
26 #include <com/sun/star/uno/Any.hxx>
30 class SvNumberFormatter
;
34 /// For old documents the Field-Which IDs must be preserved !!!
36 RES_DBFLD
= RES_FIELDS_BEGIN
,
73 RES_AUTHORITY
, ///< Table of authorities
79 /// List of FieldTypes at UI.
83 TYP_DATEFLD
= TYP_BEGIN
, // 0
113 TYP_EXTUSERFLD
, // 30
130 enum SwFileNameFormat
145 VVF_CMD
= 0x0010, ///< Show command.
146 VVF_INVISIBLE
= 0x0040, ///< Invisible.
147 VVF_XXP
= 0x0400, ///< 1234%
148 VVF_XX_XXP
= 0x0800, ///< 1.234,56%
151 // From here new formats:
152 VVF_SYS
= 0x2000, ///< Format for numbers from system.
153 VVF_X
= 0x2100, ///< 1234
154 VVF_X_X
= 0x2200, ///< 1234.5
155 VVF_X_XX
= 0x2300, ///< 1245.56
156 VVF_XX_X
= 0x2400, ///< 1.234.5
157 VVF_XX_XX
= 0x2500, ///< 1.234.56
158 VVF_XX_XXX
= 0x2600, ///< 1.234.567
159 VVF_SYS_CUR
= 0x2700, ///< Format for currency from system.
160 VVF_CUR_X
= 0x2800, ///< EUR 1234
161 VVF_CUR_XX_XX
= 0x2900, ///< EUR 1234.56 EUR 1234.00
162 VVF_CUR_XX_X0
= 0x2a00, ///< EUR 1234.56 EUR 1234.--
163 VVF_X_CUR
= 0x2b00, ///< 1234 EUR
164 VVF_XX_XX_CUR
= 0x2c00, ///< 1234.56 EUR 1234.00 EUR
165 VVF_XX_X0_CUR
= 0x2d00, ///< 1234.56 EUR 1234.-- EUR
168 VF_INVISIBLE
= VVF_INVISIBLE
,
170 VF_XX_XXP
= VVF_XX_XXP
,
171 VF_VISIBLE
= VVF_SYS
,
173 VF_XX_XX
= VVF_XX_XX
,
174 VF_XX_XX_CUR
= VVF_SYS_CUR
,
179 typedef sal_uInt16 SwGetSetExpType
;
180 namespace nsSwGetSetExpType
182 const SwGetSetExpType GSE_STRING
= 0x0001; ///< String
183 const SwGetSetExpType GSE_EXPR
= 0x0002; ///< Expression
184 const SwGetSetExpType GSE_INP
= 0x0004; ///< InputField
185 const SwGetSetExpType GSE_SEQ
= 0x0008; ///< Sequence
186 const SwGetSetExpType GSE_FORMULA
= 0x0010; ///< Formula
189 typedef sal_uInt16 SwExtendedSubType
;
190 namespace nsSwExtendedSubType
192 const SwExtendedSubType SUB_CMD
= 0x0100; ///< Show command.
193 const SwExtendedSubType SUB_INVISIBLE
= 0x0200; ///< Invisible.
194 const SwExtendedSubType SUB_OWN_FMT
= 0x0400; ///< SwDBField: Don't accept formating from database.
197 enum SwInputFieldSubType
211 enum SwDateTimeSubType
219 extern sal_uInt16 aTypeTab
[];
222 String
GetResult(double nVal
, sal_uInt32 nNumFmt
, sal_uInt16 nLang
= LANGUAGE_SYSTEM
);
223 void SetErrorStr(const String
& rStr
);
224 String
FormatNumber(sal_uInt32 nNum
, sal_uInt32 nFormat
);
226 /** Instances of SwFields and those derived from it occur 0 to n times.
227 For each class there is one instance of the associated type class.
228 Base class of all field types is SwFieldType. */
230 class SW_DLLPUBLIC SwFieldType
: public SwModify
234 friend void _FinitUI(); ///< In order to delete pointer!
235 static std::vector
<String
>* pFldNames
;
237 static void _GetFldName(); ///< Sets up FldNames; fldmgr.cxx!
240 /// Single argument ctors shall be explicit.
241 explicit SwFieldType( sal_uInt16 nWhichId
);
245 static const String
& GetTypeStr( sal_uInt16 nTypeId
);
247 /// Only in derived classes.
248 virtual const OUString
& GetName() const;
249 virtual SwFieldType
* Copy() const = 0;
250 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const;
251 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
);
253 sal_uInt16
Which() const { return nWhich
; }
255 inline void UpdateFlds() const;
258 inline void SwFieldType::UpdateFlds() const
260 ((SwFieldType
*)this)->ModifyNotification( 0, 0 );
263 /** Base class of all fields.
264 Type of field is queried via Which.
265 Expanded content of field is queried via Expand(). */
266 class SW_DLLPUBLIC SwField
269 mutable String m_Cache
; ///< Cached expansion (for clipboard).
270 sal_uInt16 nLang
; ///< Always change via SetLanguage!
271 sal_Bool bIsAutomaticLanguage
;
276 virtual String
Expand() const = 0;
277 virtual SwField
* Copy() const = 0;
280 void SetFormat(sal_uInt32 nSet
) {nFormat
= nSet
;}
282 SwField(SwFieldType
* pTyp
, sal_uInt32 nFmt
= 0, sal_uInt16 nLang
= LANGUAGE_SYSTEM
);
287 inline SwFieldType
* GetTyp() const;
289 /// Set new type (used for copying among documents).
290 virtual SwFieldType
* ChgTyp( SwFieldType
* );
292 /** expand the field.
293 @param bCached return cached field value.
294 @remark most callers should use the cached field value.
295 this is because various fields need special handing
296 (ChangeExpansion()) to return correct values, and only
297 SwTxtFormatter::NewFldPortion() sets things up properly.
298 @return the generated text (suitable for display)
300 String
ExpandField(bool const bCached
) const;
302 /// @return name or content.
303 virtual String
GetFieldName() const;
305 SwField
* CopyField() const;
308 sal_uInt16
Which() const
310 ; // implemented in fldbas.cxx
312 { return pType
->Which(); }
316 sal_uInt16
GetTypeId() const;
317 virtual sal_uInt16
GetSubType() const;
318 virtual void SetSubType(sal_uInt16
);
320 /// Language at field position.
321 inline sal_uInt16
GetLanguage() const;
322 virtual void SetLanguage(sal_uInt16 nLng
);
324 /// Query parameters for dialog and for BASIC.
325 inline sal_uInt32
GetFormat() const;
326 virtual const OUString
& GetPar1() const;
327 virtual OUString
GetPar2() const;
329 virtual String
GetFormula() const;
331 virtual void ChangeFormat(sal_uInt32 n
);
332 virtual void SetPar1(const OUString
& rStr
);
333 virtual void SetPar2(const OUString
& rStr
);
335 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
) const;
336 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhichId
);
338 /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
339 sal_Bool
HasClickHdl() const;
340 sal_Bool
IsFixed() const;
342 sal_Bool
IsAutomaticLanguage() const { return bIsAutomaticLanguage
;}
343 void SetAutomaticLanguage(sal_Bool bSet
){bIsAutomaticLanguage
= bSet
;}
345 virtual String
GetDescription() const;
346 /// Is this field clickable?
347 bool IsClickable() const;
350 inline SwFieldType
* SwField::GetTyp() const
353 inline sal_uInt32
SwField::GetFormat() const
356 inline sal_uInt16
SwField::GetLanguage() const
360 /// Fields containing values that have to be formated via number formatter.
361 class SwValueFieldType
: public SwFieldType
364 sal_Bool bUseFormat
; ///< Use number formatter.
367 SwValueFieldType( SwDoc
* pDocPtr
, sal_uInt16 nWhichId
);
368 SwValueFieldType( const SwValueFieldType
& rTyp
);
371 inline SwDoc
* GetDoc() const { return pDoc
; }
372 inline void SetDoc(SwDoc
* pNewDoc
) { pDoc
= pNewDoc
; }
374 inline sal_Bool
UseFormat() const { return bUseFormat
; }
375 inline void EnableFormat(sal_Bool bFormat
= sal_True
) { bUseFormat
= bFormat
; }
377 String
ExpandValue(const double& rVal
, sal_uInt32 nFmt
, sal_uInt16 nLng
=0) const;
378 void DoubleToString(String
&rValue
, const double &rVal
, LanguageType eLng
) const;
379 void DoubleToString(String
&rValue
, const double &rVal
, sal_uInt32 nFmt
) const;
382 class SW_DLLPUBLIC SwValueField
: public SwField
387 SwValueField( SwValueFieldType
* pFldType
, sal_uInt32 nFmt
= 0, sal_uInt16 nLang
= LANGUAGE_SYSTEM
, const double fVal
= 0.0 );
388 SwValueField( const SwValueField
& rFld
);
391 virtual ~SwValueField();
393 virtual SwFieldType
* ChgTyp( SwFieldType
* );
394 virtual void SetLanguage(sal_uInt16 nLng
);
396 inline SwDoc
* GetDoc() const { return ((SwValueFieldType
*)GetTyp())->GetDoc(); }
398 virtual double GetValue() const;
399 virtual void SetValue( const double& rVal
);
401 inline String
ExpandValue(const double& rVal
, sal_uInt32 nFmt
, sal_uInt16 nLng
=0) const
402 { return ((SwValueFieldType
*)GetTyp())->ExpandValue(rVal
, nFmt
, nLng
); }
404 static sal_uInt32
GetSystemFormat(SvNumberFormatter
* pFormatter
, sal_uInt32 nFmt
);
407 class SW_DLLPUBLIC SwFormulaField
: public SwValueField
412 SwFormulaField( SwValueFieldType
* pFldType
, sal_uInt32 nFmt
= 0, const double fVal
= 0.0 );
413 SwFormulaField( const SwFormulaField
& rFld
);
416 virtual String
GetFormula() const;
417 void SetFormula(const String
& rStr
);
419 void SetExpandedFormula(const String
& rStr
);
420 String
GetExpandedFormula() const;
423 #endif // SW_FLDBAS_HXX
425 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */