Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_SW_INC_FLDBAS_HXX
20 : #define INCLUDED_SW_INC_FLDBAS_HXX
21 :
22 : #include <i18nlangtag/lang.h>
23 : #include "swdllapi.h"
24 : #include <calbck.hxx>
25 : #include <com/sun/star/beans/XPropertySet.hpp>
26 : #include <com/sun/star/uno/Any.hxx>
27 : #include <cppuhelper/weakref.hxx>
28 : #include <vector>
29 : #include <toxe.hxx>
30 : class SwDoc;
31 : class SvNumberFormatter;
32 :
33 : enum RES_FIELDS
34 : {
35 : /// For old documents the Field-Which IDs must be preserved !!!
36 : RES_FIELDS_BEGIN,
37 : RES_DBFLD = RES_FIELDS_BEGIN,
38 : RES_USERFLD,
39 : RES_FILENAMEFLD,
40 : RES_DBNAMEFLD,
41 : RES_DATEFLD,
42 : RES_TIMEFLD,
43 : RES_PAGENUMBERFLD,
44 : RES_AUTHORFLD,
45 : RES_CHAPTERFLD,
46 : RES_DOCSTATFLD,
47 : RES_GETEXPFLD,
48 : RES_SETEXPFLD,
49 : RES_GETREFFLD,
50 : RES_HIDDENTXTFLD,
51 : RES_POSTITFLD,
52 : RES_FIXDATEFLD,
53 : RES_FIXTIMEFLD,
54 : RES_REGFLD,
55 : RES_VARREGFLD,
56 : RES_SETREFFLD,
57 : RES_INPUTFLD,
58 : RES_MACROFLD,
59 : RES_DDEFLD,
60 : RES_TABLEFLD,
61 : RES_HIDDENPARAFLD,
62 : RES_DOCINFOFLD,
63 : RES_TEMPLNAMEFLD,
64 : RES_DBNEXTSETFLD,
65 : RES_DBNUMSETFLD,
66 : RES_DBSETNUMBERFLD,
67 : RES_EXTUSERFLD,
68 : RES_REFPAGESETFLD,
69 : RES_REFPAGEGETFLD,
70 : RES_INTERNETFLD,
71 : RES_JUMPEDITFLD,
72 : RES_SCRIPTFLD,
73 : RES_DATETIMEFLD,
74 : RES_AUTHORITY, ///< Table of authorities
75 : RES_COMBINED_CHARS,
76 : RES_DROPDOWN,
77 : RES_FIELDS_END
78 : };
79 :
80 : /// List of FieldTypes at UI.
81 : enum SwFldTypesEnum
82 : {
83 : TYP_BEGIN,
84 : TYP_DATEFLD = TYP_BEGIN, // 0
85 : TYP_TIMEFLD,
86 : TYP_FILENAMEFLD,
87 : TYP_DBNAMEFLD,
88 : TYP_CHAPTERFLD,
89 : TYP_PAGENUMBERFLD,
90 : TYP_DOCSTATFLD,
91 : TYP_AUTHORFLD,
92 : TYP_SETFLD,
93 : TYP_GETFLD,
94 : TYP_FORMELFLD, // 10
95 : TYP_HIDDENTXTFLD,
96 : TYP_SETREFFLD,
97 : TYP_GETREFFLD,
98 : TYP_DDEFLD,
99 : TYP_MACROFLD,
100 : TYP_INPUTFLD,
101 : TYP_HIDDENPARAFLD,
102 : TYP_DOCINFOFLD,
103 : TYP_DBFLD,
104 : TYP_USERFLD, // 20
105 : TYP_POSTITFLD,
106 : TYP_TEMPLNAMEFLD,
107 : TYP_SEQFLD,
108 : TYP_DBNEXTSETFLD,
109 : TYP_DBNUMSETFLD,
110 : TYP_DBSETNUMBERFLD,
111 : TYP_CONDTXTFLD,
112 : TYP_NEXTPAGEFLD,
113 : TYP_PREVPAGEFLD,
114 : TYP_EXTUSERFLD, // 30
115 : TYP_FIXDATEFLD,
116 : TYP_FIXTIMEFLD,
117 : TYP_SETINPFLD,
118 : TYP_USRINPFLD,
119 : TYP_SETREFPAGEFLD,
120 : TYP_GETREFPAGEFLD,
121 : TYP_INTERNETFLD,
122 : TYP_JUMPEDITFLD,
123 : TYP_SCRIPTFLD,
124 : TYP_AUTHORITY, // 40
125 : TYP_COMBINED_CHARS,
126 : TYP_DROPDOWN,
127 : TYP_END
128 : };
129 : enum SwAttrFieldTYpe
130 : {
131 : ATTR_NONE,
132 : ATTR_DATEFLD,
133 : ATTR_TIMEFLD,
134 : ATTR_PAGENUMBERFLD,
135 : ATTR_PAGECOOUNTFLD,
136 : ATTR_BOOKMARKFLD,
137 : ATTR_SETREFATTRFLD
138 : };
139 : enum SwFileNameFormat
140 : {
141 : FF_BEGIN,
142 : FF_NAME = FF_BEGIN,
143 : FF_PATHNAME,
144 : FF_PATH,
145 : FF_NAME_NOEXT,
146 : FF_UI_NAME,
147 : FF_UI_RANGE,
148 : FF_END,
149 : FF_FIXED = 0x8000
150 : };
151 :
152 : enum SwVarFormat
153 : {
154 : VVF_CMD = 0x0010, ///< Show command.
155 : VVF_INVISIBLE = 0x0040, ///< Invisible.
156 : VVF_XXP = 0x0400, ///< 1234%
157 : VVF_XX_XXP = 0x0800, ///< 1.234,56%
158 : VVF_CLEAR = 0x000f,
159 :
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
175 : /// Compatibility:
176 : VF_CMD = VVF_CMD,
177 : VF_INVISIBLE = VVF_INVISIBLE,
178 : VF_XXP = VVF_XXP,
179 : VF_XX_XXP = VVF_XX_XXP,
180 : VF_VISIBLE = VVF_SYS,
181 : VF_XX = VVF_X,
182 : VF_XX_XX = VVF_XX_XX,
183 : VF_XX_XX_CUR = VVF_SYS_CUR,
184 : VF_CLEAR = VVF_CLEAR
185 :
186 : };
187 :
188 : typedef sal_uInt16 SwGetSetExpType;
189 : namespace nsSwGetSetExpType
190 : {
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
196 : }
197 :
198 : typedef sal_uInt16 SwExtendedSubType;
199 : namespace nsSwExtendedSubType
200 : {
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.
204 : }
205 :
206 : enum SwInputFieldSubType
207 : {
208 : INP_TXT = 0x01,
209 : INP_USR = 0x02,
210 : INP_VAR = 0x03
211 : };
212 :
213 : enum SwUserType
214 : {
215 : UF_STRING = 0x01,
216 : UF_EXPR = 0x02
217 : };
218 :
219 : enum SwDateTimeSubType
220 : {
221 : FIXEDFLD = 1,
222 : DATEFLD = 2,
223 : TIMEFLD = 4
224 : };
225 :
226 : /// General tools.
227 : OUString GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
228 : void SetErrorStr(const OUString& rStr);
229 : OUString FormatNumber(sal_uInt32 nNum, sal_uInt32 nFormat);
230 :
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. */
234 :
235 161836 : class SW_DLLPUBLIC SwFieldType : public SwModify
236 : {
237 : ::com::sun::star::uno::WeakReference<
238 : ::com::sun::star::beans::XPropertySet> m_wXFieldMaster;
239 :
240 : sal_uInt16 nWhich;
241 :
242 : friend void _FinitUI(); ///< In order to delete pointer!
243 : static std::vector<OUString>* pFldNames;
244 :
245 : static void _GetFldName(); ///< Sets up FldNames; fldmgr.cxx!
246 :
247 : protected:
248 : /// Single argument ctors shall be explicit.
249 : explicit SwFieldType( sal_uInt16 nWhichId );
250 :
251 : public:
252 :
253 : SAL_DLLPRIVATE ::com::sun::star::uno::WeakReference<
254 1820 : ::com::sun::star::beans::XPropertySet> const& GetXObject() const
255 1820 : { return m_wXFieldMaster; }
256 1820 : SAL_DLLPRIVATE void SetXObject(::com::sun::star::uno::Reference<
257 : ::com::sun::star::beans::XPropertySet> const& xFieldMaster)
258 1820 : { m_wXFieldMaster = xFieldMaster; }
259 :
260 : static OUString GetTypeStr( sal_uInt16 nTypeId );
261 :
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 );
267 :
268 1066734 : sal_uInt16 Which() const { return nWhich; }
269 :
270 : inline void UpdateFlds() const;
271 : };
272 :
273 32551 : inline void SwFieldType::UpdateFlds() const
274 : {
275 32551 : ((SwFieldType*)this)->ModifyNotification( 0, 0 );
276 32551 : }
277 :
278 : /** Base class of all fields.
279 : Type of field is queried via Which.
280 : Expanded content of field is queried via Expand(). */
281 8 : class SW_DLLPUBLIC SwField
282 : {
283 : private:
284 : mutable OUString m_Cache; ///< Cached expansion (for clipboard).
285 : bool m_bUseFieldValueCache; /// control the usage of the cached field value
286 :
287 : sal_uInt16 nLang; ///< Always change via SetLanguage!
288 : bool bIsAutomaticLanguage;
289 : sal_uInt32 nFormat;
290 :
291 : SwFieldType* pType;
292 :
293 : virtual OUString Expand() const = 0;
294 : virtual SwField* Copy() const = 0;
295 :
296 : protected:
297 222 : void SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
298 :
299 : SwField( SwFieldType* pTyp,
300 : sal_uInt32 nFmt = 0,
301 : sal_uInt16 nLang = LANGUAGE_SYSTEM,
302 : bool m_bUseFieldValueCache = true );
303 :
304 : public:
305 : virtual ~SwField();
306 :
307 : inline SwFieldType* GetTyp() const;
308 :
309 : /// Set new type (used for copying among documents).
310 : virtual SwFieldType* ChgTyp( SwFieldType* );
311 :
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 : SwTxtFormatter::NewFldPortion() sets things up properly.
318 : @return the generated text (suitable for display)
319 : */
320 : OUString ExpandField(bool const bCached, ToxAuthorityField eField = AUTH_FIELD_IDENTIFIER) const;
321 :
322 : OUString ExpandCitation(ToxAuthorityField eField = AUTH_FIELD_IDENTIFIER) const;
323 :
324 : /// @return name or content.
325 : virtual OUString GetFieldName() const;
326 :
327 : SwField * CopyField() const;
328 :
329 : /// ResId
330 2040 : sal_uInt16 Which() const
331 : #ifdef DBG_UTIL
332 : ; // implemented in fldbas.cxx
333 : #else
334 2040 : { return pType->Which(); }
335 : #endif
336 :
337 : // TYP_ID
338 : sal_uInt16 GetTypeId() const;
339 : virtual sal_uInt16 GetSubType() const;
340 : virtual void SetSubType(sal_uInt16);
341 :
342 : /// Language at field position.
343 : inline sal_uInt16 GetLanguage() const;
344 : virtual void SetLanguage(sal_uInt16 nLng);
345 :
346 : /// Query parameters for dialog and for BASIC.
347 : inline sal_uInt32 GetFormat() const;
348 : virtual OUString GetPar1() const;
349 : virtual OUString GetPar2() const;
350 :
351 : virtual OUString GetFormula() const;
352 :
353 : virtual void ChangeFormat(sal_uInt32 n);
354 : virtual void SetPar1(const OUString& rStr);
355 : virtual void SetPar2(const OUString& rStr);
356 :
357 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
358 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
359 :
360 : /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
361 : bool HasClickHdl() const;
362 : bool IsFixed() const;
363 :
364 1562 : bool IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
365 1990 : void SetAutomaticLanguage(bool bSet){bIsAutomaticLanguage = bSet;}
366 :
367 : virtual OUString GetDescription() const;
368 : /// Is this field clickable?
369 : bool IsClickable() const;
370 : };
371 :
372 350284 : inline SwFieldType* SwField::GetTyp() const
373 350284 : { return pType; }
374 :
375 21198 : inline sal_uInt32 SwField::GetFormat() const
376 21198 : { return nFormat; }
377 :
378 14052 : inline sal_uInt16 SwField::GetLanguage() const
379 14052 : { return nLang; }
380 :
381 : /// Fields containing values that have to be formated via number formatter.
382 40656 : class SwValueFieldType : public SwFieldType
383 : {
384 : SwDoc* pDoc;
385 : bool bUseFormat; ///< Use number formatter.
386 :
387 : protected:
388 : SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
389 : SwValueFieldType( const SwValueFieldType& rTyp );
390 :
391 : public:
392 1672 : inline SwDoc* GetDoc() const { return pDoc; }
393 140 : inline void SetDoc(SwDoc* pNewDoc) { pDoc = pNewDoc; }
394 :
395 72 : inline bool UseFormat() const { return bUseFormat; }
396 20966 : inline void EnableFormat(bool bFormat = true) { bUseFormat = bFormat; }
397 :
398 : OUString ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
399 : OUString DoubleToString(const double &rVal, LanguageType eLng) const;
400 : OUString DoubleToString(const double &rVal, sal_uInt32 nFmt) const;
401 : };
402 :
403 : class SW_DLLPUBLIC SwValueField : public SwField
404 : {
405 : double fValue;
406 :
407 : protected:
408 : SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
409 : SwValueField( const SwValueField& rFld );
410 :
411 : public:
412 : virtual ~SwValueField();
413 :
414 : virtual SwFieldType* ChgTyp( SwFieldType* ) SAL_OVERRIDE;
415 : virtual void SetLanguage(sal_uInt16 nLng) SAL_OVERRIDE;
416 :
417 788 : inline SwDoc* GetDoc() const { return ((SwValueFieldType*)GetTyp())->GetDoc(); }
418 :
419 : virtual double GetValue() const;
420 : virtual void SetValue( const double& rVal );
421 :
422 54 : inline OUString ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
423 54 : { return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
424 :
425 : static sal_uInt32 GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
426 : };
427 :
428 538 : class SW_DLLPUBLIC SwFormulaField : public SwValueField
429 : {
430 : OUString sFormula;
431 :
432 : protected:
433 : SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
434 : SwFormulaField( const SwFormulaField& rFld );
435 :
436 : public:
437 : virtual OUString GetFormula() const SAL_OVERRIDE;
438 : void SetFormula(const OUString& rStr);
439 :
440 : void SetExpandedFormula(const OUString& rStr);
441 : OUString GetExpandedFormula() const;
442 : };
443 :
444 : #endif // INCLUDED_SW_INC_FLDBAS_HXX
445 :
446 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|