lok: Hide file linking in section
[LibreOffice.git] / sw / inc / dbfld.hxx
blob1c0d0db2c30f93c4128b413a8ff350498de33e90
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
22 #include "swdllapi.h"
23 #include "fldbas.hxx"
24 #include "swdbdata.hxx"
26 class SwDoc;
28 // Database field.
29 class SW_DLLPUBLIC SwDBFieldType final : public SwValueFieldType
31 SwDBData m_aDBData;
32 OUString m_sName; ///< only used in ::GetName() !
33 OUString m_sColumn;
34 long m_nRefCnt;
36 public:
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++; }
45 void ReleaseRef();
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
58 OUString m_aContent;
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;
68 public:
69 SwDBField(SwDBFieldType*, sal_uInt32 nFormat = 0);
70 virtual ~SwDBField() override;
72 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
74 /// Current text.
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.
86 void Evaluate();
88 /// Evaluation for header and footer.
89 void InitContent();
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; }
98 /// Get name.
99 virtual OUString GetPar1() const override;
101 /// access to the command string
102 void SetFieldCode(const OUString& rStr) { m_sFieldCode = rStr; }
104 /// DBName
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
123 SwDBData m_aDBData;
124 sal_uInt16 m_nSubType;
126 protected:
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);
132 public:
133 /// DBName
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
151 public:
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
160 OUString m_aCond;
161 bool m_bCondValid;
163 public:
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;
174 // Condition
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
190 public:
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
200 OUString m_aCond;
201 OUString m_aPar2;
202 bool m_bCondValid;
204 public:
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 *);
214 // Condition
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; }
233 // Database name.
234 class SwDBNameFieldType final : public SwFieldType
236 SwDoc *m_pDoc;
237 public:
238 SwDBNameFieldType(SwDoc*);
240 OUString Expand() const;
241 virtual std::unique_ptr<SwFieldType> Copy() const override;
244 // Database field.
245 class SwDBNameField final : public SwDBNameInfField
247 public:
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
259 public:
260 SwDBSetNumberFieldType();
262 virtual std::unique_ptr<SwFieldType> Copy() const override;
265 // Database field.
266 class SW_DLLPUBLIC SwDBSetNumberField final : public SwDBNameInfField
268 long m_nNumber;
269 public:
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: */