LibreOffice Module sw (master)  1
dbfld.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_SW_INC_DBFLD_HXX
20 #define INCLUDED_SW_INC_DBFLD_HXX
21 
22 #include "swdllapi.h"
23 #include "fldbas.hxx"
24 #include "swdbdata.hxx"
25 
26 class SwDoc;
27 
28 // Database field.
30 {
32  OUString m_sName;
33  OUString m_sColumn;
35 
36 public:
37 
38  SwDBFieldType(SwDoc* pDocPtr, const OUString& rColumnName, const SwDBData& rDBData);
39  virtual ~SwDBFieldType() override;
40 
41  virtual OUString GetName() const override;
42  virtual std::unique_ptr<SwFieldType> Copy() const override;
43 
44  void AddRef() { m_nRefCnt++; }
45  void ReleaseRef();
46 
47  const OUString& GetColumnName() const {return m_sColumn;}
48  const SwDBData& GetDBData() const {return m_aDBData;}
49 
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 {};
53 };
54 
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
58 {
59  OUString m_aContent;
60  OUString m_sFieldCode;
61  sal_uInt16 m_nSubType;
62  bool m_bIsInBodyText : 1;
63  bool m_bValidValue : 1;
64  bool m_bInitialized : 1;
65 
66  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
67  virtual std::unique_ptr<SwField> Copy() const override;
68 
69 public:
70  SwDBField(SwDBFieldType*, sal_uInt32 nFormat = 0);
71  virtual ~SwDBField() override;
72 
73  virtual SwFieldType* ChgTyp( SwFieldType* ) override;
74 
76  inline void SetExpansion(const OUString& rStr);
77 
78  virtual sal_uInt16 GetSubType() const override;
79  virtual void SetSubType(sal_uInt16 nType) override;
80 
81  virtual OUString GetFieldName() const override;
82 
84  void ChgValue( double d, bool bVal );
85 
87  void Evaluate();
88 
90  void InitContent();
91  void InitContent(const OUString& rExpansion);
92 
93  inline void ChgBodyTextFlag( bool bIsInBody );
94 
95  bool IsInitialized() const { return m_bInitialized; }
96  void ClearInitialized() { m_bInitialized = false; }
97  void SetInitialized() { m_bInitialized = true; }
98 
100  virtual OUString GetPar1() const override;
101 
103  void SetFieldCode(const OUString& rStr) { m_sFieldCode = rStr; }
104 
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;
109 
110  static bool FormatValue( SvNumberFormatter const * pDocFormatter, OUString const &aString, sal_uInt32 nFormat,
111  double &aNumber, sal_Int32 nColumnType, SwDBField *pField = nullptr );
112 };
113 
114 inline void SwDBField::SetExpansion(const OUString& rStr)
115  { m_aContent = rStr; }
116 
118 inline void SwDBField::ChgBodyTextFlag( bool bIsInBody )
119  { m_bIsInBodyText = bIsInBody; }
120 
121 // Base class for all other database fields.
123 {
125  sal_uInt16 m_nSubType;
126 
127 protected:
128  const SwDBData& GetDBData() const {return m_aDBData;}
129  SwDBData& GetDBData() {return m_aDBData;}
130 
131  SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uInt32 nFormat = 0);
132 
133 public:
135  const SwDBData& GetRealDBData() const { return m_aDBData; }
136  SwDBData& GetRealDBData() { return m_aDBData; }
137 
138  SwDBData GetDBData(SwDoc* pDoc);
139  void SetDBData(const SwDBData& rDBData);
140 
141  virtual OUString GetFieldName() const override;
142 
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;
147 };
148 
149 // Database field next record.
151 {
152 public:
154 
155  virtual std::unique_ptr<SwFieldType> Copy() const override;
156 };
157 
158 // Next data record with condition.
160 {
161  OUString m_aCond;
163 
164 public:
166  const OUString& rCond, const SwDBData& rDBData);
167 
168  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
169  virtual std::unique_ptr<SwField> Copy() const override;
170 
171  void Evaluate(const SwDoc&);
172  inline void SetCondValid(bool bCond);
173  inline bool IsCondValid() const;
174 
175  // Condition
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;
180 };
181 
182 inline bool SwDBNextSetField::IsCondValid() const
183  { return m_bCondValid; }
184 
185 inline void SwDBNextSetField::SetCondValid(bool bCond)
186  { m_bCondValid = bCond; }
187 
188 // Database field next record.
189 class SwDBNumSetFieldType final : public SwFieldType
190 {
191 public:
193 
194  virtual std::unique_ptr<SwFieldType> Copy() const override;
195 };
196 
197 // Data record with number xxx.
198 // Number is in nFormat (bit of a misuse!)
199 class SwDBNumSetField final : public SwDBNameInfField
200 {
201  OUString m_aCond;
202  OUString m_aPar2;
204 
205 public:
206  SwDBNumSetField(SwDBNumSetFieldType*, const OUString& rCond, const OUString& rDBNum, const SwDBData& rDBData);
207 
208  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
209  virtual std::unique_ptr<SwField> Copy() const override;
210 
211  inline bool IsCondValid() const;
212  inline void SetCondValid(bool bCond);
213  void Evaluate(const SwDoc&);
214 
215  // Condition
216  virtual OUString GetPar1() const override;
217  virtual void SetPar1(const OUString& rStr) override;
218 
219  // Number of data record.
220  virtual OUString GetPar2() const override;
221  virtual void SetPar2(const OUString& rStr) override;
222 
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;
226 };
227 
228 inline bool SwDBNumSetField::IsCondValid() const
229  { return m_bCondValid; }
230 
231 inline void SwDBNumSetField::SetCondValid(bool bCond)
232  { m_bCondValid = bCond; }
233 
234 // Database name.
235 class SwDBNameFieldType final : public SwFieldType
236 {
238 public:
240 
241  OUString Expand() const;
242  virtual std::unique_ptr<SwFieldType> Copy() const override;
243 };
244 
245 // Database field.
246 class SwDBNameField final : public SwDBNameInfField
247 {
248 public:
249  SwDBNameField(SwDBNameFieldType*, const SwDBData& rDBData);
250 
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;
255 };
256 
257 // Number of data record.
259 {
260 public:
262 
263  virtual std::unique_ptr<SwFieldType> Copy() const override;
264 };
265 
266 // Database field.
268 {
270 public:
271  SwDBSetNumberField(SwDBSetNumberFieldType*, const SwDBData& rDBData, sal_uInt32 nFormat = 0);
272 
273  virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
274  virtual std::unique_ptr<SwField> Copy() const override;
275  void Evaluate(const SwDoc&);
276 
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;
281 };
282 
284  { return m_nNumber; }
285 
287  { m_nNumber = nNum; }
288 
289 #endif // INCLUDED_SW_INC_DBFLD_HXX
290 
291 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:241
tools::Long m_nNumber
Definition: dbfld.hxx:269
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:697
bool IsCondValid() const
Definition: dbfld.hxx:182
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:477
SwDBData m_aDBData
Definition: dbfld.hxx:124
bool m_bCondValid
Definition: dbfld.hxx:162
virtual std::unique_ptr< SwFieldType > Copy() const =0
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:499
bool IsInitialized() const
Definition: dbfld.hxx:95
long Long
virtual OUString GetPar2() const override
get condition
Definition: dbfld.cxx:686
const OUString & GetColumnName() const
Definition: dbfld.hxx:47
OUString m_sColumn
Definition: dbfld.hxx:33
SwDoc * m_pDoc
Definition: dbfld.hxx:237
Base class of all fields.
Definition: fldbas.hxx:291
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:646
OUString m_sName
only used in GetName() !
Definition: dbfld.hxx:32
Definition: doc.hxx:187
SwDBNameFieldType(SwDoc *)
Definition: dbfld.cxx:735
const SwDBData & GetDBData() const
Definition: dbfld.hxx:128
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:652
OUString m_sFieldCode
contains Word's field code
Definition: dbfld.hxx:60
virtual void SetPar1(const OUString &rStr) override
set LogDBName
Definition: dbfld.cxx:680
SwDBNumSetField(SwDBNumSetFieldType *, const OUString &rCond, const OUString &rDBNum, const SwDBData &rDBData)
Definition: dbfld.cxx:637
The root element of a Writer document layout.
Definition: rootfrm.hxx:81
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:747
virtual OUString GetPar1() const
Definition: fldbas.cxx:321
bool m_bCondValid
Definition: dbfld.hxx:203
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
void SetCondValid(bool bCond)
Definition: dbfld.hxx:185
void AddRef()
Definition: dbfld.hxx:44
void SetFieldCode(const OUString &rStr)
access to the command string
Definition: dbfld.hxx:103
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:369
sal_uInt16 m_nSubType
Definition: dbfld.hxx:125
void Evaluate(const SwDoc &)
Definition: dbfld.cxx:661
SwDBData & GetDBData()
Definition: dbfld.hxx:129
OUString Expand() const
Definition: dbfld.cxx:741
SwDBData & GetRealDBData()
Definition: dbfld.hxx:136
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:351
OUString m_aContent
Definition: dbfld.hxx:59
const SwDBData & GetDBData() const
Definition: dbfld.hxx:48
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:336
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:774
virtual std::unique_ptr< SwField > Copy() const =0
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:647
void SetSetNumber(tools::Long nNum)
Definition: dbfld.hxx:286
bool m_bIsInBodyText
Definition: dbfld.hxx:62
OUString m_aCond
Definition: dbfld.hxx:161
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:632
SwDBData m_aDBData
Definition: dbfld.hxx:31
tools::Long m_nRefCnt
Definition: dbfld.hxx:34
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:758
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
void SetCondValid(bool bCond)
Definition: dbfld.hxx:231
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:342
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:142
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:714
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:414
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:765
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:137
void SetInitialized()
Definition: dbfld.hxx:97
void SetExpansion(const OUString &rStr)
Current text.
Definition: dbfld.hxx:114
const SwDBData & GetDBData() const
DBName.
Definition: dbfld.hxx:106
sal_uInt16 m_nSubType
Definition: dbfld.hxx:61
void ClearInitialized()
Definition: dbfld.hxx:96
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:145
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:305
bool IsCondValid() const
Definition: dbfld.hxx:228
const SwDBData & GetRealDBData() const
DBName.
Definition: dbfld.hxx:135
virtual void SetPar2(const OUString &rStr) override
set condition
Definition: dbfld.cxx:692
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:347
OUString m_aPar2
Definition: dbfld.hxx:202
void ChgBodyTextFlag(bool bIsInBody)
set from UpdateExpFields (the Node-Position is known there)
Definition: dbfld.hxx:118
OUString m_aCond
Definition: dbfld.hxx:201
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:779
SwDBNameField(SwDBNameFieldType *, const SwDBData &rDBData)
Definition: dbfld.cxx:754
virtual void UpdateFields() override
Definition: dbfld.hxx:52
tools::Long GetSetNumber() const
Definition: dbfld.hxx:283
virtual OUString GetPar1() const override
get LogDBName
Definition: dbfld.cxx:674