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"
29 class SW_DLLPUBLIC SwDBFieldType final
: public SwValueFieldType
32 OUString m_sName
; ///< only used in ::GetName() !
38 SwDBFieldType(SwDoc
* pDocPtr
, const OUString
& rColumnName
, const SwDBData
& rDBData
);
39 virtual ~SwDBFieldType() override
;
41 virtual OUString
GetName() const override
;
42 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
44 void AddRef() { m_nRefCnt
++; }
47 const OUString
& GetColumnName() const {return m_sColumn
;}
48 const SwDBData
& GetDBData() const {return m_aDBData
;}
50 virtual void QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
51 virtual void PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
54 // Classes derived from SwFields. They overlay the expand-function.
55 // Content is formatted according to the format (if available).
56 class SW_DLLPUBLIC SwDBField final
: public SwValueField
59 OUString m_sFieldCode
; ///< contains Word's field code
60 sal_uInt16 m_nSubType
;
61 bool m_bIsInBodyText
: 1;
62 bool m_bValidValue
: 1;
63 bool m_bInitialized
: 1;
65 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
66 virtual std::unique_ptr
<SwField
> Copy() const override
;
69 SwDBField(SwDBFieldType
*, sal_uInt32 nFormat
= 0);
70 virtual ~SwDBField() override
;
72 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
75 inline void SetExpansion(const OUString
& rStr
);
77 virtual sal_uInt16
GetSubType() const override
;
78 virtual void SetSubType(sal_uInt16 nType
) override
;
80 virtual OUString
GetFieldName() const override
;
82 /// For calculations in expressions.
83 void ChgValue( double d
, bool bVal
);
85 /// Get the evaluation via DBManager string.
88 /// Evaluation for header and footer.
90 void InitContent(const OUString
& rExpansion
);
92 inline void ChgBodyTextFlag( bool bIsInBody
);
94 bool IsInitialized() const { return m_bInitialized
; }
95 void ClearInitialized() { m_bInitialized
= false; }
96 void SetInitialized() { m_bInitialized
= true; }
99 virtual OUString
GetPar1() const override
;
101 /// access to the command string
102 void SetFieldCode(const OUString
& rStr
) { m_sFieldCode
= rStr
; }
105 const SwDBData
& GetDBData() const { return static_cast<SwDBFieldType
*>(GetTyp())->GetDBData(); }
106 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
107 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
109 static bool FormatValue( SvNumberFormatter
const * pDocFormatter
, OUString
const &aString
, sal_uInt32 nFormat
,
110 double &aNumber
, sal_Int32 nColumnType
, SwDBField
*pField
= nullptr );
113 inline void SwDBField::SetExpansion(const OUString
& rStr
)
114 { m_aContent
= rStr
; }
116 /// set from UpdateExpFields (the Node-Position is known there)
117 inline void SwDBField::ChgBodyTextFlag( bool bIsInBody
)
118 { m_bIsInBodyText
= bIsInBody
; }
120 // Base class for all other database fields.
121 class SW_DLLPUBLIC SwDBNameInfField
: public SwField
124 sal_uInt16 m_nSubType
;
127 const SwDBData
& GetDBData() const {return m_aDBData
;}
128 SwDBData
& GetDBData() {return m_aDBData
;}
130 SwDBNameInfField(SwFieldType
* pTyp
, const SwDBData
& rDBData
, sal_uInt32 nFormat
= 0);
134 const SwDBData
& GetRealDBData() const { return m_aDBData
; }
135 SwDBData
& GetRealDBData() { return m_aDBData
; }
137 SwDBData
GetDBData(SwDoc
* pDoc
);
138 void SetDBData(const SwDBData
& rDBData
);
140 virtual OUString
GetFieldName() const override
;
142 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
143 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
144 virtual sal_uInt16
GetSubType() const override
;
145 virtual void SetSubType(sal_uInt16 nType
) override
;
148 // Database field next record.
149 class SW_DLLPUBLIC SwDBNextSetFieldType final
: public SwFieldType
152 SwDBNextSetFieldType();
154 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
157 // Next data record with condition.
158 class SW_DLLPUBLIC SwDBNextSetField final
: public SwDBNameInfField
164 SwDBNextSetField( SwDBNextSetFieldType
*,
165 const OUString
& rCond
, const SwDBData
& rDBData
);
167 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
168 virtual std::unique_ptr
<SwField
> Copy() const override
;
170 void Evaluate(SwDoc
const *);
171 inline void SetCondValid(bool bCond
);
172 inline bool IsCondValid() const;
175 virtual OUString
GetPar1() const override
;
176 virtual void SetPar1(const OUString
& rStr
) override
;
177 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
178 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
181 inline bool SwDBNextSetField::IsCondValid() const
182 { return m_bCondValid
; }
184 inline void SwDBNextSetField::SetCondValid(bool bCond
)
185 { m_bCondValid
= bCond
; }
187 // Database field next record.
188 class SwDBNumSetFieldType final
: public SwFieldType
191 SwDBNumSetFieldType();
193 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
196 // Data record with number xxx.
197 // Number is in nFormat (bit of a misuse!)
198 class SwDBNumSetField final
: public SwDBNameInfField
205 SwDBNumSetField(SwDBNumSetFieldType
*, const OUString
& rCond
, const OUString
& rDBNum
, const SwDBData
& rDBData
);
207 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
208 virtual std::unique_ptr
<SwField
> Copy() const override
;
210 inline bool IsCondValid() const;
211 inline void SetCondValid(bool bCond
);
212 void Evaluate(SwDoc
const *);
215 virtual OUString
GetPar1() const override
;
216 virtual void SetPar1(const OUString
& rStr
) override
;
218 // Number of data record.
219 virtual OUString
GetPar2() const override
;
220 virtual void SetPar2(const OUString
& rStr
) override
;
222 // Number of data record is in nFormat!!
223 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
224 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
227 inline bool SwDBNumSetField::IsCondValid() const
228 { return m_bCondValid
; }
230 inline void SwDBNumSetField::SetCondValid(bool bCond
)
231 { m_bCondValid
= bCond
; }
234 class SwDBNameFieldType final
: public SwFieldType
238 SwDBNameFieldType(SwDoc
*);
240 OUString
Expand() const;
241 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
245 class SwDBNameField final
: public SwDBNameInfField
248 SwDBNameField(SwDBNameFieldType
*, const SwDBData
& rDBData
);
250 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
251 virtual std::unique_ptr
<SwField
> Copy() const override
;
252 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
253 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
256 // Number of data record.
257 class SW_DLLPUBLIC SwDBSetNumberFieldType final
: public SwFieldType
260 SwDBSetNumberFieldType();
262 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
266 class SW_DLLPUBLIC SwDBSetNumberField final
: public SwDBNameInfField
270 SwDBSetNumberField(SwDBSetNumberFieldType
*, const SwDBData
& rDBData
, sal_uInt32 nFormat
= 0);
272 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
273 virtual std::unique_ptr
<SwField
> Copy() const override
;
274 void Evaluate(SwDoc
const *);
276 inline long GetSetNumber() const;
277 inline void SetSetNumber(long nNum
);
278 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
279 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
282 inline long SwDBSetNumberField::GetSetNumber() const
283 { return m_nNumber
; }
285 inline void SwDBSetNumberField::SetSetNumber(long nNum
)
286 { m_nNumber
= nNum
; }
288 #endif // INCLUDED_SW_INC_DBFLD_HXX
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */