xref: /aoo42x/main/sw/inc/dbfld.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef SW_DBFLD_HXX
24 #define SW_DBFLD_HXX
25 
26 #include "swdllapi.h"
27 #include "fldbas.hxx"
28 #include "swdbdata.hxx"
29 
30 class SwDoc;
31 class SwTxtFld;
32 class SwFrm;
33 
34 /*--------------------------------------------------------------------
35 	Beschreibung: Datenbankfeld
36  --------------------------------------------------------------------*/
37 
38 class SW_DLLPUBLIC SwDBFieldType : public SwValueFieldType
39 {
40 	SwDBData 	aDBData;		//
41 	String 		sName;			// only used in ::GetName() !
42 	String 		sColumn;
43 	long   		nRefCnt;
44 
45 public:
46 
47 	SwDBFieldType(SwDoc* pDocPtr, const String& rColumnName, const SwDBData& rDBData);
48     ~SwDBFieldType();
49 
50 	virtual const String& GetName() const;
51 	virtual SwFieldType*  Copy() const;
52 
AddRef()53 	inline void		AddRef() { nRefCnt++; }
54 	void			ReleaseRef();
55 
GetColumnName() const56 	const String&	GetColumnName()	const {return sColumn;}
GetDBData() const57 	const SwDBData&	GetDBData()	const {return aDBData;}
58 
59     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
60     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
61 };
62 
63 /*--------------------------------------------------------------------
64 	Beschreibung:
65 	von SwFields abgeleitete Klassen. Sie ueberlagern die Expand-Funktion.
66 	Der Inhalt wird entsprechend dem Format, soweit vorhanden, formatiert.
67  --------------------------------------------------------------------*/
68 
69 class SW_DLLPUBLIC SwDBField : public SwValueField
70 {
71 	String  aContent;
72     String  sFieldCode; // contains Word's field code
73 	sal_uInt16	nSubType;
74 	sal_Bool 	bIsInBodyTxt	: 1;
75 	sal_Bool	bValidValue		: 1;
76 	sal_Bool	bInitialized	: 1;
77 
78     virtual String      Expand() const;
79     virtual SwField*    Copy() const;
80 
81 public:
82 	SwDBField(SwDBFieldType*, sal_uLong nFmt = 0);
83 	virtual ~SwDBField();
84 
85 	virtual SwFieldType*	ChgTyp( SwFieldType* );
86 
87 	// Der aktuelle Text
88 	inline  void		SetExpansion(const String& rStr);
89 
90 	virtual sal_uInt16		GetSubType() const;
91 	virtual void		SetSubType(sal_uInt16 nType);
92 
93     virtual String      GetFieldName() const;
94 
95 	// fuer Berechnungen in Ausdruecken
96 	void 				ChgValue( double d, sal_Bool bVal );
97 
98 	// Evaluierung ueber den DBMgr String rauspulen
99 	void				Evaluate();
100 
101 	// Evaluierung fuer Kopf und Fusszeilen
102 	void 			    ChangeExpansion( const SwFrm*, const SwTxtFld* );
103 	void				InitContent();
104 	void				InitContent(const String& rExpansion);
105 
106 	inline void 		ChgBodyTxtFlag( sal_Bool bIsInBody );
107 
IsInitialized() const108 	inline sal_Bool 		IsInitialized() const	{ return bInitialized; }
ClearInitialized()109 	inline void			ClearInitialized()		{ bInitialized = sal_False; }
SetInitialized()110 	inline void			SetInitialized()		{ bInitialized = sal_True; }
111 
112 	// Name erfragen
113 	virtual const String& GetPar1() const;
114 
115     // access to the command string
GetFieldCode() const116     const String&       GetFieldCode()   const
117                         { return sFieldCode;}
SetFieldCode(const String & rStr)118     void                SetFieldCode(const String& rStr)
119                         { sFieldCode = rStr; }
120 
121 	// DBName
GetDBData() const122 	inline const SwDBData& 	GetDBData() const { return ((SwDBFieldType*)GetTyp())->GetDBData(); }
123     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
124     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
125 };
126 
SetExpansion(const String & rStr)127 inline  void SwDBField::SetExpansion(const String& rStr)
128 	{ aContent = rStr; }
129 
130 // wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt)
ChgBodyTxtFlag(sal_Bool bIsInBody)131 inline void SwDBField::ChgBodyTxtFlag( sal_Bool bIsInBody )
132 	{ bIsInBodyTxt = bIsInBody; }
133 
134 /*--------------------------------------------------------------------
135 	Beschreibung: Basisklasse fuer alle weiteren Datenbankfelder
136  --------------------------------------------------------------------*/
137 
138 class SW_DLLPUBLIC SwDBNameInfField : public SwField
139 {
140 	SwDBData 	aDBData;
141     sal_uInt16      nSubType;
142 
143 protected:
GetDBData() const144 	const SwDBData& GetDBData() const {return aDBData;}
GetDBData()145 	SwDBData& 		GetDBData() {return aDBData;}
146 
147 	SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt = 0);
148 
149 public:
150 	// DBName
GetRealDBData()151 	inline const SwDBData&	GetRealDBData() { return aDBData; }
152 
153 	SwDBData				GetDBData(SwDoc* pDoc);
154 	void				    SetDBData(const SwDBData& rDBData); // #111840#
155 
156     virtual String          GetFieldName() const;
157 
158     virtual sal_Bool            QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
159     virtual sal_Bool            PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
160     virtual sal_uInt16          GetSubType() const;
161     virtual void            SetSubType(sal_uInt16 nType);
162 };
163 
164 
165 /*--------------------------------------------------------------------
166 	Beschreibung: Datenbankfeld Naechster Satz
167  --------------------------------------------------------------------*/
168 
169 class SW_DLLPUBLIC SwDBNextSetFieldType : public SwFieldType
170 {
171 public:
172 	SwDBNextSetFieldType();
173 
174 	virtual SwFieldType* 	Copy() const;
175 };
176 
177 
178 /*--------------------------------------------------------------------
179 	Beschreibung: Naechsten Datensatz mit Bedingung
180  --------------------------------------------------------------------*/
181 
182 class SW_DLLPUBLIC SwDBNextSetField : public SwDBNameInfField
183 {
184 	String 	aCond;
185 	sal_Bool	bCondValid;
186 
187 public:
188 	SwDBNextSetField( SwDBNextSetFieldType*,
189 					  const String& rCond, const String& rDummy, const SwDBData& rDBData);
190 
191 	virtual String 			Expand() const;
192 	virtual SwField*		Copy() const;
193 
194 	void					Evaluate(SwDoc*);
195 	inline void				SetCondValid(sal_Bool bCond);
196 	inline sal_Bool				IsCondValid() const;
197 
198 	// Condition
199 	virtual const String&	GetPar1() const;
200 	virtual void	   		SetPar1(const String& rStr);
201     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
202     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
203 };
204 
IsCondValid() const205 inline sal_Bool	SwDBNextSetField::IsCondValid() const
206 	{ return bCondValid; }
207 
SetCondValid(sal_Bool bCond)208 inline void	SwDBNextSetField::SetCondValid(sal_Bool bCond)
209 	{ bCondValid = bCond; }
210 
211 /*--------------------------------------------------------------------
212 	Beschreibung: Datenbankfeld Naechster Satz
213  --------------------------------------------------------------------*/
214 
215 class SwDBNumSetFieldType : public SwFieldType
216 {
217 public:
218 	SwDBNumSetFieldType();
219 
220 	virtual SwFieldType*	Copy() const;
221 };
222 
223 
224 /*--------------------------------------------------------------------
225 	Beschreibung: Datensatz mit Nummer xxx
226 				  Die Nummer steht in nFormat
227 				  ! kleiner Missbrauch
228  --------------------------------------------------------------------*/
229 
230 class SwDBNumSetField : public SwDBNameInfField
231 {
232 	String 	aCond;
233 	String 	aPar2;
234 	sal_Bool 	bCondValid;
235 
236 public:
237 	SwDBNumSetField(SwDBNumSetFieldType*, const String& rCond, const String& rDBNum, const SwDBData& rDBData);
238 
239 	virtual String 			Expand() const;
240 	virtual SwField*		Copy() const;
241 
242 	inline sal_Bool				IsCondValid() const;
243 	inline void				SetCondValid(sal_Bool bCond);
244 	void					Evaluate(SwDoc*);
245 
246 	// Condition
247 	virtual const String&	GetPar1() const;
248 	virtual void	   		SetPar1(const String& rStr);
249 
250 	// Datensatznummer
251 	virtual String			GetPar2() 	const;
252 	virtual void			SetPar2(const String& rStr);
253 
254 	// Die Datensatznummer steht in nFormat !!
255     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
256     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
257 };
258 
IsCondValid() const259 inline sal_Bool	SwDBNumSetField::IsCondValid() const
260 	{ return bCondValid; }
261 
SetCondValid(sal_Bool bCond)262 inline void	SwDBNumSetField::SetCondValid(sal_Bool bCond)
263 	{ bCondValid = bCond; }
264 
265 /*--------------------------------------------------------------------
266 	Beschreibung: Datenbankname
267  --------------------------------------------------------------------*/
268 
269 class SwDBNameFieldType : public SwFieldType
270 {
271 		SwDoc *pDoc;
272 public:
273 	SwDBNameFieldType(SwDoc*);
274 
275 	String 					Expand(sal_uLong) const;
276 	virtual SwFieldType*    Copy() const;
277 };
278 
279 /*--------------------------------------------------------------------
280 	Beschreibung: Datenbankfeld
281  --------------------------------------------------------------------*/
282 
283 class SW_DLLPUBLIC SwDBNameField : public SwDBNameInfField
284 {
285 public:
286 	SwDBNameField(SwDBNameFieldType*, const SwDBData& rDBData, sal_uLong nFmt = 0);
287 
288 	virtual String	 Expand() const;
289 	virtual SwField* Copy() const;
290     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
291     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
292 };
293 
294 /*--------------------------------------------------------------------
295 	Beschreibung: Datensatznummer
296  --------------------------------------------------------------------*/
297 
298 class SW_DLLPUBLIC SwDBSetNumberFieldType : public SwFieldType
299 {
300 public:
301 	SwDBSetNumberFieldType();
302 
303 	virtual SwFieldType*    Copy() const;
304 };
305 
306 /*--------------------------------------------------------------------
307 	Beschreibung: Datenbankfeld
308  --------------------------------------------------------------------*/
309 
310 class SW_DLLPUBLIC SwDBSetNumberField : public SwDBNameInfField
311 {
312 	long	nNumber;
313 
314 public:
315 	SwDBSetNumberField(SwDBSetNumberFieldType*, const SwDBData& rDBData, sal_uLong nFmt = 0);
316 
317 	virtual String	Expand() const;
318 	virtual 		SwField* Copy() const;
319 	void			Evaluate(SwDoc*);
320 
321 	inline long		GetSetNumber() const;
322 	inline void		SetSetNumber(long nNum);
323     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
324     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
325 };
326 
GetSetNumber() const327 inline long	SwDBSetNumberField::GetSetNumber() const
328 	{ return nNumber; }
329 
SetSetNumber(long nNum)330 inline void	SwDBSetNumberField::SetSetNumber(long nNum)
331 	{ nNumber = nNum; }
332 
333 
334 #endif // SW_DBFLD_HXX
335