/src/libreoffice/sw/inc/dbfld.hxx
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | #pragma once |
20 | | |
21 | | #include "swdllapi.h" |
22 | | #include "fldbas.hxx" |
23 | | #include "swdbdata.hxx" |
24 | | |
25 | | class SwDoc; |
26 | | |
27 | | // Database field. |
28 | | class SW_DLLPUBLIC SwDBFieldType final : public SwValueFieldType |
29 | | { |
30 | | SwDBData m_aDBData; |
31 | | UIName m_sName; ///< only used in ::GetName() ! |
32 | | OUString m_sColumn; |
33 | | tools::Long m_nRefCnt; |
34 | | |
35 | | public: |
36 | | |
37 | | SwDBFieldType(SwDoc* pDocPtr, const OUString& rColumnName, SwDBData aDBData); |
38 | | virtual ~SwDBFieldType() override; |
39 | | |
40 | | virtual UIName GetName() const override; |
41 | | virtual std::unique_ptr<SwFieldType> Copy() const override; |
42 | | |
43 | 4.87k | void AddRef() { m_nRefCnt++; } |
44 | | void ReleaseRef(); |
45 | | |
46 | 4.87k | const OUString& GetColumnName() const {return m_sColumn;} |
47 | 0 | const SwDBData& GetDBData() const {return m_aDBData;} |
48 | | |
49 | | virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nWhich ) const override; |
50 | | virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nWhich ) override; |
51 | 153 | virtual void UpdateFields() override {}; |
52 | | }; |
53 | | |
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 |
57 | | { |
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; |
64 | | |
65 | | virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; |
66 | | virtual std::unique_ptr<SwField> Copy() const override; |
67 | | |
68 | | public: |
69 | | SwDBField(SwDBFieldType*, sal_uInt32 nFormat = 0); |
70 | | virtual ~SwDBField() override; |
71 | | |
72 | | virtual SwFieldType* ChgTyp( SwFieldType* ) override; |
73 | | |
74 | | /// Current text. |
75 | | inline void SetExpansion(const OUString& rStr); |
76 | | |
77 | | virtual sal_uInt16 GetSubType() const override; |
78 | | virtual void SetSubType(sal_uInt16 nType) override; |
79 | | |
80 | | virtual OUString GetFieldName() const override; |
81 | | |
82 | | /// For calculations in expressions. |
83 | | void ChgValue( double d, bool bVal ); |
84 | | |
85 | | /// Get the evaluation via DBManager string. |
86 | | void Evaluate(); |
87 | | |
88 | | /// Evaluation for header and footer. |
89 | | void InitContent(); |
90 | | void InitContent(const OUString& rExpansion); |
91 | | |
92 | | inline void ChgBodyTextFlag( bool bIsInBody ); |
93 | | |
94 | 4.87k | bool IsInitialized() const { return m_bInitialized; } |
95 | 0 | void ClearInitialized() { m_bInitialized = false; } |
96 | 0 | void SetInitialized() { m_bInitialized = true; } |
97 | | |
98 | | /// Get name. |
99 | | virtual OUString GetPar1() const override; |
100 | | |
101 | | /// access to the command string |
102 | 0 | void SetFieldCode(const OUString& rStr) { m_sFieldCode = rStr; } |
103 | | |
104 | | /// DBName |
105 | 0 | 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; |
108 | | |
109 | | static bool FormatValue( SvNumberFormatter const * pDocFormatter, OUString const &aString, sal_uInt32 nFormat, |
110 | | double &aNumber, sal_Int32 nColumnType, SwDBField *pField = nullptr ); |
111 | | }; |
112 | | |
113 | | inline void SwDBField::SetExpansion(const OUString& rStr) |
114 | 715 | { m_aContent = rStr; } |
115 | | |
116 | | /// set from UpdateExpFields (the Node-Position is known there) |
117 | | inline void SwDBField::ChgBodyTextFlag( bool bIsInBody ) |
118 | 462 | { m_bIsInBodyText = bIsInBody; } |
119 | | |
120 | | // Base class for all other database fields. |
121 | | class SW_DLLPUBLIC SwDBNameInfField : public SwField |
122 | | { |
123 | | SwDBData m_aDBData; |
124 | | sal_uInt16 m_nSubType; |
125 | | |
126 | | protected: |
127 | 0 | const SwDBData& GetDBData() const {return m_aDBData;} |
128 | 0 | SwDBData& GetDBData() {return m_aDBData;} |
129 | | |
130 | | SwDBNameInfField(SwFieldType* pTyp, SwDBData aDBData, sal_uInt32 nFormat = 0); |
131 | | |
132 | | public: |
133 | | /// DBName |
134 | 0 | const SwDBData& GetRealDBData() const { return m_aDBData; } |
135 | 0 | SwDBData& GetRealDBData() { return m_aDBData; } |
136 | | |
137 | | SwDBData GetDBData(SwDoc* pDoc); |
138 | | void SetDBData(const SwDBData& rDBData); |
139 | | |
140 | | virtual OUString GetFieldName() const override; |
141 | | |
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; |
146 | | }; |
147 | | |
148 | | // Database field next record. |
149 | | class SW_DLLPUBLIC SwDBNextSetFieldType final : public SwFieldType |
150 | | { |
151 | | public: |
152 | | SwDBNextSetFieldType(); |
153 | | |
154 | | virtual std::unique_ptr<SwFieldType> Copy() const override; |
155 | | }; |
156 | | |
157 | | // Next data record with condition. |
158 | | class SW_DLLPUBLIC SwDBNextSetField final : public SwDBNameInfField |
159 | | { |
160 | | OUString m_aCond; |
161 | | bool m_bCondValid; |
162 | | |
163 | | public: |
164 | | SwDBNextSetField( SwDBNextSetFieldType*, |
165 | | OUString aCond, const SwDBData& rDBData); |
166 | | |
167 | | virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; |
168 | | virtual std::unique_ptr<SwField> Copy() const override; |
169 | | |
170 | | void Evaluate(const SwDoc&); |
171 | | inline void SetCondValid(bool bCond); |
172 | | inline bool IsCondValid() const; |
173 | | |
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; |
179 | | }; |
180 | | |
181 | | inline bool SwDBNextSetField::IsCondValid() const |
182 | 0 | { return m_bCondValid; } |
183 | | |
184 | | inline void SwDBNextSetField::SetCondValid(bool bCond) |
185 | 0 | { m_bCondValid = bCond; } |
186 | | |
187 | | // Database field next record. |
188 | | class SwDBNumSetFieldType final : public SwFieldType |
189 | | { |
190 | | public: |
191 | | SwDBNumSetFieldType(); |
192 | | |
193 | | virtual std::unique_ptr<SwFieldType> Copy() const override; |
194 | | }; |
195 | | |
196 | | // Data record with number xxx. |
197 | | // Number is in nFormat (bit of a misuse!) |
198 | | class SwDBNumSetField final : public SwDBNameInfField |
199 | | { |
200 | | OUString m_aCond; |
201 | | OUString m_aPar2; |
202 | | bool m_bCondValid; |
203 | | |
204 | | public: |
205 | | SwDBNumSetField(SwDBNumSetFieldType*, OUString aCond, OUString aDBNum, const SwDBData& rDBData); |
206 | | |
207 | | virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; |
208 | | virtual std::unique_ptr<SwField> Copy() const override; |
209 | | |
210 | | inline bool IsCondValid() const; |
211 | | inline void SetCondValid(bool bCond); |
212 | | void Evaluate(const SwDoc&); |
213 | | |
214 | | // Condition |
215 | | virtual OUString GetPar1() const override; |
216 | | virtual void SetPar1(const OUString& rStr) override; |
217 | | |
218 | | // Number of data record. |
219 | | virtual OUString GetPar2() const override; |
220 | | virtual void SetPar2(const OUString& rStr) override; |
221 | | |
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; |
225 | | }; |
226 | | |
227 | | inline bool SwDBNumSetField::IsCondValid() const |
228 | 0 | { return m_bCondValid; } |
229 | | |
230 | | inline void SwDBNumSetField::SetCondValid(bool bCond) |
231 | 0 | { m_bCondValid = bCond; } |
232 | | |
233 | | // Database name. |
234 | | class SwDBNameFieldType final : public SwFieldType |
235 | | { |
236 | | SwDoc *m_pDoc; |
237 | | public: |
238 | | SwDBNameFieldType(SwDoc*); |
239 | | |
240 | | OUString Expand() const; |
241 | | virtual std::unique_ptr<SwFieldType> Copy() const override; |
242 | | }; |
243 | | |
244 | | // Database field. |
245 | | class SwDBNameField final : public SwDBNameInfField |
246 | | { |
247 | | public: |
248 | | SwDBNameField(SwDBNameFieldType*, const SwDBData& rDBData); |
249 | | |
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; |
254 | | }; |
255 | | |
256 | | // Number of data record. |
257 | | class SW_DLLPUBLIC SwDBSetNumberFieldType final : public SwFieldType |
258 | | { |
259 | | public: |
260 | | SwDBSetNumberFieldType(); |
261 | | |
262 | | virtual std::unique_ptr<SwFieldType> Copy() const override; |
263 | | }; |
264 | | |
265 | | // Database field. |
266 | | class SW_DLLPUBLIC SwDBSetNumberField final : public SwDBNameInfField |
267 | | { |
268 | | tools::Long m_nNumber; |
269 | | public: |
270 | | SwDBSetNumberField(SwDBSetNumberFieldType*, const SwDBData& rDBData, sal_uInt32 nFormat = 0); |
271 | | |
272 | | virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override; |
273 | | virtual std::unique_ptr<SwField> Copy() const override; |
274 | | void Evaluate(const SwDoc&); |
275 | | |
276 | | inline tools::Long GetSetNumber() const; |
277 | | inline void SetSetNumber(tools::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; |
280 | | }; |
281 | | |
282 | | inline tools::Long SwDBSetNumberField::GetSetNumber() const |
283 | 0 | { return m_nNumber; } |
284 | | |
285 | | inline void SwDBSetNumberField::SetSetNumber(tools::Long nNum) |
286 | 0 | { m_nNumber = nNum; } |
287 | | |
288 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |