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_DBFLD_HXX
20 : #define INCLUDED_SW_INC_DBFLD_HXX
21 :
22 : #include "swdllapi.h"
23 : #include "fldbas.hxx"
24 : #include "swdbdata.hxx"
25 :
26 : class SwDoc;
27 : class SwTxtFld;
28 : class SwFrm;
29 :
30 : // Database field.
31 : class SW_DLLPUBLIC SwDBFieldType : public SwValueFieldType
32 : {
33 : SwDBData aDBData;
34 : OUString sName; ///< only used in ::GetName() !
35 : OUString sColumn;
36 : long nRefCnt;
37 :
38 : public:
39 :
40 : SwDBFieldType(SwDoc* pDocPtr, const OUString& rColumnName, const SwDBData& rDBData);
41 : virtual ~SwDBFieldType();
42 :
43 : virtual OUString GetName() const SAL_OVERRIDE;
44 : virtual SwFieldType* Copy() const SAL_OVERRIDE;
45 :
46 324 : inline void AddRef() { nRefCnt++; }
47 : void ReleaseRef();
48 :
49 282 : OUString GetColumnName() const {return sColumn;}
50 100 : const SwDBData& GetDBData() const {return aDBData;}
51 :
52 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
53 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
54 : };
55 :
56 : // Classes derived from SwFields. They overlay the expand-function.
57 : // Content is formated according to the format (if available).
58 : class SW_DLLPUBLIC SwDBField : public SwValueField
59 : {
60 : OUString aContent;
61 : OUString sFieldCode; ///< contains Word's field code
62 : sal_uInt16 nSubType;
63 : bool bIsInBodyTxt : 1;
64 : bool bValidValue : 1;
65 : bool bInitialized : 1;
66 :
67 : virtual OUString Expand() const SAL_OVERRIDE;
68 : virtual SwField* Copy() const SAL_OVERRIDE;
69 :
70 : public:
71 : SwDBField(SwDBFieldType*, sal_uLong nFmt = 0);
72 : virtual ~SwDBField();
73 :
74 : virtual SwFieldType* ChgTyp( SwFieldType* ) SAL_OVERRIDE;
75 :
76 : /// Current text.
77 : inline void SetExpansion(const OUString& rStr);
78 :
79 : virtual sal_uInt16 GetSubType() const SAL_OVERRIDE;
80 : virtual void SetSubType(sal_uInt16 nType) SAL_OVERRIDE;
81 :
82 : virtual OUString GetFieldName() const SAL_OVERRIDE;
83 :
84 : /// For calculations in expressions.
85 : void ChgValue( double d, bool bVal );
86 :
87 : /// Get the evaluation via DBManager string.
88 : void Evaluate();
89 :
90 : /// Evaluation for header and footer.
91 : void ChangeExpansion( const SwFrm*, const SwTxtFld* );
92 : void InitContent();
93 : void InitContent(const OUString& rExpansion);
94 :
95 : inline void ChgBodyTxtFlag( bool bIsInBody );
96 :
97 298 : inline bool IsInitialized() const { return bInitialized; }
98 0 : inline void ClearInitialized() { bInitialized = false; }
99 0 : inline void SetInitialized() { bInitialized = true; }
100 :
101 : /// Get name.
102 : virtual OUString GetPar1() const SAL_OVERRIDE;
103 :
104 : /// access to the command string
105 : OUString GetFieldCode() const { return sFieldCode;}
106 0 : void SetFieldCode(const OUString& rStr) { sFieldCode = rStr; }
107 :
108 : /// DBName
109 100 : inline const SwDBData& GetDBData() const { return ((SwDBFieldType*)GetTyp())->GetDBData(); }
110 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
111 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
112 :
113 : static bool FormatValue( SvNumberFormatter* pDocFormatter, OUString &aString, sal_uInt32 nFmt,
114 : double &aNumber, sal_Int32 nColumnType, SwDBField *pField = NULL );
115 : };
116 :
117 42 : inline void SwDBField::SetExpansion(const OUString& rStr)
118 42 : { aContent = rStr; }
119 :
120 : /// set from UpdateExpFlds (the Node-Position is known there)
121 142 : inline void SwDBField::ChgBodyTxtFlag( bool bIsInBody )
122 142 : { bIsInBodyTxt = bIsInBody; }
123 :
124 : // Base class for all other database fields.
125 0 : class SW_DLLPUBLIC SwDBNameInfField : public SwField
126 : {
127 : SwDBData aDBData;
128 : sal_uInt16 nSubType;
129 :
130 : protected:
131 0 : const SwDBData& GetDBData() const {return aDBData;}
132 0 : SwDBData& GetDBData() {return aDBData;}
133 :
134 : SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt = 0);
135 :
136 : public:
137 : /// DBName
138 0 : inline const SwDBData& GetRealDBData() { return aDBData; }
139 :
140 : SwDBData GetDBData(SwDoc* pDoc);
141 : void SetDBData(const SwDBData& rDBData);
142 :
143 : virtual OUString GetFieldName() const SAL_OVERRIDE;
144 :
145 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
146 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
147 : virtual sal_uInt16 GetSubType() const SAL_OVERRIDE;
148 : virtual void SetSubType(sal_uInt16 nType) SAL_OVERRIDE;
149 : };
150 :
151 : // Database field next record.
152 10090 : class SW_DLLPUBLIC SwDBNextSetFieldType : public SwFieldType
153 : {
154 : public:
155 : SwDBNextSetFieldType();
156 :
157 : virtual SwFieldType* Copy() const SAL_OVERRIDE;
158 : };
159 :
160 : // Next data record with condition.
161 0 : class SW_DLLPUBLIC SwDBNextSetField : public SwDBNameInfField
162 : {
163 : OUString aCond;
164 : bool bCondValid;
165 :
166 : public:
167 : SwDBNextSetField( SwDBNextSetFieldType*,
168 : const OUString& rCond, const OUString& rDummy, const SwDBData& rDBData);
169 :
170 : virtual OUString Expand() const SAL_OVERRIDE;
171 : virtual SwField* Copy() const SAL_OVERRIDE;
172 :
173 : void Evaluate(SwDoc*);
174 : inline void SetCondValid(bool bCond);
175 : inline bool IsCondValid() const;
176 :
177 : // Condition
178 : virtual OUString GetPar1() const SAL_OVERRIDE;
179 : virtual void SetPar1(const OUString& rStr) SAL_OVERRIDE;
180 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
181 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
182 : };
183 :
184 0 : inline bool SwDBNextSetField::IsCondValid() const
185 0 : { return bCondValid; }
186 :
187 0 : inline void SwDBNextSetField::SetCondValid(bool bCond)
188 0 : { bCondValid = bCond; }
189 :
190 : // Database field next record.
191 10090 : class SwDBNumSetFieldType : public SwFieldType
192 : {
193 : public:
194 : SwDBNumSetFieldType();
195 :
196 : virtual SwFieldType* Copy() const SAL_OVERRIDE;
197 : };
198 :
199 : // Data record with number xxx.
200 : // Number is in nFormat (bit of a misuse!)
201 0 : class SwDBNumSetField : public SwDBNameInfField
202 : {
203 : OUString aCond;
204 : OUString aPar2;
205 : bool bCondValid;
206 :
207 : public:
208 : SwDBNumSetField(SwDBNumSetFieldType*, const OUString& rCond, const OUString& rDBNum, const SwDBData& rDBData);
209 :
210 : virtual OUString Expand() const SAL_OVERRIDE;
211 : virtual SwField* Copy() const SAL_OVERRIDE;
212 :
213 : inline bool IsCondValid() const;
214 : inline void SetCondValid(bool bCond);
215 : void Evaluate(SwDoc*);
216 :
217 : // Condition
218 : virtual OUString GetPar1() const SAL_OVERRIDE;
219 : virtual void SetPar1(const OUString& rStr) SAL_OVERRIDE;
220 :
221 : // Number of data record.
222 : virtual OUString GetPar2() const SAL_OVERRIDE;
223 : virtual void SetPar2(const OUString& rStr) SAL_OVERRIDE;
224 :
225 : // Number of data record is in nFormat!!
226 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
227 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
228 : };
229 :
230 0 : inline bool SwDBNumSetField::IsCondValid() const
231 0 : { return bCondValid; }
232 :
233 0 : inline void SwDBNumSetField::SetCondValid(bool bCond)
234 0 : { bCondValid = bCond; }
235 :
236 : // Database name.
237 10090 : class SwDBNameFieldType : public SwFieldType
238 : {
239 : SwDoc *pDoc;
240 : public:
241 : SwDBNameFieldType(SwDoc*);
242 :
243 : OUString Expand(sal_uLong) const;
244 : virtual SwFieldType* Copy() const SAL_OVERRIDE;
245 : };
246 :
247 : // Database field.
248 0 : class SW_DLLPUBLIC SwDBNameField : public SwDBNameInfField
249 : {
250 : public:
251 : SwDBNameField(SwDBNameFieldType*, const SwDBData& rDBData, sal_uLong nFmt = 0);
252 :
253 : virtual OUString Expand() const SAL_OVERRIDE;
254 : virtual SwField* Copy() const SAL_OVERRIDE;
255 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
256 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
257 : };
258 :
259 : // Number of data record.
260 10090 : class SW_DLLPUBLIC SwDBSetNumberFieldType : public SwFieldType
261 : {
262 : public:
263 : SwDBSetNumberFieldType();
264 :
265 : virtual SwFieldType* Copy() const SAL_OVERRIDE;
266 : };
267 :
268 : // Database field.
269 0 : class SW_DLLPUBLIC SwDBSetNumberField : public SwDBNameInfField
270 : {
271 : long nNumber;
272 : public:
273 : SwDBSetNumberField(SwDBSetNumberFieldType*, const SwDBData& rDBData, sal_uLong nFmt = 0);
274 :
275 : virtual OUString Expand() const SAL_OVERRIDE;
276 : virtual SwField* Copy() const SAL_OVERRIDE;
277 : void Evaluate(SwDoc*);
278 :
279 : inline long GetSetNumber() const;
280 : inline void SetSetNumber(long nNum);
281 : virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const SAL_OVERRIDE;
282 : virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) SAL_OVERRIDE;
283 : };
284 :
285 0 : inline long SwDBSetNumberField::GetSetNumber() const
286 0 : { return nNumber; }
287 :
288 0 : inline void SwDBSetNumberField::SetSetNumber(long nNum)
289 0 : { nNumber = nNum; }
290 :
291 : #endif // INCLUDED_SW_INC_DBFLD_HXX
292 :
293 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|