Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / dbfld.hxx
blob61b1b2267afbf3529ff76ad48fe0ea8433feffed
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;
27 class SwTextField;
28 class SwFrame;
30 // Database field.
31 class SW_DLLPUBLIC SwDBFieldType : public SwValueFieldType
33 SwDBData aDBData;
34 OUString sName; ///< only used in ::GetName() !
35 OUString sColumn;
36 long nRefCnt;
38 public:
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++; }
47 void ReleaseRef();
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
60 OUString aContent;
61 OUString sFieldCode; ///< contains Word's field code
62 sal_uInt16 nSubType;
63 bool bIsInBodyText : 1;
64 bool bValidValue : 1;
65 bool bInitialized : 1;
67 virtual OUString Expand() const override;
68 virtual SwField* Copy() const override;
70 public:
71 SwDBField(SwDBFieldType*, sal_uLong nFormat = 0);
72 virtual ~SwDBField() override;
74 virtual SwFieldType* ChgTyp( SwFieldType* ) override;
76 /// Current text.
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.
88 void Evaluate();
90 /// Evaluation for header and footer.
91 void InitContent();
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; }
100 /// Get name.
101 virtual OUString GetPar1() const override;
103 /// access to the command string
104 void SetFieldCode(const OUString& rStr) { sFieldCode = rStr; }
106 /// DBName
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)
116 { aContent = 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
125 SwDBData aDBData;
126 sal_uInt16 nSubType;
128 protected:
129 const SwDBData& GetDBData() const {return aDBData;}
130 SwDBData& GetDBData() {return aDBData;}
132 SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFormat = 0);
134 public:
135 /// DBName
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
153 public:
154 SwDBNextSetFieldType();
156 virtual SwFieldType* Copy() const override;
159 // Next data record with condition.
160 class SW_DLLPUBLIC SwDBNextSetField : public SwDBNameInfField
162 OUString aCond;
163 bool bCondValid;
165 public:
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;
176 // Condition
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
192 public:
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
202 OUString aCond;
203 OUString aPar2;
204 bool bCondValid;
206 public:
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*);
216 // Condition
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; }
235 // Database name.
236 class SwDBNameFieldType : public SwFieldType
238 SwDoc *pDoc;
239 public:
240 SwDBNameFieldType(SwDoc*);
242 OUString Expand() const;
243 virtual SwFieldType* Copy() const override;
246 // Database field.
247 class SW_DLLPUBLIC SwDBNameField : public SwDBNameInfField
249 public:
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
261 public:
262 SwDBSetNumberFieldType();
264 virtual SwFieldType* Copy() const override;
267 // Database field.
268 class SW_DLLPUBLIC SwDBSetNumberField : public SwDBNameInfField
270 long nNumber;
271 public:
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
285 { return nNumber; }
287 inline void SwDBSetNumberField::SetSetNumber(long nNum)
288 { nNumber = nNum; }
290 #endif // INCLUDED_SW_INC_DBFLD_HXX
292 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */