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_DBFLD_HXX
20 #define INCLUDED_SW_INC_DBFLD_HXX
24 #include "swdbdata.hxx"
31 class SW_DLLPUBLIC SwDBFieldType
: public SwValueFieldType
34 OUString sName
; ///< only used in ::GetName() !
40 SwDBFieldType(SwDoc
* pDocPtr
, const OUString
& rColumnName
, const SwDBData
& rDBData
);
41 virtual ~SwDBFieldType();
43 virtual OUString
GetName() const SAL_OVERRIDE
;
44 virtual SwFieldType
* Copy() const SAL_OVERRIDE
;
46 inline void AddRef() { nRefCnt
++; }
49 OUString
GetColumnName() const {return sColumn
;}
50 const SwDBData
& GetDBData() const {return aDBData
;}
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
;
56 // Classes derived from SwFields. They overlay the expand-function.
57 // Content is formatted according to the format (if available).
58 class SW_DLLPUBLIC SwDBField
: public SwValueField
61 OUString sFieldCode
; ///< contains Word's field code
63 bool bIsInBodyText
: 1;
65 bool bInitialized
: 1;
67 virtual OUString
Expand() const SAL_OVERRIDE
;
68 virtual SwField
* Copy() const SAL_OVERRIDE
;
71 SwDBField(SwDBFieldType
*, sal_uLong nFormat
= 0);
74 virtual SwFieldType
* ChgTyp( SwFieldType
* ) SAL_OVERRIDE
;
77 inline void SetExpansion(const OUString
& rStr
);
79 virtual sal_uInt16
GetSubType() const SAL_OVERRIDE
;
80 virtual void SetSubType(sal_uInt16 nType
) SAL_OVERRIDE
;
82 virtual OUString
GetFieldName() const SAL_OVERRIDE
;
84 /// For calculations in expressions.
85 void ChgValue( double d
, bool bVal
);
87 /// Get the evaluation via DBManager string.
90 /// Evaluation for header and footer.
91 void ChangeExpansion( const SwFrm
*, const SwTextField
* );
93 void InitContent(const OUString
& rExpansion
);
95 inline void ChgBodyTextFlag( bool bIsInBody
);
97 inline bool IsInitialized() const { return bInitialized
; }
98 inline void ClearInitialized() { bInitialized
= false; }
99 inline void SetInitialized() { bInitialized
= true; }
102 virtual OUString
GetPar1() const SAL_OVERRIDE
;
104 /// access to the command string
105 OUString
GetFieldCode() const { return sFieldCode
;}
106 void SetFieldCode(const OUString
& rStr
) { sFieldCode
= rStr
; }
109 inline const SwDBData
& GetDBData() const { return static_cast<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
;
113 static bool FormatValue( SvNumberFormatter
* pDocFormatter
, OUString
&aString
, sal_uInt32 nFormat
,
114 double &aNumber
, sal_Int32 nColumnType
, SwDBField
*pField
= NULL
);
117 inline void SwDBField::SetExpansion(const OUString
& rStr
)
120 /// set from UpdateExpFields (the Node-Position is known there)
121 inline void SwDBField::ChgBodyTextFlag( bool bIsInBody
)
122 { bIsInBodyText
= bIsInBody
; }
124 // Base class for all other database fields.
125 class SW_DLLPUBLIC SwDBNameInfField
: public SwField
131 const SwDBData
& GetDBData() const {return aDBData
;}
132 SwDBData
& GetDBData() {return aDBData
;}
134 SwDBNameInfField(SwFieldType
* pTyp
, const SwDBData
& rDBData
, sal_uLong nFormat
= 0);
138 inline const SwDBData
& GetRealDBData() const { return aDBData
; }
139 inline SwDBData
& GetRealDBData() { return aDBData
; }
141 SwDBData
GetDBData(SwDoc
* pDoc
);
142 void SetDBData(const SwDBData
& rDBData
);
144 virtual OUString
GetFieldName() const SAL_OVERRIDE
;
146 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const SAL_OVERRIDE
;
147 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) SAL_OVERRIDE
;
148 virtual sal_uInt16
GetSubType() const SAL_OVERRIDE
;
149 virtual void SetSubType(sal_uInt16 nType
) SAL_OVERRIDE
;
152 // Database field next record.
153 class SW_DLLPUBLIC SwDBNextSetFieldType
: public SwFieldType
156 SwDBNextSetFieldType();
158 virtual SwFieldType
* Copy() const SAL_OVERRIDE
;
161 // Next data record with condition.
162 class SW_DLLPUBLIC SwDBNextSetField
: public SwDBNameInfField
168 SwDBNextSetField( SwDBNextSetFieldType
*,
169 const OUString
& rCond
, const OUString
& rDummy
, const SwDBData
& rDBData
);
171 virtual OUString
Expand() const SAL_OVERRIDE
;
172 virtual SwField
* Copy() const SAL_OVERRIDE
;
174 void Evaluate(SwDoc
*);
175 inline void SetCondValid(bool bCond
);
176 inline bool IsCondValid() const;
179 virtual OUString
GetPar1() const SAL_OVERRIDE
;
180 virtual void SetPar1(const OUString
& rStr
) SAL_OVERRIDE
;
181 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const SAL_OVERRIDE
;
182 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) SAL_OVERRIDE
;
185 inline bool SwDBNextSetField::IsCondValid() const
186 { return bCondValid
; }
188 inline void SwDBNextSetField::SetCondValid(bool bCond
)
189 { bCondValid
= bCond
; }
191 // Database field next record.
192 class SwDBNumSetFieldType
: public SwFieldType
195 SwDBNumSetFieldType();
197 virtual SwFieldType
* Copy() const SAL_OVERRIDE
;
200 // Data record with number xxx.
201 // Number is in nFormat (bit of a misuse!)
202 class SwDBNumSetField
: public SwDBNameInfField
209 SwDBNumSetField(SwDBNumSetFieldType
*, const OUString
& rCond
, const OUString
& rDBNum
, const SwDBData
& rDBData
);
211 virtual OUString
Expand() const SAL_OVERRIDE
;
212 virtual SwField
* Copy() const SAL_OVERRIDE
;
214 inline bool IsCondValid() const;
215 inline void SetCondValid(bool bCond
);
216 void Evaluate(SwDoc
*);
219 virtual OUString
GetPar1() const SAL_OVERRIDE
;
220 virtual void SetPar1(const OUString
& rStr
) SAL_OVERRIDE
;
222 // Number of data record.
223 virtual OUString
GetPar2() const SAL_OVERRIDE
;
224 virtual void SetPar2(const OUString
& rStr
) SAL_OVERRIDE
;
226 // Number of data record is in nFormat!!
227 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const SAL_OVERRIDE
;
228 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) SAL_OVERRIDE
;
231 inline bool SwDBNumSetField::IsCondValid() const
232 { return bCondValid
; }
234 inline void SwDBNumSetField::SetCondValid(bool bCond
)
235 { bCondValid
= bCond
; }
238 class SwDBNameFieldType
: public SwFieldType
242 SwDBNameFieldType(SwDoc
*);
244 OUString
Expand(sal_uLong
) const;
245 virtual SwFieldType
* Copy() const SAL_OVERRIDE
;
249 class SW_DLLPUBLIC SwDBNameField
: public SwDBNameInfField
252 SwDBNameField(SwDBNameFieldType
*, const SwDBData
& rDBData
, sal_uLong nFormat
= 0);
254 virtual OUString
Expand() const SAL_OVERRIDE
;
255 virtual SwField
* Copy() const SAL_OVERRIDE
;
256 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const SAL_OVERRIDE
;
257 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) SAL_OVERRIDE
;
260 // Number of data record.
261 class SW_DLLPUBLIC SwDBSetNumberFieldType
: public SwFieldType
264 SwDBSetNumberFieldType();
266 virtual SwFieldType
* Copy() const SAL_OVERRIDE
;
270 class SW_DLLPUBLIC SwDBSetNumberField
: public SwDBNameInfField
274 SwDBSetNumberField(SwDBSetNumberFieldType
*, const SwDBData
& rDBData
, sal_uLong nFormat
= 0);
276 virtual OUString
Expand() const SAL_OVERRIDE
;
277 virtual SwField
* Copy() const SAL_OVERRIDE
;
278 void Evaluate(SwDoc
*);
280 inline long GetSetNumber() const;
281 inline void SetSetNumber(long nNum
);
282 virtual bool QueryValue( com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) const SAL_OVERRIDE
;
283 virtual bool PutValue( const com::sun::star::uno::Any
& rVal
, sal_uInt16 nWhich
) SAL_OVERRIDE
;
286 inline long SwDBSetNumberField::GetSetNumber() const
289 inline void SwDBSetNumberField::SetSetNumber(long nNum
)
292 #endif // INCLUDED_SW_INC_DBFLD_HXX
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */