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