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