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() !
34 tools::Long m_nRefCnt
;
38 SwDBFieldType(SwDoc
* pDocPtr
, const OUString
& rColumnName
, SwDBData aDBData
);
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
;
52 virtual void UpdateFields() override
{};
55 // Classes derived from SwFields. They overlay the expand-function.
56 // Content is formatted according to the format (if available).
57 class SW_DLLPUBLIC SwDBField final
: public SwValueField
60 OUString m_sFieldCode
; ///< contains Word's field code
61 sal_uInt16 m_nSubType
;
62 bool m_bIsInBodyText
: 1;
63 bool m_bValidValue
: 1;
64 bool m_bInitialized
: 1;
66 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
67 virtual std::unique_ptr
<SwField
> Copy() const override
;
70 SwDBField(SwDBFieldType
*, sal_uInt32 nFormat
= 0);
71 virtual ~SwDBField() override
;
73 virtual SwFieldType
* ChgTyp( SwFieldType
* ) override
;
76 inline void SetExpansion(const OUString
& rStr
);
78 virtual sal_uInt16
GetSubType() const override
;
79 virtual void SetSubType(sal_uInt16 nType
) override
;
81 virtual OUString
GetFieldName() const override
;
83 /// For calculations in expressions.
84 void ChgValue( double d
, bool bVal
);
86 /// Get the evaluation via DBManager string.
89 /// Evaluation for header and footer.
91 void InitContent(const OUString
& rExpansion
);
93 inline void ChgBodyTextFlag( bool bIsInBody
);
95 bool IsInitialized() const { return m_bInitialized
; }
96 void ClearInitialized() { m_bInitialized
= false; }
97 void SetInitialized() { m_bInitialized
= true; }
100 virtual OUString
GetPar1() const override
;
102 /// access to the command string
103 void SetFieldCode(const OUString
& rStr
) { m_sFieldCode
= rStr
; }
106 const SwDBData
& GetDBData() const { return static_cast<SwDBFieldType
*>(GetTyp())->GetDBData(); }
107 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
108 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
110 static bool FormatValue( SvNumberFormatter
const * pDocFormatter
, OUString
const &aString
, sal_uInt32 nFormat
,
111 double &aNumber
, sal_Int32 nColumnType
, SwDBField
*pField
= nullptr );
114 inline void SwDBField::SetExpansion(const OUString
& rStr
)
115 { m_aContent
= rStr
; }
117 /// set from UpdateExpFields (the Node-Position is known there)
118 inline void SwDBField::ChgBodyTextFlag( bool bIsInBody
)
119 { m_bIsInBodyText
= bIsInBody
; }
121 // Base class for all other database fields.
122 class SW_DLLPUBLIC SwDBNameInfField
: public SwField
125 sal_uInt16 m_nSubType
;
128 const SwDBData
& GetDBData() const {return m_aDBData
;}
129 SwDBData
& GetDBData() {return m_aDBData
;}
131 SwDBNameInfField(SwFieldType
* pTyp
, SwDBData aDBData
, sal_uInt32 nFormat
= 0);
135 const SwDBData
& GetRealDBData() const { return m_aDBData
; }
136 SwDBData
& GetRealDBData() { return m_aDBData
; }
138 SwDBData
GetDBData(SwDoc
* pDoc
);
139 void SetDBData(const SwDBData
& rDBData
);
141 virtual OUString
GetFieldName() const override
;
143 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
144 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
145 virtual sal_uInt16
GetSubType() const override
;
146 virtual void SetSubType(sal_uInt16 nType
) override
;
149 // Database field next record.
150 class SW_DLLPUBLIC SwDBNextSetFieldType final
: public SwFieldType
153 SwDBNextSetFieldType();
155 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
158 // Next data record with condition.
159 class SW_DLLPUBLIC SwDBNextSetField final
: public SwDBNameInfField
165 SwDBNextSetField( SwDBNextSetFieldType
*,
166 OUString aCond
, const SwDBData
& rDBData
);
168 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
169 virtual std::unique_ptr
<SwField
> Copy() const override
;
171 void Evaluate(const SwDoc
&);
172 inline void SetCondValid(bool bCond
);
173 inline bool IsCondValid() const;
176 virtual OUString
GetPar1() const override
;
177 virtual void SetPar1(const OUString
& rStr
) override
;
178 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
179 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
182 inline bool SwDBNextSetField::IsCondValid() const
183 { return m_bCondValid
; }
185 inline void SwDBNextSetField::SetCondValid(bool bCond
)
186 { m_bCondValid
= bCond
; }
188 // Database field next record.
189 class SwDBNumSetFieldType final
: public SwFieldType
192 SwDBNumSetFieldType();
194 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
197 // Data record with number xxx.
198 // Number is in nFormat (bit of a misuse!)
199 class SwDBNumSetField final
: public SwDBNameInfField
206 SwDBNumSetField(SwDBNumSetFieldType
*, OUString aCond
, OUString aDBNum
, const SwDBData
& rDBData
);
208 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
209 virtual std::unique_ptr
<SwField
> Copy() const override
;
211 inline bool IsCondValid() const;
212 inline void SetCondValid(bool bCond
);
213 void Evaluate(const SwDoc
&);
216 virtual OUString
GetPar1() const override
;
217 virtual void SetPar1(const OUString
& rStr
) override
;
219 // Number of data record.
220 virtual OUString
GetPar2() const override
;
221 virtual void SetPar2(const OUString
& rStr
) override
;
223 // Number of data record is in nFormat!!
224 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
225 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
228 inline bool SwDBNumSetField::IsCondValid() const
229 { return m_bCondValid
; }
231 inline void SwDBNumSetField::SetCondValid(bool bCond
)
232 { m_bCondValid
= bCond
; }
235 class SwDBNameFieldType final
: public SwFieldType
239 SwDBNameFieldType(SwDoc
*);
241 OUString
Expand() const;
242 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
246 class SwDBNameField final
: public SwDBNameInfField
249 SwDBNameField(SwDBNameFieldType
*, const SwDBData
& rDBData
);
251 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
252 virtual std::unique_ptr
<SwField
> Copy() const override
;
253 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
254 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
257 // Number of data record.
258 class SW_DLLPUBLIC SwDBSetNumberFieldType final
: public SwFieldType
261 SwDBSetNumberFieldType();
263 virtual std::unique_ptr
<SwFieldType
> Copy() const override
;
267 class SW_DLLPUBLIC SwDBSetNumberField final
: public SwDBNameInfField
269 tools::Long m_nNumber
;
271 SwDBSetNumberField(SwDBSetNumberFieldType
*, const SwDBData
& rDBData
, sal_uInt32 nFormat
= 0);
273 virtual OUString
ExpandImpl(SwRootFrame
const* pLayout
) const override
;
274 virtual std::unique_ptr
<SwField
> Copy() const override
;
275 void Evaluate(const SwDoc
&);
277 inline tools::Long
GetSetNumber() const;
278 inline void SetSetNumber(tools::Long nNum
);
279 virtual bool QueryValue( css::uno::Any
& rVal
, sal_uInt16 nWhich
) const override
;
280 virtual bool PutValue( const css::uno::Any
& rVal
, sal_uInt16 nWhich
) override
;
283 inline tools::Long
SwDBSetNumberField::GetSetNumber() const
284 { return m_nNumber
; }
286 inline void SwDBSetNumberField::SetSetNumber(tools::Long nNum
)
287 { m_nNumber
= nNum
; }
289 #endif // INCLUDED_SW_INC_DBFLD_HXX
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */