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;
34  long m_nRefCnt;
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 };
53 
54 // Classes derived from SwFields. They overlay the expand-function.
55 // Content is formatted according to the format (if available).
57 {
58  OUString m_aContent;
59  OUString m_sFieldCode;
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 
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 
83  void ChgValue( double d, bool bVal );
84 
86  void Evaluate();
87 
89  void InitContent();
90  void InitContent(const OUString& rExpansion);
91 
92  inline void ChgBodyTextFlag( bool bIsInBody );
93 
94  bool IsInitialized() const { return m_bInitialized; }
95  void ClearInitialized() { m_bInitialized = false; }
96  void SetInitialized() { m_bInitialized = true; }
97 
99  virtual OUString GetPar1() const override;
100 
102  void SetFieldCode(const OUString& rStr) { m_sFieldCode = rStr; }
103 
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;
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  { m_aContent = rStr; }
115 
117 inline void SwDBField::ChgBodyTextFlag( bool bIsInBody )
118  { m_bIsInBodyText = bIsInBody; }
119 
120 // Base class for all other database fields.
122 {
124  sal_uInt16 m_nSubType;
125 
126 protected:
127  const SwDBData& GetDBData() const {return m_aDBData;}
128  SwDBData& GetDBData() {return m_aDBData;}
129 
130  SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uInt32 nFormat = 0);
131 
132 public:
134  const SwDBData& GetRealDBData() const { return m_aDBData; }
135  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.
150 {
151 public:
153 
154  virtual std::unique_ptr<SwFieldType> Copy() const override;
155 };
156 
157 // Next data record with condition.
159 {
160  OUString m_aCond;
162 
163 public:
165  const OUString& rCond, 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(SwDoc const *);
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  { return m_bCondValid; }
183 
184 inline void SwDBNextSetField::SetCondValid(bool bCond)
185  { m_bCondValid = bCond; }
186 
187 // Database field next record.
189 {
190 public:
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!)
199 {
200  OUString m_aCond;
201  OUString m_aPar2;
203 
204 public:
205  SwDBNumSetField(SwDBNumSetFieldType*, const OUString& rCond, const OUString& rDBNum, 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(SwDoc const *);
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  { return m_bCondValid; }
229 
230 inline void SwDBNumSetField::SetCondValid(bool bCond)
231  { m_bCondValid = bCond; }
232 
233 // Database name.
235 {
237 public:
239 
240  OUString Expand() const;
241  virtual std::unique_ptr<SwFieldType> Copy() const override;
242 };
243 
244 // Database field.
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.
258 {
259 public:
261 
262  virtual std::unique_ptr<SwFieldType> Copy() const override;
263 };
264 
265 // Database field.
267 {
268  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(SwDoc const *);
275 
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;
280 };
281 
283  { return m_nNumber; }
284 
285 inline void SwDBSetNumberField::SetSetNumber(long nNum)
286  { m_nNumber = nNum; }
287 
288 #endif // INCLUDED_SW_INC_DBFLD_HXX
289 
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:234
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:711
bool IsCondValid() const
Definition: dbfld.hxx:181
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const override
Definition: dbfld.cxx:491
SwDBData m_aDBData
Definition: dbfld.hxx:123
void Evaluate(SwDoc const *)
Definition: dbfld.cxx:675
bool m_bCondValid
Definition: dbfld.hxx:161
virtual std::unique_ptr< SwFieldType > Copy() const =0
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:513
bool IsInitialized() const
Definition: dbfld.hxx:94
virtual OUString GetPar2() const override
get condition
Definition: dbfld.cxx:700
const OUString & GetColumnName() const
Definition: dbfld.hxx:47
OUString m_sColumn
Definition: dbfld.hxx:33
SwDoc * m_pDoc
Definition: dbfld.hxx:236
Base class of all fields.
Definition: fldbas.hxx:280
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:576
OUString m_sName
only used in ::GetName() !
Definition: dbfld.hxx:32
Definition: doc.hxx:185
SwDBNameFieldType(SwDoc *)
Definition: dbfld.cxx:749
const SwDBData & GetDBData() const
Definition: dbfld.hxx:127
virtual std::unique_ptr< SwField > Copy() const override
Definition: dbfld.cxx:666
OUString m_sFieldCode
contains Word's field code
Definition: dbfld.hxx:59
virtual void SetPar1(const OUString &rStr) override
set LogDBName
Definition: dbfld.cxx:694
SwDBNumSetField(SwDBNumSetFieldType *, const OUString &rCond, const OUString &rDBNum, const SwDBData &rDBData)
Definition: dbfld.cxx:651
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
long m_nRefCnt
Definition: dbfld.hxx:34
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:761
virtual OUString GetPar1() const
Definition: fldbas.cxx:271
bool m_bCondValid
Definition: dbfld.hxx:202
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
void SetCondValid(bool bCond)
Definition: dbfld.hxx:184
void AddRef()
Definition: dbfld.hxx:44
void SetFieldCode(const OUString &rStr)
access to the command string
Definition: dbfld.hxx:102
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:314
sal_uInt16 m_nSubType
Definition: dbfld.hxx:124
SwDBData & GetDBData()
Definition: dbfld.hxx:128
OUString Expand() const
Definition: dbfld.cxx:755
SwDBData & GetRealDBData()
Definition: dbfld.hxx:135
long GetSetNumber() const
Definition: dbfld.hxx:282
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:301
OUString m_aContent
Definition: dbfld.hxx:58
const SwDBData & GetDBData() const
Definition: dbfld.hxx:48
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:286
virtual std::unique_ptr< SwField > Copy() const =0
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const override
Definition: dbfld.cxx:661
bool m_bIsInBodyText
Definition: dbfld.hxx:61
OUString m_aCond
Definition: dbfld.hxx:160
virtual std::unique_ptr< SwFieldType > Copy() const override
Definition: dbfld.cxx:646
SwDBData m_aDBData
Definition: dbfld.hxx:31
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
void SetSetNumber(long nNum)
Definition: dbfld.hxx:285
void SetCondValid(bool bCond)
Definition: dbfld.hxx:230
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:292
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:148
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich) override
Definition: dbfld.cxx:728
SwFieldType * GetTyp() const
Definition: fldbas.hxx:383
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:399
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:143
void SetInitialized()
Definition: dbfld.hxx:96
void SetExpansion(const OUString &rStr)
Current text.
Definition: dbfld.hxx:113
const SwDBData & GetDBData() const
DBName.
Definition: dbfld.hxx:105
sal_uInt16 m_nSubType
Definition: dbfld.hxx:60
void ClearInitialized()
Definition: dbfld.hxx:95
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:151
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:255
bool IsCondValid() const
Definition: dbfld.hxx:227
const SwDBData & GetRealDBData() const
DBName.
Definition: dbfld.hxx:134
virtual void SetPar2(const OUString &rStr) override
set condition
Definition: dbfld.cxx:706
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:297
OUString m_aPar2
Definition: dbfld.hxx:201
void ChgBodyTextFlag(bool bIsInBody)
set from UpdateExpFields (the Node-Position is known there)
Definition: dbfld.hxx:117
OUString m_aCond
Definition: dbfld.hxx:200
virtual OUString GetPar1() const override
get LogDBName
Definition: dbfld.cxx:688