xref: /aoo41x/main/sw/source/core/fields/dbfld.cxx (revision c0286415)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <float.h>
28cdf0e10cSrcweir #include <sfx2/app.hxx>
29cdf0e10cSrcweir #include <svl/zforlist.hxx>
30cdf0e10cSrcweir #include <svx/pageitem.hxx>
31cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
32cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
33cdf0e10cSrcweir #include <fmtfld.hxx>
34cdf0e10cSrcweir #include <txtfld.hxx>
35cdf0e10cSrcweir #include <doc.hxx>
36cdf0e10cSrcweir #include <docary.hxx>
37cdf0e10cSrcweir #include <frame.hxx>
38cdf0e10cSrcweir #include <fldbas.hxx>
39cdf0e10cSrcweir #include <pam.hxx>
40cdf0e10cSrcweir #include <ndtxt.hxx>
41cdf0e10cSrcweir #include <dbfld.hxx>
42cdf0e10cSrcweir #include <dbmgr.hxx>
43cdf0e10cSrcweir #include <docfld.hxx>
44cdf0e10cSrcweir #include <expfld.hxx>
45cdf0e10cSrcweir #include <txtatr.hxx>
46cdf0e10cSrcweir #include <unofldmid.h>
47cdf0e10cSrcweir #include <switerator.hxx>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
50cdf0e10cSrcweir using namespace ::com::sun::star;
51cdf0e10cSrcweir using ::rtl::OUString;
52cdf0e10cSrcweir 
53cdf0e10cSrcweir /*--------------------------------------------------------------------
54cdf0e10cSrcweir 	Beschreibung: Datenbanktrenner durch Punkte fuer Anzeige ersetzen
55cdf0e10cSrcweir  --------------------------------------------------------------------*/
56cdf0e10cSrcweir 
lcl_DBTrennConv(const String & aContent)57cdf0e10cSrcweir String lcl_DBTrennConv(const String& aContent)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	String sTmp(aContent);
60cdf0e10cSrcweir 	sal_Unicode* pStr = sTmp.GetBufferAccess();
61cdf0e10cSrcweir 	for( sal_uInt16 i = sTmp.Len(); i; --i, ++pStr )
62cdf0e10cSrcweir 		if( DB_DELIM == *pStr )
63cdf0e10cSrcweir 			*pStr = '.';
64cdf0e10cSrcweir 	return sTmp;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*--------------------------------------------------------------------
68cdf0e10cSrcweir 	Beschreibung: DatenbankFeldTyp
69cdf0e10cSrcweir  --------------------------------------------------------------------*/
70cdf0e10cSrcweir 
SwDBFieldType(SwDoc * pDocPtr,const String & rNam,const SwDBData & rDBData)71cdf0e10cSrcweir SwDBFieldType::SwDBFieldType(SwDoc* pDocPtr, const String& rNam, const SwDBData& rDBData ) :
72cdf0e10cSrcweir 	SwValueFieldType( pDocPtr, RES_DBFLD ),
73cdf0e10cSrcweir 	aDBData(rDBData),
74cdf0e10cSrcweir 	sColumn(rNam),
75cdf0e10cSrcweir 	nRefCnt(0)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     if(aDBData.sDataSource.getLength() || aDBData.sCommand.getLength())
78cdf0e10cSrcweir     {
79cdf0e10cSrcweir         sName =  aDBData.sDataSource;
80cdf0e10cSrcweir         sName += DB_DELIM;
81cdf0e10cSrcweir         sName += (String)aDBData.sCommand;
82cdf0e10cSrcweir         sName += DB_DELIM;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 	sName += GetColumnName();
85cdf0e10cSrcweir }
86cdf0e10cSrcweir //------------------------------------------------------------------------------
~SwDBFieldType()87cdf0e10cSrcweir SwDBFieldType::~SwDBFieldType()
88cdf0e10cSrcweir {
89cdf0e10cSrcweir }
90cdf0e10cSrcweir //------------------------------------------------------------------------------
91cdf0e10cSrcweir 
Copy() const92cdf0e10cSrcweir SwFieldType* SwDBFieldType::Copy() const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	SwDBFieldType* pTmp = new SwDBFieldType(GetDoc(), sColumn, aDBData);
95cdf0e10cSrcweir 	return pTmp;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir //------------------------------------------------------------------------------
GetName() const99cdf0e10cSrcweir const String& SwDBFieldType::GetName() const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	return sName;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir //------------------------------------------------------------------------------
105cdf0e10cSrcweir 
ReleaseRef()106cdf0e10cSrcweir void SwDBFieldType::ReleaseRef()
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	ASSERT(nRefCnt > 0, "RefCount kleiner 0!");
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 	if (--nRefCnt <= 0)
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		sal_uInt16 nPos = GetDoc()->GetFldTypes()->GetPos(this);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 		if (nPos != USHRT_MAX)
115cdf0e10cSrcweir 		{
116cdf0e10cSrcweir 			GetDoc()->RemoveFldType(nPos);
117cdf0e10cSrcweir 			delete this;
118cdf0e10cSrcweir 		}
119cdf0e10cSrcweir 	}
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const122cdf0e10cSrcweir sal_Bool SwDBFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     switch( nWhichId )
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir     case FIELD_PROP_PAR1:
127cdf0e10cSrcweir 		rAny <<= aDBData.sDataSource;
128cdf0e10cSrcweir 		break;
129cdf0e10cSrcweir     case FIELD_PROP_PAR2:
130cdf0e10cSrcweir 		rAny <<= aDBData.sCommand;
131cdf0e10cSrcweir 		break;
132cdf0e10cSrcweir     case FIELD_PROP_PAR3:
133cdf0e10cSrcweir 		rAny <<= OUString(sColumn);
134cdf0e10cSrcweir 		break;
135cdf0e10cSrcweir 	case FIELD_PROP_SHORT1:
136cdf0e10cSrcweir 		rAny <<= aDBData.nCommandType;
137cdf0e10cSrcweir 		break;
138cdf0e10cSrcweir     default:
139cdf0e10cSrcweir 		DBG_ERROR("illegal property");
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 	return sal_True;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)144cdf0e10cSrcweir sal_Bool SwDBFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     switch( nWhichId )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir     case FIELD_PROP_PAR1:
149cdf0e10cSrcweir 		rAny >>= aDBData.sDataSource;
150cdf0e10cSrcweir 		break;
151cdf0e10cSrcweir     case FIELD_PROP_PAR2:
152cdf0e10cSrcweir 		rAny >>= aDBData.sCommand;
153cdf0e10cSrcweir 		break;
154cdf0e10cSrcweir     case FIELD_PROP_PAR3:
155cdf0e10cSrcweir 		{
156cdf0e10cSrcweir 			String sTmp;
157cdf0e10cSrcweir 			::GetString( rAny, sTmp );
158cdf0e10cSrcweir 			if( sTmp != sColumn )
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				sColumn = sTmp;
161cdf0e10cSrcweir 				SwIterator<SwFmtFld,SwFieldType> aIter( *this );
162*c0286415SOliver-Rainer Wittmann 				SwFmtFld* pFmtFld = aIter.First();
163*c0286415SOliver-Rainer Wittmann 				while(pFmtFld)
164cdf0e10cSrcweir 				{
165cdf0e10cSrcweir 					// Feld im Undo?
166*c0286415SOliver-Rainer Wittmann 					SwTxtFld *pTxtFld = pFmtFld->GetTxtFld();
167cdf0e10cSrcweir 					if(pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
168cdf0e10cSrcweir 					{
169*c0286415SOliver-Rainer Wittmann 						SwDBField* pDBField = (SwDBField*)pFmtFld->GetField();
170cdf0e10cSrcweir 						pDBField->ClearInitialized();
171cdf0e10cSrcweir 						pDBField->InitContent();
172cdf0e10cSrcweir  					}
173*c0286415SOliver-Rainer Wittmann 					pFmtFld = aIter.Next();
174cdf0e10cSrcweir 				}
175cdf0e10cSrcweir 			}
176cdf0e10cSrcweir 		}
177cdf0e10cSrcweir 		break;
178cdf0e10cSrcweir 	case FIELD_PROP_SHORT1:
179cdf0e10cSrcweir 		rAny >>= aDBData.nCommandType;
180cdf0e10cSrcweir 		break;
181cdf0e10cSrcweir 	default:
182cdf0e10cSrcweir 		DBG_ERROR("illegal property");
183cdf0e10cSrcweir 	}
184cdf0e10cSrcweir 	return sal_True;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir /*--------------------------------------------------------------------
187cdf0e10cSrcweir 	Beschreibung: SwDBField
188cdf0e10cSrcweir  --------------------------------------------------------------------*/
189cdf0e10cSrcweir 
SwDBField(SwDBFieldType * pTyp,sal_uLong nFmt)190cdf0e10cSrcweir SwDBField::SwDBField(SwDBFieldType* pTyp, sal_uLong nFmt)
191cdf0e10cSrcweir 	: 	SwValueField(pTyp, nFmt),
192cdf0e10cSrcweir 		nSubType(0),
193cdf0e10cSrcweir 		bIsInBodyTxt(sal_True),
194cdf0e10cSrcweir 		bValidValue(sal_False),
195cdf0e10cSrcweir 		bInitialized(sal_False)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	if (GetTyp())
198cdf0e10cSrcweir 		((SwDBFieldType*)GetTyp())->AddRef();
199cdf0e10cSrcweir 	InitContent();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir //------------------------------------------------------------------------------
203cdf0e10cSrcweir 
~SwDBField()204cdf0e10cSrcweir SwDBField::~SwDBField()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir 	if (GetTyp())
207cdf0e10cSrcweir 		((SwDBFieldType*)GetTyp())->ReleaseRef();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //------------------------------------------------------------------------------
211cdf0e10cSrcweir 
InitContent()212cdf0e10cSrcweir void SwDBField::InitContent()
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	if (!IsInitialized())
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 		aContent = '<';
217cdf0e10cSrcweir 		aContent += ((SwDBFieldType*)GetTyp())->GetColumnName();
218cdf0e10cSrcweir 		aContent += '>';
219cdf0e10cSrcweir 	}
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir //------------------------------------------------------------------------------
223cdf0e10cSrcweir 
InitContent(const String & rExpansion)224cdf0e10cSrcweir void SwDBField::InitContent(const String& rExpansion)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	if (rExpansion.Len() > 2)
227cdf0e10cSrcweir 	{
228cdf0e10cSrcweir 		if (rExpansion.GetChar(0) == '<' &&
229cdf0e10cSrcweir 			rExpansion.GetChar(rExpansion.Len() - 1) == '>')
230cdf0e10cSrcweir 		{
231cdf0e10cSrcweir 			String sColumn( rExpansion.Copy( 1, rExpansion.Len() - 2 ) );
232cdf0e10cSrcweir 			if( ::GetAppCmpStrIgnore().isEqual( sColumn,
233cdf0e10cSrcweir 							((SwDBFieldType *)GetTyp())->GetColumnName() ))
234cdf0e10cSrcweir 			{
235cdf0e10cSrcweir 				InitContent();
236cdf0e10cSrcweir 				return;
237cdf0e10cSrcweir 			}
238cdf0e10cSrcweir 		}
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 	SetExpansion( rExpansion );
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir //------------------------------------------------------------------------------
244cdf0e10cSrcweir 
Expand() const245cdf0e10cSrcweir String SwDBField::Expand() const
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     String sRet;
248cdf0e10cSrcweir 
249cdf0e10cSrcweir     if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
250cdf0e10cSrcweir         sRet = lcl_DBTrennConv(aContent);
251cdf0e10cSrcweir     return sRet;
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir //------------------------------------------------------------------------------
255cdf0e10cSrcweir 
Copy() const256cdf0e10cSrcweir SwField* SwDBField::Copy() const
257cdf0e10cSrcweir {
258cdf0e10cSrcweir 	SwDBField *pTmp = new SwDBField((SwDBFieldType*)GetTyp(), GetFormat());
259cdf0e10cSrcweir 	pTmp->aContent 		= aContent;
260cdf0e10cSrcweir 	pTmp->bIsInBodyTxt 	= bIsInBodyTxt;
261cdf0e10cSrcweir 	pTmp->bValidValue 	= bValidValue;
262cdf0e10cSrcweir 	pTmp->bInitialized	= bInitialized;
263cdf0e10cSrcweir 	pTmp->nSubType		= nSubType;
264cdf0e10cSrcweir 	pTmp->SetValue(GetValue());
265cdf0e10cSrcweir     pTmp->sFieldCode = sFieldCode;
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	return pTmp;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir 
GetFieldName() const270cdf0e10cSrcweir String SwDBField::GetFieldName() const
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     const String& rDBName = static_cast<SwDBFieldType*>(GetTyp())->GetName();
273cdf0e10cSrcweir         //TODO/CLEANUP
274cdf0e10cSrcweir         //Funktion tut nichts!
275cdf0e10cSrcweir         //String sContent( SFX_APP()->LocalizeDBName(INI2NATIONAL,
276cdf0e10cSrcweir         //                                    rDBName.GetToken(0, DB_DELIM)));
277cdf0e10cSrcweir     String sContent( rDBName.GetToken(0, DB_DELIM) );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir     if (sContent.Len() > 1)
280cdf0e10cSrcweir     {
281cdf0e10cSrcweir         sContent += DB_DELIM;
282cdf0e10cSrcweir         sContent += rDBName.GetToken(1, DB_DELIM);
283cdf0e10cSrcweir         sContent += DB_DELIM;
284cdf0e10cSrcweir         sContent += rDBName.GetToken(2, DB_DELIM);
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir     return lcl_DBTrennConv(sContent);
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir //------------------------------------------------------------------------------
290cdf0e10cSrcweir 
ChgValue(double d,sal_Bool bVal)291cdf0e10cSrcweir void SwDBField::ChgValue( double d, sal_Bool bVal )
292cdf0e10cSrcweir {
293cdf0e10cSrcweir 	bValidValue = bVal;
294cdf0e10cSrcweir 	SetValue(d);
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	if( bValidValue )
297cdf0e10cSrcweir 		aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(d, GetFormat(), GetLanguage());
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
300cdf0e10cSrcweir /*--------------------------------------------------------------------
301cdf0e10cSrcweir 	Beschreibung:
302cdf0e10cSrcweir  --------------------------------------------------------------------*/
303cdf0e10cSrcweir 
ChgTyp(SwFieldType * pNewType)304cdf0e10cSrcweir SwFieldType* SwDBField::ChgTyp( SwFieldType* pNewType )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	SwFieldType* pOld = SwValueField::ChgTyp( pNewType );
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 	((SwDBFieldType*)pNewType)->AddRef();
309cdf0e10cSrcweir 	((SwDBFieldType*)pOld)->ReleaseRef();
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 	return pOld;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir /*--------------------------------------------------------------------
315cdf0e10cSrcweir 	Beschreibung: Aktuellen Field-Value holen und chachen
316cdf0e10cSrcweir  --------------------------------------------------------------------*/
317cdf0e10cSrcweir 
Evaluate()318cdf0e10cSrcweir void SwDBField::Evaluate()
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	SwNewDBMgr* pMgr = GetDoc()->GetNewDBMgr();
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 	// erstmal loeschen
323cdf0e10cSrcweir 	bValidValue = sal_False;
324cdf0e10cSrcweir 	double nValue = DBL_MAX;
325cdf0e10cSrcweir 	const SwDBData& aTmpData = GetDBData();
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     if(!pMgr || !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
328cdf0e10cSrcweir 		return ;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	sal_uInt32 nFmt;
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 	// Passenden Spaltennamen suchen
333cdf0e10cSrcweir 	String aColNm( ((SwDBFieldType*)GetTyp())->GetColumnName() );
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	SvNumberFormatter* pDocFormatter = GetDoc()->GetNumberFormatter();
336cdf0e10cSrcweir 	pMgr->GetMergeColumnCnt(aColNm, GetLanguage(), aContent, &nValue, &nFmt);
337cdf0e10cSrcweir 	if( !( nSubType & nsSwExtendedSubType::SUB_OWN_FMT ) )
338cdf0e10cSrcweir 		SetFormat( nFmt = pMgr->GetColumnFmt( aTmpData.sDataSource, aTmpData.sCommand,
339cdf0e10cSrcweir 										aColNm, pDocFormatter, GetLanguage() ));
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	if( DBL_MAX != nValue )
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		sal_Int32 nColumnType = pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
344cdf0e10cSrcweir 		if(	DataType::DATE == nColumnType  || DataType::TIME == nColumnType  ||
345cdf0e10cSrcweir                  DataType::TIMESTAMP  == nColumnType)
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 		{
348cdf0e10cSrcweir 			Date aStandard(1,1,1900);
349cdf0e10cSrcweir 			if (*pDocFormatter->GetNullDate() != aStandard)
350cdf0e10cSrcweir 				nValue += (aStandard - *pDocFormatter->GetNullDate());
351cdf0e10cSrcweir 		}
352cdf0e10cSrcweir 		bValidValue = sal_True;
353cdf0e10cSrcweir 		SetValue(nValue);
354cdf0e10cSrcweir 		aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
355cdf0e10cSrcweir 	}
356cdf0e10cSrcweir 	else
357cdf0e10cSrcweir 	{
358cdf0e10cSrcweir 		SwSbxValue aVal;
359cdf0e10cSrcweir 		aVal.PutString( aContent );
360cdf0e10cSrcweir 
361cdf0e10cSrcweir 		if (aVal.IsNumeric())
362cdf0e10cSrcweir 		{
363cdf0e10cSrcweir 			SetValue(aVal.GetDouble());
364cdf0e10cSrcweir 
365cdf0e10cSrcweir 			SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
366cdf0e10cSrcweir             if (nFmt && nFmt != SAL_MAX_UINT32 && !pFormatter->IsTextFormat(nFmt))
367cdf0e10cSrcweir 				bValidValue = sal_True;	// Wegen Bug #60339 nicht mehr bei allen Strings
368cdf0e10cSrcweir 		}
369cdf0e10cSrcweir 		else
370cdf0e10cSrcweir 		{
371cdf0e10cSrcweir 			// Bei Strings sal_True wenn Laenge > 0 sonst sal_False
372cdf0e10cSrcweir 			SetValue(aContent.Len() ? 1 : 0);
373cdf0e10cSrcweir 		}
374cdf0e10cSrcweir 	}
375cdf0e10cSrcweir 	bInitialized = sal_True;
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir /*--------------------------------------------------------------------
379cdf0e10cSrcweir 	Beschreibung: Namen erfragen
380cdf0e10cSrcweir  --------------------------------------------------------------------*/
381cdf0e10cSrcweir 
GetPar1() const382cdf0e10cSrcweir const String& SwDBField::GetPar1() const
383cdf0e10cSrcweir {
384cdf0e10cSrcweir 	return ((SwDBFieldType*)GetTyp())->GetName();
385cdf0e10cSrcweir }
386cdf0e10cSrcweir 
387cdf0e10cSrcweir /*--------------------------------------------------------------------
388cdf0e10cSrcweir 	Beschreibung:
389cdf0e10cSrcweir  --------------------------------------------------------------------*/
390cdf0e10cSrcweir 
GetSubType() const391cdf0e10cSrcweir sal_uInt16 SwDBField::GetSubType() const
392cdf0e10cSrcweir {
393cdf0e10cSrcweir 	return nSubType;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir 
396cdf0e10cSrcweir /*--------------------------------------------------------------------
397cdf0e10cSrcweir 	Beschreibung:
398cdf0e10cSrcweir  --------------------------------------------------------------------*/
399cdf0e10cSrcweir 
SetSubType(sal_uInt16 nType)400cdf0e10cSrcweir void SwDBField::SetSubType(sal_uInt16 nType)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir 	nSubType = nType;
403cdf0e10cSrcweir }
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const406cdf0e10cSrcweir sal_Bool SwDBField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
407cdf0e10cSrcweir {
408cdf0e10cSrcweir     switch( nWhichId )
409cdf0e10cSrcweir 	{
410cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
411cdf0e10cSrcweir 		{
412cdf0e10cSrcweir 			sal_Bool bTemp = 0 == (GetSubType()&nsSwExtendedSubType::SUB_OWN_FMT);
413cdf0e10cSrcweir 			rAny.setValue(&bTemp, ::getBooleanCppuType());
414cdf0e10cSrcweir 		}
415cdf0e10cSrcweir 		break;
416cdf0e10cSrcweir     case FIELD_PROP_BOOL2:
417cdf0e10cSrcweir     {
418cdf0e10cSrcweir         sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
419cdf0e10cSrcweir         rAny.setValue(&bVal, ::getBooleanCppuType());
420cdf0e10cSrcweir     }
421cdf0e10cSrcweir     break;
422cdf0e10cSrcweir     case FIELD_PROP_FORMAT:
423cdf0e10cSrcweir 		rAny <<= (sal_Int32)GetFormat();
424cdf0e10cSrcweir 		break;
425cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
426cdf0e10cSrcweir 		rAny <<= OUString(aContent);
427cdf0e10cSrcweir 		break;
428cdf0e10cSrcweir     case FIELD_PROP_PAR2:
429cdf0e10cSrcweir         rAny <<= OUString(sFieldCode);
430cdf0e10cSrcweir         break;
431cdf0e10cSrcweir     default:
432cdf0e10cSrcweir 		DBG_ERROR("illegal property");
433cdf0e10cSrcweir 	}
434cdf0e10cSrcweir 	return sal_True;
435cdf0e10cSrcweir 
436cdf0e10cSrcweir }
437cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)438cdf0e10cSrcweir sal_Bool SwDBField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
439cdf0e10cSrcweir {
440cdf0e10cSrcweir     switch( nWhichId )
441cdf0e10cSrcweir 	{
442cdf0e10cSrcweir 	case FIELD_PROP_BOOL1:
443cdf0e10cSrcweir 		if( *(sal_Bool*)rAny.getValue() )
444cdf0e10cSrcweir 			SetSubType(GetSubType()&~nsSwExtendedSubType::SUB_OWN_FMT);
445cdf0e10cSrcweir 		else
446cdf0e10cSrcweir 			SetSubType(GetSubType()|nsSwExtendedSubType::SUB_OWN_FMT);
447cdf0e10cSrcweir 		break;
448cdf0e10cSrcweir     case FIELD_PROP_BOOL2:
449cdf0e10cSrcweir     {
450cdf0e10cSrcweir         sal_uInt16 nSubTyp = GetSubType();
451cdf0e10cSrcweir         sal_Bool bVisible = sal_False;
452cdf0e10cSrcweir         if(!(rAny >>= bVisible))
453cdf0e10cSrcweir             return sal_False;
454cdf0e10cSrcweir         if(bVisible)
455cdf0e10cSrcweir             nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
456cdf0e10cSrcweir         else
457cdf0e10cSrcweir             nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
458cdf0e10cSrcweir         SetSubType(nSubTyp);
459cdf0e10cSrcweir         //invalidate text node
460cdf0e10cSrcweir         if(GetTyp())
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             SwIterator<SwFmtFld,SwFieldType> aIter( *GetTyp() );
463*c0286415SOliver-Rainer Wittmann             SwFmtFld* pFmtFld = aIter.First();
464*c0286415SOliver-Rainer Wittmann             while(pFmtFld)
465cdf0e10cSrcweir             {
466*c0286415SOliver-Rainer Wittmann                 SwTxtFld *pTxtFld = pFmtFld->GetTxtFld();
467*c0286415SOliver-Rainer Wittmann                 if(pTxtFld && (SwDBField*)pFmtFld->GetField() == this )
468cdf0e10cSrcweir                 {
469cdf0e10cSrcweir                     //notify the change
470*c0286415SOliver-Rainer Wittmann                     pTxtFld->NotifyContentChange(*pFmtFld);
471cdf0e10cSrcweir                     break;
472cdf0e10cSrcweir                 }
473*c0286415SOliver-Rainer Wittmann                 pFmtFld = aIter.Next();
474cdf0e10cSrcweir             }
475cdf0e10cSrcweir         }
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir     break;
478cdf0e10cSrcweir     case FIELD_PROP_FORMAT:
479cdf0e10cSrcweir 		{
480cdf0e10cSrcweir 			sal_Int32 nTemp = 0;
481cdf0e10cSrcweir 			rAny >>= nTemp;
482cdf0e10cSrcweir 			SetFormat(nTemp);
483cdf0e10cSrcweir 		}
484cdf0e10cSrcweir 		break;
485cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
486cdf0e10cSrcweir 		::GetString( rAny, aContent );
487cdf0e10cSrcweir 		break;
488cdf0e10cSrcweir     case FIELD_PROP_PAR2:
489cdf0e10cSrcweir         ::GetString( rAny, sFieldCode );
490cdf0e10cSrcweir     break;
491cdf0e10cSrcweir 	default:
492cdf0e10cSrcweir 		DBG_ERROR("illegal property");
493cdf0e10cSrcweir 	}
494cdf0e10cSrcweir 	return sal_True;
495cdf0e10cSrcweir }
496cdf0e10cSrcweir 
497cdf0e10cSrcweir /*--------------------------------------------------------------------
498cdf0e10cSrcweir 	Beschreibung: Basisklasse fuer alle weiteren Datenbankfelder
499cdf0e10cSrcweir  --------------------------------------------------------------------*/
500cdf0e10cSrcweir 
SwDBNameInfField(SwFieldType * pTyp,const SwDBData & rDBData,sal_uLong nFmt)501cdf0e10cSrcweir SwDBNameInfField::SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt) :
502cdf0e10cSrcweir 	SwField(pTyp, nFmt),
503cdf0e10cSrcweir     aDBData(rDBData),
504cdf0e10cSrcweir     nSubType(0)
505cdf0e10cSrcweir {
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir //------------------------------------------------------------------------------
509cdf0e10cSrcweir 
GetDBData(SwDoc * pDoc)510cdf0e10cSrcweir SwDBData SwDBNameInfField::GetDBData(SwDoc* pDoc)
511cdf0e10cSrcweir {
512cdf0e10cSrcweir 	SwDBData aRet;
513cdf0e10cSrcweir 	if(aDBData.sDataSource.getLength())
514cdf0e10cSrcweir 		aRet = aDBData;
515cdf0e10cSrcweir 	else
516cdf0e10cSrcweir 		aRet = pDoc->GetDBData();
517cdf0e10cSrcweir 	return aRet;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir // #111840#
SetDBData(const SwDBData & rDBData)521cdf0e10cSrcweir void SwDBNameInfField::SetDBData(const SwDBData & rDBData)
522cdf0e10cSrcweir {
523cdf0e10cSrcweir     aDBData = rDBData;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir //------------------------------------------------------------------------------
527cdf0e10cSrcweir 
GetFieldName() const528cdf0e10cSrcweir String SwDBNameInfField::GetFieldName() const
529cdf0e10cSrcweir {
530cdf0e10cSrcweir     String sStr( SwField::GetFieldName() );
531cdf0e10cSrcweir     if (aDBData.sDataSource.getLength())
532cdf0e10cSrcweir     {
533cdf0e10cSrcweir         sStr += ':';
534cdf0e10cSrcweir         sStr += String(aDBData.sDataSource);
535cdf0e10cSrcweir         sStr += DB_DELIM;
536cdf0e10cSrcweir         sStr += String(aDBData.sCommand);
537cdf0e10cSrcweir     }
538cdf0e10cSrcweir 	return lcl_DBTrennConv(sStr);
539cdf0e10cSrcweir }
540cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const541cdf0e10cSrcweir sal_Bool SwDBNameInfField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
542cdf0e10cSrcweir {
543cdf0e10cSrcweir     switch( nWhichId )
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
546cdf0e10cSrcweir 		rAny <<= aDBData.sDataSource;
547cdf0e10cSrcweir 		break;
548cdf0e10cSrcweir 	case FIELD_PROP_PAR2:
549cdf0e10cSrcweir 		rAny <<= aDBData.sCommand;
550cdf0e10cSrcweir 		break;
551cdf0e10cSrcweir 	case FIELD_PROP_SHORT1:
552cdf0e10cSrcweir 		rAny <<= aDBData.nCommandType;
553cdf0e10cSrcweir 		break;
554cdf0e10cSrcweir     case FIELD_PROP_BOOL2:
555cdf0e10cSrcweir     {
556cdf0e10cSrcweir         sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
557cdf0e10cSrcweir         rAny.setValue(&bVal, ::getBooleanCppuType());
558cdf0e10cSrcweir     }
559cdf0e10cSrcweir     break;
560cdf0e10cSrcweir     default:
561cdf0e10cSrcweir 		DBG_ERROR("illegal property");
562cdf0e10cSrcweir 	}
563cdf0e10cSrcweir 	return sal_True;
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)566cdf0e10cSrcweir sal_Bool SwDBNameInfField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
567cdf0e10cSrcweir {
568cdf0e10cSrcweir     switch( nWhichId )
569cdf0e10cSrcweir 	{
570cdf0e10cSrcweir 	case FIELD_PROP_PAR1:
571cdf0e10cSrcweir 		rAny >>= aDBData.sDataSource;
572cdf0e10cSrcweir 		break;
573cdf0e10cSrcweir 	case FIELD_PROP_PAR2:
574cdf0e10cSrcweir 		rAny >>= aDBData.sCommand;
575cdf0e10cSrcweir 		break;
576cdf0e10cSrcweir 	case FIELD_PROP_SHORT1:
577cdf0e10cSrcweir 		rAny >>= aDBData.nCommandType;
578cdf0e10cSrcweir 		break;
579cdf0e10cSrcweir     case FIELD_PROP_BOOL2:
580cdf0e10cSrcweir     {
581cdf0e10cSrcweir         sal_uInt16 nSubTyp = GetSubType();
582cdf0e10cSrcweir         sal_Bool bVisible = sal_False;
583cdf0e10cSrcweir         if(!(rAny >>= bVisible))
584cdf0e10cSrcweir             return sal_False;
585cdf0e10cSrcweir         if(bVisible)
586cdf0e10cSrcweir             nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
587cdf0e10cSrcweir         else
588cdf0e10cSrcweir             nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
589cdf0e10cSrcweir         SetSubType(nSubTyp);
590cdf0e10cSrcweir     }
591cdf0e10cSrcweir     break;
592cdf0e10cSrcweir     default:
593cdf0e10cSrcweir 		DBG_ERROR("illegal property");
594cdf0e10cSrcweir 	}
595cdf0e10cSrcweir 	return sal_True;
596cdf0e10cSrcweir }
597cdf0e10cSrcweir 
GetSubType() const598cdf0e10cSrcweir sal_uInt16 SwDBNameInfField::GetSubType() const
599cdf0e10cSrcweir {
600cdf0e10cSrcweir     return nSubType;
601cdf0e10cSrcweir }
602cdf0e10cSrcweir 
SetSubType(sal_uInt16 nType)603cdf0e10cSrcweir void SwDBNameInfField::SetSubType(sal_uInt16 nType)
604cdf0e10cSrcweir {
605cdf0e10cSrcweir     nSubType = nType;
606cdf0e10cSrcweir }
607cdf0e10cSrcweir 
608cdf0e10cSrcweir /*--------------------------------------------------------------------
609cdf0e10cSrcweir 	Beschreibung: NaechsterDatensatz
610cdf0e10cSrcweir  --------------------------------------------------------------------*/
611cdf0e10cSrcweir 
SwDBNextSetFieldType()612cdf0e10cSrcweir SwDBNextSetFieldType::SwDBNextSetFieldType()
613cdf0e10cSrcweir 	: SwFieldType( RES_DBNEXTSETFLD )
614cdf0e10cSrcweir {
615cdf0e10cSrcweir }
616cdf0e10cSrcweir 
617cdf0e10cSrcweir //------------------------------------------------------------------------------
618cdf0e10cSrcweir 
Copy() const619cdf0e10cSrcweir SwFieldType* SwDBNextSetFieldType::Copy() const
620cdf0e10cSrcweir {
621cdf0e10cSrcweir 	SwDBNextSetFieldType* pTmp = new SwDBNextSetFieldType();
622cdf0e10cSrcweir     return pTmp;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir /*--------------------------------------------------------------------
625cdf0e10cSrcweir 	Beschreibung: SwDBSetField
626cdf0e10cSrcweir  --------------------------------------------------------------------*/
627cdf0e10cSrcweir 
SwDBNextSetField(SwDBNextSetFieldType * pTyp,const String & rCond,const String &,const SwDBData & rDBData)628cdf0e10cSrcweir SwDBNextSetField::SwDBNextSetField(SwDBNextSetFieldType* pTyp,
629cdf0e10cSrcweir 								   const String& rCond,
630cdf0e10cSrcweir 								   const String& ,
631cdf0e10cSrcweir 								   const SwDBData& rDBData) :
632cdf0e10cSrcweir 	SwDBNameInfField(pTyp, rDBData), aCond(rCond), bCondValid(sal_True)
633cdf0e10cSrcweir {}
634cdf0e10cSrcweir 
635cdf0e10cSrcweir //------------------------------------------------------------------------------
636cdf0e10cSrcweir 
Expand() const637cdf0e10cSrcweir String SwDBNextSetField::Expand() const
638cdf0e10cSrcweir {
639cdf0e10cSrcweir 	return aEmptyStr;
640cdf0e10cSrcweir }
641cdf0e10cSrcweir 
642cdf0e10cSrcweir //------------------------------------------------------------------------------
643cdf0e10cSrcweir 
Copy() const644cdf0e10cSrcweir SwField* SwDBNextSetField::Copy() const
645cdf0e10cSrcweir {
646cdf0e10cSrcweir 	SwDBNextSetField *pTmp = new SwDBNextSetField((SwDBNextSetFieldType*)GetTyp(),
647cdf0e10cSrcweir 										 aCond, aEmptyStr, GetDBData());
648cdf0e10cSrcweir     pTmp->SetSubType(GetSubType());
649cdf0e10cSrcweir     pTmp->bCondValid = bCondValid;
650cdf0e10cSrcweir 	return pTmp;
651cdf0e10cSrcweir }
652cdf0e10cSrcweir //------------------------------------------------------------------------------
653cdf0e10cSrcweir 
Evaluate(SwDoc * pDoc)654cdf0e10cSrcweir void SwDBNextSetField::Evaluate(SwDoc* pDoc)
655cdf0e10cSrcweir {
656cdf0e10cSrcweir 	SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
657cdf0e10cSrcweir 	const SwDBData& rData = GetDBData();
658cdf0e10cSrcweir 	if( !bCondValid ||
659cdf0e10cSrcweir             !pMgr || !pMgr->IsDataSourceOpen(rData.sDataSource, rData.sCommand, sal_False))
660cdf0e10cSrcweir 		return ;
661cdf0e10cSrcweir     pMgr->ToNextRecord(rData.sDataSource, rData.sCommand);
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
664cdf0e10cSrcweir /*--------------------------------------------------------------------
665cdf0e10cSrcweir 	Beschreibung: Bedingung
666cdf0e10cSrcweir  --------------------------------------------------------------------*/
667cdf0e10cSrcweir 
GetPar1() const668cdf0e10cSrcweir const String& SwDBNextSetField::GetPar1() const
669cdf0e10cSrcweir {
670cdf0e10cSrcweir 	return aCond;
671cdf0e10cSrcweir }
672cdf0e10cSrcweir 
SetPar1(const String & rStr)673cdf0e10cSrcweir void SwDBNextSetField::SetPar1(const String& rStr)
674cdf0e10cSrcweir {
675cdf0e10cSrcweir 	aCond = rStr;
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const678cdf0e10cSrcweir sal_Bool SwDBNextSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
679cdf0e10cSrcweir {
680cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
681cdf0e10cSrcweir     switch( nWhichId )
682cdf0e10cSrcweir 	{
683cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
684cdf0e10cSrcweir 		rAny <<= OUString(aCond);
685cdf0e10cSrcweir 		break;
686cdf0e10cSrcweir 	default:
687cdf0e10cSrcweir         bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
688cdf0e10cSrcweir 	}
689cdf0e10cSrcweir 	return bRet;
690cdf0e10cSrcweir }
691cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)692cdf0e10cSrcweir sal_Bool SwDBNextSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
693cdf0e10cSrcweir {
694cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
695cdf0e10cSrcweir     switch( nWhichId )
696cdf0e10cSrcweir 	{
697cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
698cdf0e10cSrcweir 		::GetString( rAny, aCond );
699cdf0e10cSrcweir 		break;
700cdf0e10cSrcweir 	default:
701cdf0e10cSrcweir         bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
702cdf0e10cSrcweir 	}
703cdf0e10cSrcweir 	return bRet;
704cdf0e10cSrcweir }
705cdf0e10cSrcweir 
706cdf0e10cSrcweir /*--------------------------------------------------------------------
707cdf0e10cSrcweir 	Beschreibung: Datensatz mit bestimmter ID
708cdf0e10cSrcweir  --------------------------------------------------------------------*/
709cdf0e10cSrcweir 
SwDBNumSetFieldType()710cdf0e10cSrcweir SwDBNumSetFieldType::SwDBNumSetFieldType() :
711cdf0e10cSrcweir 	SwFieldType( RES_DBNUMSETFLD )
712cdf0e10cSrcweir {
713cdf0e10cSrcweir }
714cdf0e10cSrcweir 
715cdf0e10cSrcweir //------------------------------------------------------------------------------
716cdf0e10cSrcweir 
Copy() const717cdf0e10cSrcweir SwFieldType* SwDBNumSetFieldType::Copy() const
718cdf0e10cSrcweir {
719cdf0e10cSrcweir 	SwDBNumSetFieldType* pTmp = new SwDBNumSetFieldType();
720cdf0e10cSrcweir 	return pTmp;
721cdf0e10cSrcweir }
722cdf0e10cSrcweir 
723cdf0e10cSrcweir /*--------------------------------------------------------------------
724cdf0e10cSrcweir 	Beschreibung: SwDBSetField
725cdf0e10cSrcweir  --------------------------------------------------------------------*/
726cdf0e10cSrcweir 
SwDBNumSetField(SwDBNumSetFieldType * pTyp,const String & rCond,const String & rDBNum,const SwDBData & rDBData)727cdf0e10cSrcweir SwDBNumSetField::SwDBNumSetField(SwDBNumSetFieldType* pTyp,
728cdf0e10cSrcweir 								 const String& rCond,
729cdf0e10cSrcweir 								 const String& rDBNum,
730cdf0e10cSrcweir 								 const SwDBData& rDBData) :
731cdf0e10cSrcweir 	SwDBNameInfField(pTyp, rDBData),
732cdf0e10cSrcweir 	aCond(rCond),
733cdf0e10cSrcweir 	aPar2(rDBNum),
734cdf0e10cSrcweir 	bCondValid(sal_True)
735cdf0e10cSrcweir {}
736cdf0e10cSrcweir 
737cdf0e10cSrcweir //------------------------------------------------------------------------------
738cdf0e10cSrcweir 
Expand() const739cdf0e10cSrcweir String SwDBNumSetField::Expand() const
740cdf0e10cSrcweir {
741cdf0e10cSrcweir 	return aEmptyStr;
742cdf0e10cSrcweir }
743cdf0e10cSrcweir 
744cdf0e10cSrcweir //------------------------------------------------------------------------------
745cdf0e10cSrcweir 
Copy() const746cdf0e10cSrcweir SwField* SwDBNumSetField::Copy() const
747cdf0e10cSrcweir {
748cdf0e10cSrcweir 	SwDBNumSetField *pTmp = new SwDBNumSetField((SwDBNumSetFieldType*)GetTyp(),
749cdf0e10cSrcweir 										 aCond, aPar2, GetDBData());
750cdf0e10cSrcweir 	pTmp->bCondValid = bCondValid;
751cdf0e10cSrcweir     pTmp->SetSubType(GetSubType());
752cdf0e10cSrcweir     return pTmp;
753cdf0e10cSrcweir }
754cdf0e10cSrcweir 
Evaluate(SwDoc * pDoc)755cdf0e10cSrcweir void SwDBNumSetField::Evaluate(SwDoc* pDoc)
756cdf0e10cSrcweir {
757cdf0e10cSrcweir 	SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
758cdf0e10cSrcweir 	const SwDBData& aTmpData = GetDBData();
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	if( bCondValid && pMgr && pMgr->IsInMerge() &&
761cdf0e10cSrcweir                         pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
762cdf0e10cSrcweir 	{	// Bedingug OK -> aktuellen Set einstellen
763cdf0e10cSrcweir 		pMgr->ToRecordId(Max((sal_uInt16)aPar2.ToInt32(), sal_uInt16(1))-1);
764cdf0e10cSrcweir 	}
765cdf0e10cSrcweir }
766cdf0e10cSrcweir 
767cdf0e10cSrcweir /*--------------------------------------------------------------------
768cdf0e10cSrcweir 	Beschreibung: LogDBName
769cdf0e10cSrcweir  --------------------------------------------------------------------*/
770cdf0e10cSrcweir 
GetPar1() const771cdf0e10cSrcweir const String& SwDBNumSetField::GetPar1() const
772cdf0e10cSrcweir {
773cdf0e10cSrcweir 	return aCond;
774cdf0e10cSrcweir }
775cdf0e10cSrcweir 
SetPar1(const String & rStr)776cdf0e10cSrcweir void SwDBNumSetField::SetPar1(const String& rStr)
777cdf0e10cSrcweir {
778cdf0e10cSrcweir 	aCond = rStr;
779cdf0e10cSrcweir }
780cdf0e10cSrcweir 
781cdf0e10cSrcweir /*--------------------------------------------------------------------
782cdf0e10cSrcweir 	Beschreibung: Bedingung
783cdf0e10cSrcweir  --------------------------------------------------------------------*/
784cdf0e10cSrcweir 
GetPar2() const785cdf0e10cSrcweir String SwDBNumSetField::GetPar2() const
786cdf0e10cSrcweir {
787cdf0e10cSrcweir 	return aPar2;
788cdf0e10cSrcweir }
789cdf0e10cSrcweir 
SetPar2(const String & rStr)790cdf0e10cSrcweir void SwDBNumSetField::SetPar2(const String& rStr)
791cdf0e10cSrcweir {
792cdf0e10cSrcweir 	aPar2 = rStr;
793cdf0e10cSrcweir }
794cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const795cdf0e10cSrcweir sal_Bool SwDBNumSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
796cdf0e10cSrcweir {
797cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
798cdf0e10cSrcweir     switch( nWhichId )
799cdf0e10cSrcweir 	{
800cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
801cdf0e10cSrcweir 		rAny <<= OUString(aCond);
802cdf0e10cSrcweir 		break;
803cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
804cdf0e10cSrcweir 		rAny <<= (sal_Int32)aPar2.ToInt32();
805cdf0e10cSrcweir 		break;
806cdf0e10cSrcweir 	default:
807cdf0e10cSrcweir         bRet = SwDBNameInfField::QueryValue(rAny, nWhichId );
808cdf0e10cSrcweir 	}
809cdf0e10cSrcweir 	return bRet;
810cdf0e10cSrcweir }
811cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)812cdf0e10cSrcweir sal_Bool    SwDBNumSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
813cdf0e10cSrcweir {
814cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
815cdf0e10cSrcweir     switch( nWhichId )
816cdf0e10cSrcweir 	{
817cdf0e10cSrcweir 	case FIELD_PROP_PAR3:
818cdf0e10cSrcweir 		::GetString( rAny, aCond );
819cdf0e10cSrcweir 		break;
820cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
821cdf0e10cSrcweir 		{
822cdf0e10cSrcweir 			sal_Int32 nVal = 0;
823cdf0e10cSrcweir 			rAny >>= nVal;
824cdf0e10cSrcweir 			aPar2 = String::CreateFromInt32(nVal);
825cdf0e10cSrcweir 		}
826cdf0e10cSrcweir 		break;
827cdf0e10cSrcweir 	default:
828cdf0e10cSrcweir         bRet = SwDBNameInfField::PutValue(rAny, nWhichId );
829cdf0e10cSrcweir 	}
830cdf0e10cSrcweir 	return bRet;
831cdf0e10cSrcweir }
832cdf0e10cSrcweir 
833cdf0e10cSrcweir /*--------------------------------------------------------------------
834cdf0e10cSrcweir 	Beschreibung: SwDBNameFieldType
835cdf0e10cSrcweir  --------------------------------------------------------------------*/
836cdf0e10cSrcweir 
SwDBNameFieldType(SwDoc * pDocument)837cdf0e10cSrcweir SwDBNameFieldType::SwDBNameFieldType(SwDoc* pDocument)
838cdf0e10cSrcweir 	: SwFieldType( RES_DBNAMEFLD )
839cdf0e10cSrcweir {
840cdf0e10cSrcweir 	pDoc = pDocument;
841cdf0e10cSrcweir }
842cdf0e10cSrcweir //------------------------------------------------------------------------------
843cdf0e10cSrcweir 
Expand(sal_uLong) const844cdf0e10cSrcweir String SwDBNameFieldType::Expand(sal_uLong ) const
845cdf0e10cSrcweir {
846cdf0e10cSrcweir 	const SwDBData aData = pDoc->GetDBData();
847cdf0e10cSrcweir 	String sRet(aData.sDataSource);
848cdf0e10cSrcweir 	sRet += '.';
849cdf0e10cSrcweir 	sRet += (String)aData.sCommand;
850cdf0e10cSrcweir 	return sRet;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir //------------------------------------------------------------------------------
853cdf0e10cSrcweir 
Copy() const854cdf0e10cSrcweir SwFieldType* SwDBNameFieldType::Copy() const
855cdf0e10cSrcweir {
856cdf0e10cSrcweir 	SwDBNameFieldType *pTmp = new SwDBNameFieldType(pDoc);
857cdf0e10cSrcweir 	return pTmp;
858cdf0e10cSrcweir }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir //------------------------------------------------------------------------------
861cdf0e10cSrcweir 
862cdf0e10cSrcweir /*--------------------------------------------------------------------
863cdf0e10cSrcweir 	Beschreibung: Name der angedockten DB
864cdf0e10cSrcweir  --------------------------------------------------------------------*/
865cdf0e10cSrcweir 
SwDBNameField(SwDBNameFieldType * pTyp,const SwDBData & rDBData,sal_uLong nFmt)866cdf0e10cSrcweir SwDBNameField::SwDBNameField(SwDBNameFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt)
867cdf0e10cSrcweir 	: SwDBNameInfField(pTyp, rDBData, nFmt)
868cdf0e10cSrcweir {}
869cdf0e10cSrcweir 
870cdf0e10cSrcweir //------------------------------------------------------------------------------
871cdf0e10cSrcweir 
Expand() const872cdf0e10cSrcweir String SwDBNameField::Expand() const
873cdf0e10cSrcweir {
874cdf0e10cSrcweir     String sRet;
875cdf0e10cSrcweir     if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
876cdf0e10cSrcweir         sRet = ((SwDBNameFieldType*)GetTyp())->Expand(GetFormat());
877cdf0e10cSrcweir     return sRet;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir //------------------------------------------------------------------------------
881cdf0e10cSrcweir 
Copy() const882cdf0e10cSrcweir SwField* SwDBNameField::Copy() const
883cdf0e10cSrcweir {
884cdf0e10cSrcweir 	SwDBNameField *pTmp = new SwDBNameField((SwDBNameFieldType*)GetTyp(), GetDBData());
885cdf0e10cSrcweir 	pTmp->ChangeFormat(GetFormat());
886cdf0e10cSrcweir 	pTmp->SetLanguage(GetLanguage());
887cdf0e10cSrcweir     pTmp->SetSubType(GetSubType());
888cdf0e10cSrcweir 	return pTmp;
889cdf0e10cSrcweir }
890cdf0e10cSrcweir 
891cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const892cdf0e10cSrcweir sal_Bool SwDBNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
893cdf0e10cSrcweir {
894cdf0e10cSrcweir     return SwDBNameInfField::QueryValue(rAny, nWhichId );
895cdf0e10cSrcweir }
896cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)897cdf0e10cSrcweir sal_Bool SwDBNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
898cdf0e10cSrcweir {
899cdf0e10cSrcweir     return SwDBNameInfField::PutValue(rAny, nWhichId );
900cdf0e10cSrcweir }
901cdf0e10cSrcweir /*--------------------------------------------------------------------
902cdf0e10cSrcweir 	Beschreibung: SwDBNameFieldType
903cdf0e10cSrcweir  --------------------------------------------------------------------*/
904cdf0e10cSrcweir 
SwDBSetNumberFieldType()905cdf0e10cSrcweir SwDBSetNumberFieldType::SwDBSetNumberFieldType()
906cdf0e10cSrcweir 	: SwFieldType( RES_DBSETNUMBERFLD )
907cdf0e10cSrcweir {
908cdf0e10cSrcweir }
909cdf0e10cSrcweir 
910cdf0e10cSrcweir //------------------------------------------------------------------------------
911cdf0e10cSrcweir 
Copy() const912cdf0e10cSrcweir SwFieldType* SwDBSetNumberFieldType::Copy() const
913cdf0e10cSrcweir {
914cdf0e10cSrcweir 	SwDBSetNumberFieldType *pTmp = new SwDBSetNumberFieldType;
915cdf0e10cSrcweir 	return pTmp;
916cdf0e10cSrcweir }
917cdf0e10cSrcweir 
918cdf0e10cSrcweir //------------------------------------------------------------------------------
919cdf0e10cSrcweir 
920cdf0e10cSrcweir /*--------------------------------------------------------------------
921cdf0e10cSrcweir 	Beschreibung: SetNumber der angedockten DB
922cdf0e10cSrcweir  --------------------------------------------------------------------*/
923cdf0e10cSrcweir 
SwDBSetNumberField(SwDBSetNumberFieldType * pTyp,const SwDBData & rDBData,sal_uLong nFmt)924cdf0e10cSrcweir SwDBSetNumberField::SwDBSetNumberField(SwDBSetNumberFieldType* pTyp,
925cdf0e10cSrcweir 									   const SwDBData& rDBData,
926cdf0e10cSrcweir 									   sal_uLong nFmt)
927cdf0e10cSrcweir 	: SwDBNameInfField(pTyp, rDBData, nFmt), nNumber(0)
928cdf0e10cSrcweir {}
929cdf0e10cSrcweir 
930cdf0e10cSrcweir //------------------------------------------------------------------------------
931cdf0e10cSrcweir 
Expand() const932cdf0e10cSrcweir String SwDBSetNumberField::Expand() const
933cdf0e10cSrcweir {
934cdf0e10cSrcweir     if(0 !=(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE) || nNumber == 0)
935cdf0e10cSrcweir 		return aEmptyStr;
936cdf0e10cSrcweir 	else
937cdf0e10cSrcweir 		return FormatNumber((sal_uInt16)nNumber, GetFormat());
938cdf0e10cSrcweir }
939cdf0e10cSrcweir 
940cdf0e10cSrcweir //------------------------------------------------------------------------------
941cdf0e10cSrcweir 
Evaluate(SwDoc * pDoc)942cdf0e10cSrcweir void SwDBSetNumberField::Evaluate(SwDoc* pDoc)
943cdf0e10cSrcweir {
944cdf0e10cSrcweir 	SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
945cdf0e10cSrcweir 
946cdf0e10cSrcweir     const SwDBData& aTmpData = GetDBData();
947cdf0e10cSrcweir     if (!pMgr || !pMgr->IsInMerge() ||
948cdf0e10cSrcweir         !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_False))
949cdf0e10cSrcweir         return;
950cdf0e10cSrcweir     nNumber = pMgr->GetSelectedRecordId();
951cdf0e10cSrcweir }
952cdf0e10cSrcweir 
953cdf0e10cSrcweir 
954cdf0e10cSrcweir //------------------------------------------------------------------------------
955cdf0e10cSrcweir 
Copy() const956cdf0e10cSrcweir SwField* SwDBSetNumberField::Copy() const
957cdf0e10cSrcweir {
958cdf0e10cSrcweir 	SwDBSetNumberField *pTmp =
959cdf0e10cSrcweir 		new SwDBSetNumberField((SwDBSetNumberFieldType*)GetTyp(), GetDBData(), GetFormat());
960cdf0e10cSrcweir 	pTmp->SetLanguage(GetLanguage());
961cdf0e10cSrcweir 	pTmp->SetSetNumber(nNumber);
962cdf0e10cSrcweir     pTmp->SetSubType(GetSubType());
963cdf0e10cSrcweir     return pTmp;
964cdf0e10cSrcweir }
965cdf0e10cSrcweir 
QueryValue(uno::Any & rAny,sal_uInt16 nWhichId) const966cdf0e10cSrcweir sal_Bool SwDBSetNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
967cdf0e10cSrcweir {
968cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
969cdf0e10cSrcweir     switch( nWhichId )
970cdf0e10cSrcweir 	{
971cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
972cdf0e10cSrcweir 		rAny <<= (sal_Int16)GetFormat();
973cdf0e10cSrcweir 		break;
974cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
975cdf0e10cSrcweir 		rAny <<= nNumber;
976cdf0e10cSrcweir 		break;
977cdf0e10cSrcweir 	default:
978cdf0e10cSrcweir         bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
979cdf0e10cSrcweir 	}
980cdf0e10cSrcweir 	return bRet;
981cdf0e10cSrcweir }
982cdf0e10cSrcweir 
PutValue(const uno::Any & rAny,sal_uInt16 nWhichId)983cdf0e10cSrcweir sal_Bool SwDBSetNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
984cdf0e10cSrcweir {
985cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
986cdf0e10cSrcweir     switch( nWhichId )
987cdf0e10cSrcweir 	{
988cdf0e10cSrcweir 	case FIELD_PROP_USHORT1:
989cdf0e10cSrcweir 		{
990cdf0e10cSrcweir 			sal_Int16 nSet = 0;
991cdf0e10cSrcweir 			rAny >>= nSet;
992cdf0e10cSrcweir 			if(nSet < (sal_Int16) SVX_NUMBER_NONE )
993cdf0e10cSrcweir 				SetFormat(nSet);
994cdf0e10cSrcweir 			else {
995cdf0e10cSrcweir 				//exception(wrong_value)
996cdf0e10cSrcweir 				;
997cdf0e10cSrcweir             }
998cdf0e10cSrcweir 		}
999cdf0e10cSrcweir 		break;
1000cdf0e10cSrcweir 	case FIELD_PROP_FORMAT:
1001cdf0e10cSrcweir 		rAny >>= nNumber;
1002cdf0e10cSrcweir 		break;
1003cdf0e10cSrcweir 	default:
1004cdf0e10cSrcweir         bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
1005cdf0e10cSrcweir 	}
1006cdf0e10cSrcweir 	return bRet;
1007cdf0e10cSrcweir }
1008cdf0e10cSrcweir 
1009cdf0e10cSrcweir 
1010