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() override
;
43 virtual OUString
GetName() const override
;
44 virtual SwFieldType
* Copy() const override
;
46 void AddRef() { nRefCnt
++; }
49 const OUString
& GetColumnName() const {return sColumn
;}
50 const SwDBData
& GetDBData() const {return aDBData
;}
52 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
53 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) 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 override
;
68 virtual SwField
* Copy() const override
;
71 SwDBField(SwDBFieldType
*, sal_uLong nFormat
= 0);
72 virtual ~SwDBField() override
;
74 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
77 inline void SetExpansion(const OUString
& rStr
);
79 virtual sal_uInt16
GetSubType() const override
;
80 virtual void SetSubType(sal_uInt16 nType
) override
;
82 virtual OUString
GetFieldName() const 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.
92 void InitContent(const OUString
& rExpansion
);
94 inline void ChgBodyTextFlag( bool bIsInBody
);
96 bool IsInitialized() const { return bInitialized
; }
97 void ClearInitialized() { bInitialized
= false; }
98 void SetInitialized() { bInitialized
= true; }
101 virtual OUString
GetPar1() const override
;
103 /// access to the command string
104 void SetFieldCode(const OUString
& rStr
) { sFieldCode
= rStr
; }
107 const SwDBData
& GetDBData() const { return static_cast<SwDBFieldType
*>(GetTyp())->GetDBData(); }
108 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
109 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
111 static bool FormatValue( SvNumberFormatter
* pDocFormatter
, OUString
&aString
, sal_uInt32 nFormat
,
112 double &aNumber
, sal_Int32 nColumnType
, SwDBField
*pField
= nullptr );
115 inline void SwDBField::SetExpansion(const OUString
& rStr
)
118 /// set from UpdateExpFields (the Node-Position is known there)
119 inline void SwDBField::ChgBodyTextFlag( bool bIsInBody
)
120 { bIsInBodyText
= bIsInBody
; }
122 // Base class for all other database fields.
123 class SW_DLLPUBLIC SwDBNameInfField
: public SwField
129 const SwDBData
& GetDBData() const {return aDBData
;}
130 SwDBData
& GetDBData() {return aDBData
;}
132 SwDBNameInfField(SwFieldType
* pTyp
, const SwDBData
& rDBData
, sal_uLong nFormat
= 0);
136 const SwDBData
& GetRealDBData() const { return aDBData
; }
137 SwDBData
& GetRealDBData() { return aDBData
; }
139 SwDBData
GetDBData(SwDoc
* pDoc
);
140 void SetDBData(const SwDBData
& rDBData
);
142 virtual OUString
GetFieldName() const override
;
144 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
145 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
146 virtual sal_uInt16
GetSubType() const override
;
147 virtual void SetSubType(sal_uInt16 nType
) override
;
150 // Database field next record.
151 class SW_DLLPUBLIC SwDBNextSetFieldType
: public SwFieldType
154 SwDBNextSetFieldType();
156 virtual SwFieldType
* Copy() const override
;
159 // Next data record with condition.
160 class SW_DLLPUBLIC SwDBNextSetField
: public SwDBNameInfField
166 SwDBNextSetField( SwDBNextSetFieldType
*,
167 const OUString
& rCond
, const SwDBData
& rDBData
);
169 virtual OUString
Expand() const override
;
170 virtual SwField
* Copy() const override
;
172 void Evaluate(SwDoc
*);
173 inline void SetCondValid(bool bCond
);
174 inline bool IsCondValid() const;
177 virtual OUString
GetPar1() const override
;
178 virtual void SetPar1(const OUString
& rStr
) override
;
179 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
180 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
183 inline bool SwDBNextSetField::IsCondValid() const
184 { return bCondValid
; }
186 inline void SwDBNextSetField::SetCondValid(bool bCond
)
187 { bCondValid
= bCond
; }
189 // Database field next record.
190 class SwDBNumSetFieldType
: public SwFieldType
193 SwDBNumSetFieldType();
195 virtual SwFieldType
* Copy() const override
;
198 // Data record with number xxx.
199 // Number is in nFormat (bit of a misuse!)
200 class SwDBNumSetField
: public SwDBNameInfField
207 SwDBNumSetField(SwDBNumSetFieldType
*, const OUString
& rCond
, const OUString
& rDBNum
, const SwDBData
& rDBData
);
209 virtual OUString
Expand() const override
;
210 virtual SwField
* Copy() const override
;
212 inline bool IsCondValid() const;
213 inline void SetCondValid(bool bCond
);
214 void Evaluate(SwDoc
*);
217 virtual OUString
GetPar1() const override
;
218 virtual void SetPar1(const OUString
& rStr
) override
;
220 // Number of data record.
221 virtual OUString
GetPar2() const override
;
222 virtual void SetPar2(const OUString
& rStr
) override
;
224 // Number of data record is in nFormat!!
225 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
226 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
229 inline bool SwDBNumSetField::IsCondValid() const
230 { return bCondValid
; }
232 inline void SwDBNumSetField::SetCondValid(bool bCond
)
233 { bCondValid
= bCond
; }
236 class SwDBNameFieldType
: public SwFieldType
240 SwDBNameFieldType(SwDoc
*);
242 OUString
Expand() const;
243 virtual SwFieldType
* Copy() const override
;
247 class SW_DLLPUBLIC SwDBNameField
: public SwDBNameInfField
250 SwDBNameField(SwDBNameFieldType
*, const SwDBData
& rDBData
);
252 virtual OUString
Expand() const override
;
253 virtual SwField
* Copy() const override
;
254 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
255 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
258 // Number of data record.
259 class SW_DLLPUBLIC SwDBSetNumberFieldType
: public SwFieldType
262 SwDBSetNumberFieldType();
264 virtual SwFieldType
* Copy() const override
;
268 class SW_DLLPUBLIC SwDBSetNumberField
: public SwDBNameInfField
272 SwDBSetNumberField(SwDBSetNumberFieldType
*, const SwDBData
& rDBData
, sal_uLong nFormat
= 0);
274 virtual OUString
Expand() const override
;
275 virtual SwField
* Copy() const override
;
276 void Evaluate(SwDoc
*);
278 inline long GetSetNumber() const;
279 inline void SetSetNumber(long nNum
);
280 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
281 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
284 inline long SwDBSetNumberField::GetSetNumber() const
287 inline void SwDBSetNumberField::SetSetNumber(long nNum
)
290 #endif // INCLUDED_SW_INC_DBFLD_HXX
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */