merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / fields / dbfld.cxx
blob442cbd5d1e0ffb741dab1dd750be36bf295aaa0a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbfld.cxx,v $
10 * $Revision: 1.31 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <float.h>
36 #include <sfx2/app.hxx>
37 #include <svtools/zforlist.hxx>
38 #include <svx/pageitem.hxx>
39 #include <svx/dataaccessdescriptor.hxx>
40 #include <com/sun/star/sdbc/DataType.hpp>
41 #include <fmtfld.hxx>
42 #include <txtfld.hxx>
43 #include <doc.hxx>
44 #include <docary.hxx>
45 #include <frame.hxx>
46 #include <fldbas.hxx>
47 #include <pam.hxx>
48 #include <ndtxt.hxx>
49 #include <dbfld.hxx>
50 #ifndef _DBMGR_HXX
51 #include <dbmgr.hxx>
52 #endif
53 #include <docfld.hxx>
54 #include <expfld.hxx>
55 #include <txtatr.hxx>
56 #ifndef _UNOFLDMID_H
57 #include <unofldmid.h>
58 #endif
61 using namespace ::com::sun::star::sdbc;
62 using namespace ::com::sun::star;
63 using ::rtl::OUString;
65 /*--------------------------------------------------------------------
66 Beschreibung: Datenbanktrenner durch Punkte fuer Anzeige ersetzen
67 --------------------------------------------------------------------*/
69 String lcl_DBTrennConv(const String& aContent)
71 String sTmp(aContent);
72 sal_Unicode* pStr = sTmp.GetBufferAccess();
73 for( USHORT i = sTmp.Len(); i; --i, ++pStr )
74 if( DB_DELIM == *pStr )
75 *pStr = '.';
76 return sTmp;
79 /*--------------------------------------------------------------------
80 Beschreibung: DatenbankFeldTyp
81 --------------------------------------------------------------------*/
83 SwDBFieldType::SwDBFieldType(SwDoc* pDocPtr, const String& rNam, const SwDBData& rDBData ) :
84 SwValueFieldType( pDocPtr, RES_DBFLD ),
85 aDBData(rDBData),
86 sColumn(rNam),
87 nRefCnt(0)
89 if(aDBData.sDataSource.getLength() || aDBData.sCommand.getLength())
91 sName = aDBData.sDataSource;
92 sName += DB_DELIM;
93 sName += (String)aDBData.sCommand;
94 sName += DB_DELIM;
96 sName += GetColumnName();
98 //------------------------------------------------------------------------------
100 SwFieldType* SwDBFieldType::Copy() const
102 SwDBFieldType* pTmp = new SwDBFieldType(GetDoc(), sColumn, aDBData);
103 return pTmp;
106 //------------------------------------------------------------------------------
107 const String& SwDBFieldType::GetName() const
109 return sName;
112 //------------------------------------------------------------------------------
114 void SwDBFieldType::ReleaseRef()
116 ASSERT(nRefCnt > 0, "RefCount kleiner 0!");
118 if (--nRefCnt <= 0)
120 USHORT nPos = GetDoc()->GetFldTypes()->GetPos(this);
122 if (nPos != USHRT_MAX)
124 GetDoc()->RemoveFldType(nPos);
125 delete this;
130 /* -----------------24.02.99 14:51-------------------
132 * --------------------------------------------------*/
133 BOOL SwDBFieldType::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
135 switch( nWhichId )
137 case FIELD_PROP_PAR1:
138 rAny <<= aDBData.sDataSource;
139 break;
140 case FIELD_PROP_PAR2:
141 rAny <<= aDBData.sCommand;
142 break;
143 case FIELD_PROP_PAR3:
144 rAny <<= OUString(sColumn);
145 break;
146 case FIELD_PROP_SHORT1:
147 rAny <<= aDBData.nCommandType;
148 break;
149 default:
150 DBG_ERROR("illegal property");
152 return TRUE;
154 /* -----------------24.02.99 14:51-------------------
156 * --------------------------------------------------*/
157 BOOL SwDBFieldType::PutValue( const uno::Any& rAny, USHORT nWhichId )
159 switch( nWhichId )
161 case FIELD_PROP_PAR1:
162 rAny >>= aDBData.sDataSource;
163 break;
164 case FIELD_PROP_PAR2:
165 rAny >>= aDBData.sCommand;
166 break;
167 case FIELD_PROP_PAR3:
169 String sTmp;
170 ::GetString( rAny, sTmp );
171 if( sTmp != sColumn )
173 sColumn = sTmp;
174 SwClientIter aIter( *this );
175 SwFmtFld* pFld = (SwFmtFld*)aIter.First( TYPE( SwFmtFld ));
176 while(pFld)
178 // Feld im Undo?
179 SwTxtFld *pTxtFld = pFld->GetTxtFld();
180 if(pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
182 SwDBField* pDBField = (SwDBField*)pFld->GetFld();
183 pDBField->ClearInitialized();
184 pDBField->InitContent();
186 pFld = (SwFmtFld*)aIter.Next();
190 break;
191 case FIELD_PROP_SHORT1:
192 rAny >>= aDBData.nCommandType;
193 break;
194 default:
195 DBG_ERROR("illegal property");
197 return TRUE;
199 /*--------------------------------------------------------------------
200 Beschreibung: SwDBField
201 --------------------------------------------------------------------*/
203 SwDBField::SwDBField(SwDBFieldType* pTyp, ULONG nFmt)
204 : SwValueField(pTyp, nFmt),
205 nSubType(0),
206 bIsInBodyTxt(TRUE),
207 bValidValue(FALSE),
208 bInitialized(FALSE)
210 if (GetTyp())
211 ((SwDBFieldType*)GetTyp())->AddRef();
212 InitContent();
215 //------------------------------------------------------------------------------
217 SwDBField::~SwDBField()
219 if (GetTyp())
220 ((SwDBFieldType*)GetTyp())->ReleaseRef();
223 //------------------------------------------------------------------------------
225 void SwDBField::InitContent()
227 if (!IsInitialized())
229 aContent = '<';
230 aContent += ((SwDBFieldType*)GetTyp())->GetColumnName();
231 aContent += '>';
235 //------------------------------------------------------------------------------
237 void SwDBField::InitContent(const String& rExpansion)
239 if (rExpansion.Len() > 2)
241 if (rExpansion.GetChar(0) == '<' &&
242 rExpansion.GetChar(rExpansion.Len() - 1) == '>')
244 String sColumn( rExpansion.Copy( 1, rExpansion.Len() - 2 ) );
245 if( ::GetAppCmpStrIgnore().isEqual( sColumn,
246 ((SwDBFieldType *)GetTyp())->GetColumnName() ))
248 InitContent();
249 return;
253 SetExpansion( rExpansion );
256 //------------------------------------------------------------------------------
258 String SwDBField::Expand() const
260 String sRet;
262 if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
263 sRet = lcl_DBTrennConv(aContent);
264 return sRet;
267 //------------------------------------------------------------------------------
269 SwField* SwDBField::Copy() const
271 SwDBField *pTmp = new SwDBField((SwDBFieldType*)GetTyp(), GetFormat());
272 pTmp->aContent = aContent;
273 pTmp->bIsInBodyTxt = bIsInBodyTxt;
274 pTmp->bValidValue = bValidValue;
275 pTmp->bInitialized = bInitialized;
276 pTmp->nSubType = nSubType;
277 pTmp->SetValue(GetValue());
278 pTmp->sFieldCode = sFieldCode;
280 return pTmp;
283 String SwDBField::GetCntnt(BOOL bName) const
285 if(bName)
287 const String& rDBName = ((SwDBFieldType*)GetTyp())->GetName();
288 //TODO/CLEANUP
289 //Funktion tut nichts!
290 //String sContent( SFX_APP()->LocalizeDBName(INI2NATIONAL,
291 // rDBName.GetToken(0, DB_DELIM)));
292 String sContent( rDBName.GetToken(0, DB_DELIM) );
294 if (sContent.Len() > 1)
296 sContent += DB_DELIM;
297 sContent += rDBName.GetToken(1, DB_DELIM);
298 sContent += DB_DELIM;
299 sContent += rDBName.GetToken(2, DB_DELIM);
301 return lcl_DBTrennConv(sContent);
303 return Expand();
306 //------------------------------------------------------------------------------
308 void SwDBField::ChgValue( double d, BOOL bVal )
310 bValidValue = bVal;
311 SetValue(d);
313 if( bValidValue )
314 aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(d, GetFormat(), GetLanguage());
317 /*--------------------------------------------------------------------
318 Beschreibung:
319 --------------------------------------------------------------------*/
321 SwFieldType* SwDBField::ChgTyp( SwFieldType* pNewType )
323 SwFieldType* pOld = SwValueField::ChgTyp( pNewType );
325 ((SwDBFieldType*)pNewType)->AddRef();
326 ((SwDBFieldType*)pOld)->ReleaseRef();
328 return pOld;
331 /*--------------------------------------------------------------------
332 Beschreibung: Aktuellen Field-Value holen und chachen
333 --------------------------------------------------------------------*/
335 void SwDBField::Evaluate()
337 SwNewDBMgr* pMgr = GetDoc()->GetNewDBMgr();
339 // erstmal loeschen
340 bValidValue = FALSE;
341 double nValue = DBL_MAX;
342 const SwDBData& aTmpData = GetDBData();
344 if(!pMgr || !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
345 return ;
347 sal_uInt32 nFmt;
349 // Passenden Spaltennamen suchen
350 String aColNm( ((SwDBFieldType*)GetTyp())->GetColumnName() );
352 SvNumberFormatter* pDocFormatter = GetDoc()->GetNumberFormatter();
353 pMgr->GetMergeColumnCnt(aColNm, GetLanguage(), aContent, &nValue, &nFmt);
354 if( !( nSubType & nsSwExtendedSubType::SUB_OWN_FMT ) )
355 SetFormat( nFmt = pMgr->GetColumnFmt( aTmpData.sDataSource, aTmpData.sCommand,
356 aColNm, pDocFormatter, GetLanguage() ));
358 if( DBL_MAX != nValue )
360 sal_Int32 nColumnType = pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
361 if( DataType::DATE == nColumnType || DataType::TIME == nColumnType ||
362 DataType::TIMESTAMP == nColumnType)
365 Date aStandard(1,1,1900);
366 if (*pDocFormatter->GetNullDate() != aStandard)
367 nValue += (aStandard - *pDocFormatter->GetNullDate());
369 bValidValue = TRUE;
370 SetValue(nValue);
371 aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
373 else
375 SwSbxValue aVal;
376 aVal.PutString( aContent );
378 if (aVal.IsNumeric())
380 SetValue(aVal.GetDouble());
382 SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
383 if (nFmt && nFmt != SAL_MAX_UINT32 && !pFormatter->IsTextFormat(nFmt))
384 bValidValue = TRUE; // Wegen Bug #60339 nicht mehr bei allen Strings
386 else
388 // Bei Strings TRUE wenn Laenge > 0 sonst FALSE
389 SetValue(aContent.Len() ? 1 : 0);
392 bInitialized = TRUE;
395 /*--------------------------------------------------------------------
396 Beschreibung: Namen erfragen
397 --------------------------------------------------------------------*/
399 const String& SwDBField::GetPar1() const
401 return ((SwDBFieldType*)GetTyp())->GetName();
404 /*--------------------------------------------------------------------
405 Beschreibung:
406 --------------------------------------------------------------------*/
408 USHORT SwDBField::GetSubType() const
410 return nSubType;
413 /*--------------------------------------------------------------------
414 Beschreibung:
415 --------------------------------------------------------------------*/
417 void SwDBField::SetSubType(USHORT nType)
419 nSubType = nType;
422 /*-----------------06.03.98 16:15-------------------
424 --------------------------------------------------*/
425 BOOL SwDBField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
427 switch( nWhichId )
429 case FIELD_PROP_BOOL1:
431 BOOL bTemp = 0 == (GetSubType()&nsSwExtendedSubType::SUB_OWN_FMT);
432 rAny.setValue(&bTemp, ::getBooleanCppuType());
434 break;
435 case FIELD_PROP_BOOL2:
437 sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
438 rAny.setValue(&bVal, ::getBooleanCppuType());
440 break;
441 case FIELD_PROP_FORMAT:
442 rAny <<= (sal_Int32)GetFormat();
443 break;
444 case FIELD_PROP_PAR1:
445 rAny <<= OUString(aContent);
446 break;
447 case FIELD_PROP_PAR2:
448 rAny <<= OUString(sFieldCode);
449 break;
450 default:
451 DBG_ERROR("illegal property");
453 return TRUE;
456 /*-----------------06.03.98 16:15-------------------
458 --------------------------------------------------*/
459 BOOL SwDBField::PutValue( const uno::Any& rAny, USHORT nWhichId )
461 switch( nWhichId )
463 case FIELD_PROP_BOOL1:
464 if( *(sal_Bool*)rAny.getValue() )
465 SetSubType(GetSubType()&~nsSwExtendedSubType::SUB_OWN_FMT);
466 else
467 SetSubType(GetSubType()|nsSwExtendedSubType::SUB_OWN_FMT);
468 break;
469 case FIELD_PROP_BOOL2:
471 USHORT nSubTyp = GetSubType();
472 sal_Bool bVisible = sal_False;
473 if(!(rAny >>= bVisible))
474 return FALSE;
475 if(bVisible)
476 nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
477 else
478 nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
479 SetSubType(nSubTyp);
480 //invalidate text node
481 if(GetTyp())
483 SwClientIter aIter( *GetTyp() );
484 SwFmtFld* pFld = (SwFmtFld*)aIter.First( TYPE( SwFmtFld ));
485 while(pFld)
487 SwTxtFld *pTxtFld = pFld->GetTxtFld();
488 if(pTxtFld && (SwDBField*)pFld->GetFld() == this )
490 //notify the change
491 pTxtFld->NotifyContentChange(*pFld);
492 break;
494 pFld = (SwFmtFld*)aIter.Next();
498 break;
499 case FIELD_PROP_FORMAT:
501 sal_Int32 nTemp = 0;
502 rAny >>= nTemp;
503 SetFormat(nTemp);
505 break;
506 case FIELD_PROP_PAR1:
507 ::GetString( rAny, aContent );
508 break;
509 case FIELD_PROP_PAR2:
510 ::GetString( rAny, sFieldCode );
511 break;
512 default:
513 DBG_ERROR("illegal property");
515 return TRUE;
518 /*--------------------------------------------------------------------
519 Beschreibung: Basisklasse fuer alle weiteren Datenbankfelder
520 --------------------------------------------------------------------*/
522 SwDBNameInfField::SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, ULONG nFmt) :
523 SwField(pTyp, nFmt),
524 aDBData(rDBData),
525 nSubType(0)
529 //------------------------------------------------------------------------------
531 SwDBData SwDBNameInfField::GetDBData(SwDoc* pDoc)
533 SwDBData aRet;
534 if(aDBData.sDataSource.getLength())
535 aRet = aDBData;
536 else
537 aRet = pDoc->GetDBData();
538 return aRet;
541 // #111840#
542 void SwDBNameInfField::SetDBData(const SwDBData & rDBData)
544 aDBData = rDBData;
547 //------------------------------------------------------------------------------
549 String SwDBNameInfField::GetCntnt(BOOL bName) const
551 String sStr(SwField::GetCntnt(bName));
553 if(bName)
555 if (aDBData.sDataSource.getLength())
557 sStr += ':';
558 sStr += String(aDBData.sDataSource);
559 sStr += DB_DELIM;
560 sStr += String(aDBData.sCommand);
563 return lcl_DBTrennConv(sStr);
566 /*-----------------06.03.98 16:55-------------------
568 --------------------------------------------------*/
569 BOOL SwDBNameInfField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
571 switch( nWhichId )
573 case FIELD_PROP_PAR1:
574 rAny <<= aDBData.sDataSource;
575 break;
576 case FIELD_PROP_PAR2:
577 rAny <<= aDBData.sCommand;
578 break;
579 case FIELD_PROP_SHORT1:
580 rAny <<= aDBData.nCommandType;
581 break;
582 case FIELD_PROP_BOOL2:
584 sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
585 rAny.setValue(&bVal, ::getBooleanCppuType());
587 break;
588 default:
589 DBG_ERROR("illegal property");
591 return TRUE;
593 /*-----------------06.03.98 16:55-------------------
595 --------------------------------------------------*/
596 BOOL SwDBNameInfField::PutValue( const uno::Any& rAny, USHORT nWhichId )
598 switch( nWhichId )
600 case FIELD_PROP_PAR1:
601 rAny >>= aDBData.sDataSource;
602 break;
603 case FIELD_PROP_PAR2:
604 rAny >>= aDBData.sCommand;
605 break;
606 case FIELD_PROP_SHORT1:
607 rAny >>= aDBData.nCommandType;
608 break;
609 case FIELD_PROP_BOOL2:
611 USHORT nSubTyp = GetSubType();
612 sal_Bool bVisible = sal_False;
613 if(!(rAny >>= bVisible))
614 return FALSE;
615 if(bVisible)
616 nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
617 else
618 nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
619 SetSubType(nSubTyp);
621 break;
622 default:
623 DBG_ERROR("illegal property");
625 return TRUE;
627 /* -----------------4/10/2003 15:03------------------
629 --------------------------------------------------*/
630 USHORT SwDBNameInfField::GetSubType() const
632 return nSubType;
634 /* -----------------4/10/2003 15:03------------------
636 --------------------------------------------------*/
637 void SwDBNameInfField::SetSubType(USHORT nType)
639 nSubType = nType;
642 /*--------------------------------------------------------------------
643 Beschreibung: NaechsterDatensatz
644 --------------------------------------------------------------------*/
646 SwDBNextSetFieldType::SwDBNextSetFieldType()
647 : SwFieldType( RES_DBNEXTSETFLD )
651 //------------------------------------------------------------------------------
653 SwFieldType* SwDBNextSetFieldType::Copy() const
655 SwDBNextSetFieldType* pTmp = new SwDBNextSetFieldType();
656 return pTmp;
658 /*--------------------------------------------------------------------
659 Beschreibung: SwDBSetField
660 --------------------------------------------------------------------*/
662 SwDBNextSetField::SwDBNextSetField(SwDBNextSetFieldType* pTyp,
663 const String& rCond,
664 const String& ,
665 const SwDBData& rDBData) :
666 SwDBNameInfField(pTyp, rDBData), aCond(rCond), bCondValid(TRUE)
669 //------------------------------------------------------------------------------
671 String SwDBNextSetField::Expand() const
673 return aEmptyStr;
676 //------------------------------------------------------------------------------
678 SwField* SwDBNextSetField::Copy() const
680 SwDBNextSetField *pTmp = new SwDBNextSetField((SwDBNextSetFieldType*)GetTyp(),
681 aCond, aEmptyStr, GetDBData());
682 pTmp->SetSubType(GetSubType());
683 pTmp->bCondValid = bCondValid;
684 return pTmp;
686 //------------------------------------------------------------------------------
688 void SwDBNextSetField::Evaluate(SwDoc* pDoc)
690 SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
691 const SwDBData& rData = GetDBData();
692 if( !bCondValid ||
693 !pMgr || !pMgr->IsDataSourceOpen(rData.sDataSource, rData.sCommand, sal_False))
694 return ;
695 pMgr->ToNextRecord(rData.sDataSource, rData.sCommand);
698 /*--------------------------------------------------------------------
699 Beschreibung: Bedingung
700 --------------------------------------------------------------------*/
702 const String& SwDBNextSetField::GetPar1() const
704 return aCond;
707 void SwDBNextSetField::SetPar1(const String& rStr)
709 aCond = rStr;
711 /*-----------------06.03.98 16:16-------------------
713 --------------------------------------------------*/
714 BOOL SwDBNextSetField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
716 BOOL bRet = TRUE;
717 switch( nWhichId )
719 case FIELD_PROP_PAR3:
720 rAny <<= OUString(aCond);
721 break;
722 default:
723 bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
725 return bRet;
727 /*-----------------06.03.98 16:16-------------------
729 --------------------------------------------------*/
730 BOOL SwDBNextSetField::PutValue( const uno::Any& rAny, USHORT nWhichId )
732 BOOL bRet = TRUE;
733 switch( nWhichId )
735 case FIELD_PROP_PAR3:
736 ::GetString( rAny, aCond );
737 break;
738 default:
739 bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
741 return bRet;
744 /*--------------------------------------------------------------------
745 Beschreibung:
746 --------------------------------------------------------------------*/
748 String SwDBNextSetField::GetPar2() const
750 return GetDBName();
753 void SwDBNextSetField::SetPar2(const String& rStr)
755 GetDBName() = rStr;
759 /*--------------------------------------------------------------------
760 Beschreibung: Datensatz mit bestimmter ID
761 --------------------------------------------------------------------*/
763 SwDBNumSetFieldType::SwDBNumSetFieldType() :
764 SwFieldType( RES_DBNUMSETFLD )
768 //------------------------------------------------------------------------------
770 SwFieldType* SwDBNumSetFieldType::Copy() const
772 SwDBNumSetFieldType* pTmp = new SwDBNumSetFieldType();
773 return pTmp;
776 /*--------------------------------------------------------------------
777 Beschreibung: SwDBSetField
778 --------------------------------------------------------------------*/
780 SwDBNumSetField::SwDBNumSetField(SwDBNumSetFieldType* pTyp,
781 const String& rCond,
782 const String& rDBNum,
783 const SwDBData& rDBData) :
784 SwDBNameInfField(pTyp, rDBData),
785 aCond(rCond),
786 aPar2(rDBNum),
787 bCondValid(TRUE)
790 //------------------------------------------------------------------------------
792 String SwDBNumSetField::Expand() const
794 return aEmptyStr;
797 //------------------------------------------------------------------------------
799 SwField* SwDBNumSetField::Copy() const
801 SwDBNumSetField *pTmp = new SwDBNumSetField((SwDBNumSetFieldType*)GetTyp(),
802 aCond, aPar2, GetDBData());
803 pTmp->bCondValid = bCondValid;
804 pTmp->SetSubType(GetSubType());
805 return pTmp;
808 void SwDBNumSetField::Evaluate(SwDoc* pDoc)
810 SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
811 const SwDBData& aTmpData = GetDBData();
813 if( bCondValid && pMgr && pMgr->IsInMerge() &&
814 pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
815 { // Bedingug OK -> aktuellen Set einstellen
816 pMgr->ToRecordId(Max((USHORT)aPar2.ToInt32(), USHORT(1))-1);
820 /*--------------------------------------------------------------------
821 Beschreibung: LogDBName
822 --------------------------------------------------------------------*/
824 const String& SwDBNumSetField::GetPar1() const
826 return aCond;
829 void SwDBNumSetField::SetPar1(const String& rStr)
831 aCond = rStr;
834 /*--------------------------------------------------------------------
835 Beschreibung: Bedingung
836 --------------------------------------------------------------------*/
838 String SwDBNumSetField::GetPar2() const
840 return aPar2;
843 void SwDBNumSetField::SetPar2(const String& rStr)
845 aPar2 = rStr;
847 /*-----------------06.03.98 16:16-------------------
849 --------------------------------------------------*/
850 BOOL SwDBNumSetField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
852 BOOL bRet = TRUE;
853 switch( nWhichId )
855 case FIELD_PROP_PAR3:
856 rAny <<= OUString(aCond);
857 break;
858 case FIELD_PROP_FORMAT:
859 rAny <<= (sal_Int32)aPar2.ToInt32();
860 break;
861 default:
862 bRet = SwDBNameInfField::QueryValue(rAny, nWhichId );
864 return bRet;
866 /*-----------------06.03.98 16:16-------------------
868 --------------------------------------------------*/
869 BOOL SwDBNumSetField::PutValue( const uno::Any& rAny, USHORT nWhichId )
871 BOOL bRet = TRUE;
872 switch( nWhichId )
874 case FIELD_PROP_PAR3:
875 ::GetString( rAny, aCond );
876 break;
877 case FIELD_PROP_FORMAT:
879 sal_Int32 nVal = 0;
880 rAny >>= nVal;
881 aPar2 = String::CreateFromInt32(nVal);
883 break;
884 default:
885 bRet = SwDBNameInfField::PutValue(rAny, nWhichId );
887 return bRet;
890 /*--------------------------------------------------------------------
891 Beschreibung: SwDBNameFieldType
892 --------------------------------------------------------------------*/
894 SwDBNameFieldType::SwDBNameFieldType(SwDoc* pDocument)
895 : SwFieldType( RES_DBNAMEFLD )
897 pDoc = pDocument;
899 //------------------------------------------------------------------------------
901 String SwDBNameFieldType::Expand(ULONG ) const
903 const SwDBData aData = pDoc->GetDBData();
904 String sRet(aData.sDataSource);
905 sRet += '.';
906 sRet += (String)aData.sCommand;
907 return sRet;
909 //------------------------------------------------------------------------------
911 SwFieldType* SwDBNameFieldType::Copy() const
913 SwDBNameFieldType *pTmp = new SwDBNameFieldType(pDoc);
914 return pTmp;
917 //------------------------------------------------------------------------------
919 /*--------------------------------------------------------------------
920 Beschreibung: Name der angedockten DB
921 --------------------------------------------------------------------*/
923 SwDBNameField::SwDBNameField(SwDBNameFieldType* pTyp, const SwDBData& rDBData, ULONG nFmt)
924 : SwDBNameInfField(pTyp, rDBData, nFmt)
927 //------------------------------------------------------------------------------
929 String SwDBNameField::Expand() const
931 String sRet;
932 if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
933 sRet = ((SwDBNameFieldType*)GetTyp())->Expand(GetFormat());
934 return sRet;
937 //------------------------------------------------------------------------------
939 SwField* SwDBNameField::Copy() const
941 SwDBNameField *pTmp = new SwDBNameField((SwDBNameFieldType*)GetTyp(), GetDBData());
942 pTmp->ChangeFormat(GetFormat());
943 pTmp->SetLanguage(GetLanguage());
944 pTmp->SetSubType(GetSubType());
945 return pTmp;
948 /*-----------------06.03.98 16:16-------------------
950 --------------------------------------------------*/
951 BOOL SwDBNameField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
953 return SwDBNameInfField::QueryValue(rAny, nWhichId );
955 /*-----------------06.03.98 16:16-------------------
957 --------------------------------------------------*/
958 BOOL SwDBNameField::PutValue( const uno::Any& rAny, USHORT nWhichId )
960 return SwDBNameInfField::PutValue(rAny, nWhichId );
962 /*--------------------------------------------------------------------
963 Beschreibung: SwDBNameFieldType
964 --------------------------------------------------------------------*/
966 SwDBSetNumberFieldType::SwDBSetNumberFieldType()
967 : SwFieldType( RES_DBSETNUMBERFLD )
971 //------------------------------------------------------------------------------
973 SwFieldType* SwDBSetNumberFieldType::Copy() const
975 SwDBSetNumberFieldType *pTmp = new SwDBSetNumberFieldType;
976 return pTmp;
979 //------------------------------------------------------------------------------
981 /*--------------------------------------------------------------------
982 Beschreibung: SetNumber der angedockten DB
983 --------------------------------------------------------------------*/
985 SwDBSetNumberField::SwDBSetNumberField(SwDBSetNumberFieldType* pTyp,
986 const SwDBData& rDBData,
987 ULONG nFmt)
988 : SwDBNameInfField(pTyp, rDBData, nFmt), nNumber(0)
991 //------------------------------------------------------------------------------
993 String SwDBSetNumberField::Expand() const
995 if(0 !=(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE) || nNumber == 0)
996 return aEmptyStr;
997 else
998 return FormatNumber((USHORT)nNumber, GetFormat());
999 //return(nNumber == 0 ? aEmptyStr : FormatNumber(nNumber, GetFormat()));
1002 //------------------------------------------------------------------------------
1004 void SwDBSetNumberField::Evaluate(SwDoc* pDoc)
1006 SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
1008 const SwDBData& aTmpData = GetDBData();
1009 if (!pMgr || !pMgr->IsInMerge() ||
1010 !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_False))
1011 return;
1012 nNumber = pMgr->GetSelectedRecordId();
1016 //------------------------------------------------------------------------------
1018 SwField* SwDBSetNumberField::Copy() const
1020 SwDBSetNumberField *pTmp =
1021 new SwDBSetNumberField((SwDBSetNumberFieldType*)GetTyp(), GetDBData(), GetFormat());
1022 pTmp->SetLanguage(GetLanguage());
1023 pTmp->SetSetNumber(nNumber);
1024 pTmp->SetSubType(GetSubType());
1025 return pTmp;
1027 /*-----------------06.03.98 16:15-------------------
1029 --------------------------------------------------*/
1030 BOOL SwDBSetNumberField::QueryValue( uno::Any& rAny, USHORT nWhichId ) const
1032 BOOL bRet = TRUE;
1033 switch( nWhichId )
1035 case FIELD_PROP_USHORT1:
1036 rAny <<= (sal_Int16)GetFormat();
1037 break;
1038 case FIELD_PROP_FORMAT:
1039 rAny <<= nNumber;
1040 break;
1041 default:
1042 bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
1044 return bRet;
1046 /*-----------------06.03.98 16:15-------------------
1048 --------------------------------------------------*/
1049 BOOL SwDBSetNumberField::PutValue( const uno::Any& rAny, USHORT nWhichId )
1051 BOOL bRet = TRUE;
1052 switch( nWhichId )
1054 case FIELD_PROP_USHORT1:
1056 sal_Int16 nSet = 0;
1057 rAny >>= nSet;
1058 if(nSet < (INT16) SVX_NUMBER_NONE )
1059 SetFormat(nSet);
1060 else {
1061 //exception(wrong_value)
1065 break;
1066 case FIELD_PROP_FORMAT:
1067 rAny >>= nNumber;
1068 break;
1069 default:
1070 bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
1072 return bRet;