LCOV - code coverage report
Current view: top level - sw/source/core/fields - dbfld.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 165 429 38.5 %
Date: 2014-04-11 Functions: 26 71 36.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <float.h>
      21             : #include <sfx2/app.hxx>
      22             : #include <svl/zforlist.hxx>
      23             : #include <svx/pageitem.hxx>
      24             : #include <svx/dataaccessdescriptor.hxx>
      25             : #include <com/sun/star/sdbc/DataType.hpp>
      26             : #include <fmtfld.hxx>
      27             : #include <txtfld.hxx>
      28             : #include <doc.hxx>
      29             : #include <docary.hxx>
      30             : #include <frame.hxx>
      31             : #include <fldbas.hxx>
      32             : #include <pam.hxx>
      33             : #include <ndtxt.hxx>
      34             : #include <dbfld.hxx>
      35             : #include <dbmgr.hxx>
      36             : #include <docfld.hxx>
      37             : #include <expfld.hxx>
      38             : #include <txtatr.hxx>
      39             : #include <unofldmid.h>
      40             : #include <switerator.hxx>
      41             : 
      42             : using namespace ::com::sun::star::sdbc;
      43             : using namespace ::com::sun::star;
      44             : 
      45             : /// replace database separator by dots for display
      46          15 : static OUString lcl_DBTrennConv(const OUString& aContent)
      47             : {
      48          15 :     return aContent.replaceAll(OUString(DB_DELIM), OUString('.'));
      49             : }
      50             : 
      51             : // database field type
      52             : 
      53           9 : SwDBFieldType::SwDBFieldType(SwDoc* pDocPtr, const OUString& rNam, const SwDBData& rDBData ) :
      54             :     SwValueFieldType( pDocPtr, RES_DBFLD ),
      55             :     aDBData(rDBData),
      56             :     sName(rNam),
      57             :     sColumn(rNam),
      58           9 :     nRefCnt(0)
      59             : {
      60           9 :     if(!aDBData.sDataSource.isEmpty() || !aDBData.sCommand.isEmpty())
      61             :     {
      62          18 :         sName = aDBData.sDataSource
      63          18 :             + OUString(DB_DELIM)
      64          27 :             + aDBData.sCommand
      65          36 :             + OUString(DB_DELIM)
      66          36 :             + sName;
      67             :     }
      68           9 : }
      69             : 
      70          14 : SwDBFieldType::~SwDBFieldType()
      71             : {
      72          14 : }
      73             : 
      74           5 : SwFieldType* SwDBFieldType::Copy() const
      75             : {
      76           5 :     SwDBFieldType* pTmp = new SwDBFieldType(GetDoc(), sColumn, aDBData);
      77           5 :     return pTmp;
      78             : }
      79             : 
      80          11 : OUString SwDBFieldType::GetName() const
      81             : {
      82          11 :     return sName;
      83             : }
      84             : 
      85          23 : void SwDBFieldType::ReleaseRef()
      86             : {
      87             :     OSL_ENSURE(nRefCnt > 0, "RefCount < 0!");
      88             : 
      89          23 :     if (--nRefCnt <= 0)
      90             :     {
      91           4 :         sal_uInt16 nPos = GetDoc()->GetFldTypes()->GetPos(this);
      92             : 
      93           4 :         if (nPos != USHRT_MAX)
      94             :         {
      95           3 :             GetDoc()->RemoveFldType(nPos);
      96           3 :             delete this;
      97             :         }
      98             :     }
      99          23 : }
     100             : 
     101          13 : bool SwDBFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     102             : {
     103          13 :     switch( nWhichId )
     104             :     {
     105             :     case FIELD_PROP_PAR1:
     106           4 :         rAny <<= aDBData.sDataSource;
     107           4 :         break;
     108             :     case FIELD_PROP_PAR2:
     109           3 :         rAny <<= aDBData.sCommand;
     110           3 :         break;
     111             :     case FIELD_PROP_PAR3:
     112           3 :         rAny <<= sColumn;
     113           3 :         break;
     114             :     case FIELD_PROP_SHORT1:
     115           3 :         rAny <<= aDBData.nCommandType;
     116           3 :         break;
     117             :     default:
     118             :         OSL_FAIL("illegal property");
     119             :     }
     120          13 :     return true;
     121             : }
     122             : 
     123           4 : bool SwDBFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     124             : {
     125           4 :     switch( nWhichId )
     126             :     {
     127             :     case FIELD_PROP_PAR1:
     128           1 :         rAny >>= aDBData.sDataSource;
     129           1 :         break;
     130             :     case FIELD_PROP_PAR2:
     131           1 :         rAny >>= aDBData.sCommand;
     132           1 :         break;
     133             :     case FIELD_PROP_PAR3:
     134             :         {
     135           1 :             OUString sTmp;
     136           1 :             rAny >>= sTmp;
     137           1 :             if( sTmp != sColumn )
     138             :             {
     139           1 :                 sColumn = sTmp;
     140           1 :                 SwIterator<SwFmtFld,SwFieldType> aIter( *this );
     141           1 :                 SwFmtFld* pFmtFld = aIter.First();
     142           2 :                 while(pFmtFld)
     143             :                 {
     144             :                     // field in Undo?
     145           0 :                     SwTxtFld *pTxtFld = pFmtFld->GetTxtFld();
     146           0 :                     if(pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
     147             :                     {
     148           0 :                         SwDBField* pDBField = (SwDBField*)pFmtFld->GetField();
     149           0 :                         pDBField->ClearInitialized();
     150           0 :                         pDBField->InitContent();
     151             :                     }
     152           0 :                     pFmtFld = aIter.Next();
     153           1 :                 }
     154           1 :             }
     155             :         }
     156           1 :         break;
     157             :     case FIELD_PROP_SHORT1:
     158           1 :         rAny >>= aDBData.nCommandType;
     159           1 :         break;
     160             :     default:
     161             :         OSL_FAIL("illegal property");
     162             :     }
     163           4 :     return true;
     164             : }
     165             : 
     166             : // database field
     167             : 
     168          22 : SwDBField::SwDBField(SwDBFieldType* pTyp, sal_uLong nFmt)
     169             :     :   SwValueField(pTyp, nFmt),
     170             :         nSubType(0),
     171             :         bIsInBodyTxt(true),
     172             :         bValidValue(false),
     173          22 :         bInitialized(false)
     174             : {
     175          22 :     if (GetTyp())
     176          22 :         ((SwDBFieldType*)GetTyp())->AddRef();
     177          22 :     InitContent();
     178          22 : }
     179             : 
     180          66 : SwDBField::~SwDBField()
     181             : {
     182          22 :     if (GetTyp())
     183          22 :         ((SwDBFieldType*)GetTyp())->ReleaseRef();
     184          44 : }
     185             : 
     186          22 : void SwDBField::InitContent()
     187             : {
     188          22 :     if (!IsInitialized())
     189             :     {
     190          22 :         aContent = "<" + ((const SwDBFieldType*)GetTyp())->GetColumnName() + ">";
     191             :     }
     192          22 : }
     193             : 
     194           3 : void SwDBField::InitContent(const OUString& rExpansion)
     195             : {
     196           3 :     if (rExpansion.startsWith("<") && rExpansion.endsWith(">"))
     197             :     {
     198           0 :         const OUString sColumn( rExpansion.copy( 1, rExpansion.getLength() - 2 ) );
     199           0 :         if( ::GetAppCmpStrIgnore().isEqual( sColumn,
     200           0 :                         ((SwDBFieldType *)GetTyp())->GetColumnName() ))
     201             :         {
     202           0 :             InitContent();
     203           3 :             return;
     204           0 :         }
     205             :     }
     206           3 :     SetExpansion( rExpansion );
     207             : }
     208             : 
     209          20 : OUString SwDBField::Expand() const
     210             : {
     211          20 :     if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
     212          14 :         return lcl_DBTrennConv(aContent);
     213           6 :     return OUString();
     214             : }
     215             : 
     216          19 : SwField* SwDBField::Copy() const
     217             : {
     218          19 :     SwDBField *pTmp = new SwDBField((SwDBFieldType*)GetTyp(), GetFormat());
     219          19 :     pTmp->aContent      = aContent;
     220          19 :     pTmp->bIsInBodyTxt  = bIsInBodyTxt;
     221          19 :     pTmp->bValidValue   = bValidValue;
     222          19 :     pTmp->bInitialized  = bInitialized;
     223          19 :     pTmp->nSubType      = nSubType;
     224          19 :     pTmp->SetValue(GetValue());
     225          19 :     pTmp->sFieldCode = sFieldCode;
     226             : 
     227          19 :     return pTmp;
     228             : }
     229             : 
     230           1 : OUString SwDBField::GetFieldName() const
     231             : {
     232           1 :     const OUString rDBName = static_cast<SwDBFieldType*>(GetTyp())->GetName();
     233             : 
     234           2 :     OUString sContent( rDBName.getToken(0, DB_DELIM) );
     235             : 
     236           1 :     if (sContent.getLength() > 1)
     237             :     {
     238             :         sContent += OUString(DB_DELIM)
     239           2 :             + rDBName.getToken(1, DB_DELIM)
     240           4 :             + OUString(DB_DELIM)
     241           3 :             + rDBName.getToken(2, DB_DELIM);
     242             :     }
     243           2 :     return lcl_DBTrennConv(sContent);
     244             : }
     245             : 
     246           0 : void SwDBField::ChgValue( double d, bool bVal )
     247             : {
     248           0 :     bValidValue = bVal;
     249           0 :     SetValue(d);
     250             : 
     251           0 :     if( bValidValue )
     252           0 :         aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(d, GetFormat(), GetLanguage());
     253           0 : }
     254             : 
     255           1 : SwFieldType* SwDBField::ChgTyp( SwFieldType* pNewType )
     256             : {
     257           1 :     SwFieldType* pOld = SwValueField::ChgTyp( pNewType );
     258             : 
     259           1 :     ((SwDBFieldType*)pNewType)->AddRef();
     260           1 :     ((SwDBFieldType*)pOld)->ReleaseRef();
     261             : 
     262           1 :     return pOld;
     263             : }
     264             : 
     265             : /// get current field value and cache it
     266           0 : void SwDBField::Evaluate()
     267             : {
     268           0 :     SwNewDBMgr* pMgr = GetDoc()->GetNewDBMgr();
     269             : 
     270             :     // first delete
     271           0 :     bValidValue = false;
     272           0 :     double nValue = DBL_MAX;
     273           0 :     const SwDBData& aTmpData = GetDBData();
     274             : 
     275           0 :     if(!pMgr || !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
     276           0 :         return ;
     277             : 
     278             :     sal_uInt32 nFmt;
     279             : 
     280             :     // search corresponding column name
     281           0 :     OUString aColNm( ((SwDBFieldType*)GetTyp())->GetColumnName() );
     282             : 
     283           0 :     SvNumberFormatter* pDocFormatter = GetDoc()->GetNumberFormatter();
     284           0 :     pMgr->GetMergeColumnCnt(aColNm, GetLanguage(), aContent, &nValue, &nFmt);
     285           0 :     if( !( nSubType & nsSwExtendedSubType::SUB_OWN_FMT ) )
     286             :         SetFormat( nFmt = pMgr->GetColumnFmt( aTmpData.sDataSource, aTmpData.sCommand,
     287           0 :                                         aColNm, pDocFormatter, GetLanguage() ));
     288             : 
     289           0 :     if( DBL_MAX != nValue )
     290             :     {
     291           0 :         sal_Int32 nColumnType = pMgr->GetColumnType(aTmpData.sDataSource, aTmpData.sCommand, aColNm);
     292           0 :         if( DataType::DATE == nColumnType  || DataType::TIME == nColumnType  ||
     293             :                  DataType::TIMESTAMP  == nColumnType)
     294             : 
     295             :         {
     296           0 :             Date aStandard(1,1,1900);
     297           0 :             if (*pDocFormatter->GetNullDate() != aStandard)
     298           0 :                 nValue += (aStandard - *pDocFormatter->GetNullDate());
     299             :         }
     300           0 :         bValidValue = true;
     301           0 :         SetValue(nValue);
     302           0 :         aContent = ((SwValueFieldType*)GetTyp())->ExpandValue(nValue, GetFormat(), GetLanguage());
     303             :     }
     304             :     else
     305             :     {
     306           0 :         SwSbxValue aVal;
     307           0 :         aVal.PutString( aContent );
     308             : 
     309           0 :         if (aVal.IsNumeric())
     310             :         {
     311           0 :             SetValue(aVal.GetDouble());
     312             : 
     313           0 :             SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     314           0 :             if (nFmt && nFmt != SAL_MAX_UINT32 && !pFormatter->IsTextFormat(nFmt))
     315           0 :                 bValidValue = true; // because of bug #60339 not for all strings
     316             :         }
     317             :         else
     318             :         {
     319             :             // if string length > 0 then true, else false
     320           0 :             SetValue(aContent.isEmpty() ? 0 : 1);
     321           0 :         }
     322             :     }
     323           0 :     bInitialized = true;
     324             : }
     325             : 
     326             : /// get name
     327           0 : OUString SwDBField::GetPar1() const
     328             : {
     329           0 :     return ((const SwDBFieldType*)GetTyp())->GetName();
     330             : }
     331             : 
     332          41 : sal_uInt16 SwDBField::GetSubType() const
     333             : {
     334          41 :     return nSubType;
     335             : }
     336             : 
     337           7 : void SwDBField::SetSubType(sal_uInt16 nType)
     338             : {
     339           7 :     nSubType = nType;
     340           7 : }
     341             : 
     342          42 : bool SwDBField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     343             : {
     344          42 :     switch( nWhichId )
     345             :     {
     346             :     case FIELD_PROP_BOOL1:
     347             :         {
     348           7 :             sal_Bool bTemp = 0 == (GetSubType()&nsSwExtendedSubType::SUB_OWN_FMT);
     349           7 :             rAny.setValue(&bTemp, ::getBooleanCppuType());
     350             :         }
     351           7 :         break;
     352             :     case FIELD_PROP_BOOL2:
     353             :     {
     354           7 :         sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
     355           7 :         rAny.setValue(&bVal, ::getBooleanCppuType());
     356             :     }
     357           7 :     break;
     358             :     case FIELD_PROP_FORMAT:
     359           7 :         rAny <<= (sal_Int32)GetFormat();
     360           7 :         break;
     361             :     case FIELD_PROP_PAR1:
     362          14 :         rAny <<= aContent;
     363          14 :         break;
     364             :     case FIELD_PROP_PAR2:
     365           7 :         rAny <<= sFieldCode;
     366           7 :         break;
     367             :     default:
     368             :         OSL_FAIL("illegal property");
     369             :     }
     370          42 :     return true;
     371             : }
     372             : 
     373          12 : bool SwDBField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     374             : {
     375          12 :     switch( nWhichId )
     376             :     {
     377             :     case FIELD_PROP_BOOL1:
     378           2 :         if( *(sal_Bool*)rAny.getValue() )
     379           1 :             SetSubType(GetSubType()&~nsSwExtendedSubType::SUB_OWN_FMT);
     380             :         else
     381           1 :             SetSubType(GetSubType()|nsSwExtendedSubType::SUB_OWN_FMT);
     382           2 :         break;
     383             :     case FIELD_PROP_BOOL2:
     384             :     {
     385           2 :         sal_uInt16 nSubTyp = GetSubType();
     386           2 :         sal_Bool bVisible = sal_False;
     387           2 :         if(!(rAny >>= bVisible))
     388           0 :             return false;
     389           2 :         if(bVisible)
     390           1 :             nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
     391             :         else
     392           1 :             nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
     393           2 :         SetSubType(nSubTyp);
     394             :         //invalidate text node
     395           2 :         if(GetTyp())
     396             :         {
     397           2 :             SwIterator<SwFmtFld,SwFieldType> aIter( *GetTyp() );
     398           2 :             SwFmtFld* pFmtFld = aIter.First();
     399           4 :             while(pFmtFld)
     400             :             {
     401           2 :                 SwTxtFld *pTxtFld = pFmtFld->GetTxtFld();
     402           2 :                 if(pTxtFld && (SwDBField*)pFmtFld->GetField() == this )
     403             :                 {
     404             :                     //notify the change
     405           2 :                     pTxtFld->NotifyContentChange(*pFmtFld);
     406           2 :                     break;
     407             :                 }
     408           0 :                 pFmtFld = aIter.Next();
     409           2 :             }
     410             :         }
     411             :     }
     412           2 :     break;
     413             :     case FIELD_PROP_FORMAT:
     414             :         {
     415           2 :             sal_Int32 nTemp = 0;
     416           2 :             rAny >>= nTemp;
     417           2 :             SetFormat(nTemp);
     418             :         }
     419           2 :         break;
     420             :     case FIELD_PROP_PAR1:
     421           4 :         rAny >>= aContent;
     422           4 :         break;
     423             :     case FIELD_PROP_PAR2:
     424           2 :         rAny >>= sFieldCode;
     425           2 :     break;
     426             :     default:
     427             :         OSL_FAIL("illegal property");
     428             :     }
     429          12 :     return true;
     430             : }
     431             : 
     432             : // base class for all further database fields
     433             : 
     434           0 : SwDBNameInfField::SwDBNameInfField(SwFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt) :
     435             :     SwField(pTyp, nFmt),
     436             :     aDBData(rDBData),
     437           0 :     nSubType(0)
     438             : {
     439           0 : }
     440             : 
     441           0 : SwDBData SwDBNameInfField::GetDBData(SwDoc* pDoc)
     442             : {
     443           0 :     SwDBData aRet;
     444           0 :     if(!aDBData.sDataSource.isEmpty())
     445           0 :         aRet = aDBData;
     446             :     else
     447           0 :         aRet = pDoc->GetDBData();
     448           0 :     return aRet;
     449             : }
     450             : 
     451           0 : void SwDBNameInfField::SetDBData(const SwDBData & rDBData)
     452             : {
     453           0 :     aDBData = rDBData;
     454           0 : }
     455             : 
     456           0 : OUString SwDBNameInfField::GetFieldName() const
     457             : {
     458           0 :     OUString sStr( SwField::GetFieldName() );
     459           0 :     if (!aDBData.sDataSource.isEmpty())
     460             :     {
     461             :         sStr += OUString(':')
     462           0 :             + aDBData.sDataSource
     463           0 :             + OUString(DB_DELIM)
     464           0 :             + aDBData.sCommand;
     465             :     }
     466           0 :     return lcl_DBTrennConv(sStr);
     467             : }
     468             : 
     469           0 : bool SwDBNameInfField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     470             : {
     471           0 :     switch( nWhichId )
     472             :     {
     473             :     case FIELD_PROP_PAR1:
     474           0 :         rAny <<= aDBData.sDataSource;
     475           0 :         break;
     476             :     case FIELD_PROP_PAR2:
     477           0 :         rAny <<= aDBData.sCommand;
     478           0 :         break;
     479             :     case FIELD_PROP_SHORT1:
     480           0 :         rAny <<= aDBData.nCommandType;
     481           0 :         break;
     482             :     case FIELD_PROP_BOOL2:
     483             :     {
     484           0 :         sal_Bool bVal = 0 == (GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE);
     485           0 :         rAny.setValue(&bVal, ::getBooleanCppuType());
     486             :     }
     487           0 :     break;
     488             :     default:
     489             :         OSL_FAIL("illegal property");
     490             :     }
     491           0 :     return true;
     492             : }
     493             : 
     494           0 : bool SwDBNameInfField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     495             : {
     496           0 :     switch( nWhichId )
     497             :     {
     498             :     case FIELD_PROP_PAR1:
     499           0 :         rAny >>= aDBData.sDataSource;
     500           0 :         break;
     501             :     case FIELD_PROP_PAR2:
     502           0 :         rAny >>= aDBData.sCommand;
     503           0 :         break;
     504             :     case FIELD_PROP_SHORT1:
     505           0 :         rAny >>= aDBData.nCommandType;
     506           0 :         break;
     507             :     case FIELD_PROP_BOOL2:
     508             :     {
     509           0 :         sal_uInt16 nSubTyp = GetSubType();
     510           0 :         sal_Bool bVisible = sal_False;
     511           0 :         if(!(rAny >>= bVisible))
     512           0 :             return false;
     513           0 :         if(bVisible)
     514           0 :             nSubTyp &= ~nsSwExtendedSubType::SUB_INVISIBLE;
     515             :         else
     516           0 :             nSubTyp |= nsSwExtendedSubType::SUB_INVISIBLE;
     517           0 :         SetSubType(nSubTyp);
     518             :     }
     519           0 :     break;
     520             :     default:
     521             :         OSL_FAIL("illegal property");
     522             :     }
     523           0 :     return true;
     524             : }
     525             : 
     526           0 : sal_uInt16 SwDBNameInfField::GetSubType() const
     527             : {
     528           0 :     return nSubType;
     529             : }
     530             : 
     531           0 : void SwDBNameInfField::SetSubType(sal_uInt16 nType)
     532             : {
     533           0 :     nSubType = nType;
     534           0 : }
     535             : 
     536             : // next dataset
     537             : 
     538        1852 : SwDBNextSetFieldType::SwDBNextSetFieldType()
     539        1852 :     : SwFieldType( RES_DBNEXTSETFLD )
     540             : {
     541        1852 : }
     542             : 
     543           0 : SwFieldType* SwDBNextSetFieldType::Copy() const
     544             : {
     545           0 :     SwDBNextSetFieldType* pTmp = new SwDBNextSetFieldType();
     546           0 :     return pTmp;
     547             : }
     548             : 
     549             : // SwDBSetField
     550             : 
     551           0 : SwDBNextSetField::SwDBNextSetField(SwDBNextSetFieldType* pTyp,
     552             :                                    const OUString& rCond,
     553             :                                    const OUString& ,
     554             :                                    const SwDBData& rDBData) :
     555           0 :     SwDBNameInfField(pTyp, rDBData), aCond(rCond), bCondValid(true)
     556           0 : {}
     557             : 
     558           0 : OUString SwDBNextSetField::Expand() const
     559             : {
     560           0 :     return OUString();
     561             : }
     562             : 
     563           0 : SwField* SwDBNextSetField::Copy() const
     564             : {
     565           0 :     SwDBNextSetField *pTmp = new SwDBNextSetField((SwDBNextSetFieldType*)GetTyp(),
     566           0 :                                          aCond, OUString(), GetDBData());
     567           0 :     pTmp->SetSubType(GetSubType());
     568           0 :     pTmp->bCondValid = bCondValid;
     569           0 :     return pTmp;
     570             : }
     571             : 
     572           0 : void SwDBNextSetField::Evaluate(SwDoc* pDoc)
     573             : {
     574           0 :     SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
     575           0 :     const SwDBData& rData = GetDBData();
     576           0 :     if( !bCondValid ||
     577           0 :             !pMgr || !pMgr->IsDataSourceOpen(rData.sDataSource, rData.sCommand, sal_False))
     578           0 :         return ;
     579           0 :     pMgr->ToNextRecord(rData.sDataSource, rData.sCommand);
     580             : }
     581             : 
     582             : /// get condition
     583           0 : OUString SwDBNextSetField::GetPar1() const
     584             : {
     585           0 :     return aCond;
     586             : }
     587             : 
     588             : /// set condition
     589           0 : void SwDBNextSetField::SetPar1(const OUString& rStr)
     590             : {
     591           0 :     aCond = rStr;
     592           0 : }
     593             : 
     594           0 : bool SwDBNextSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     595             : {
     596           0 :     bool bRet = true;
     597           0 :     switch( nWhichId )
     598             :     {
     599             :     case FIELD_PROP_PAR3:
     600           0 :         rAny <<= aCond;
     601           0 :         break;
     602             :     default:
     603           0 :         bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
     604             :     }
     605           0 :     return bRet;
     606             : }
     607             : 
     608           0 : bool SwDBNextSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     609             : {
     610           0 :     bool bRet = true;
     611           0 :     switch( nWhichId )
     612             :     {
     613             :     case FIELD_PROP_PAR3:
     614           0 :         rAny >>= aCond;
     615           0 :         break;
     616             :     default:
     617           0 :         bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
     618             :     }
     619           0 :     return bRet;
     620             : }
     621             : 
     622             : // dataset with certain ID
     623             : 
     624        1852 : SwDBNumSetFieldType::SwDBNumSetFieldType() :
     625        1852 :     SwFieldType( RES_DBNUMSETFLD )
     626             : {
     627        1852 : }
     628             : 
     629           0 : SwFieldType* SwDBNumSetFieldType::Copy() const
     630             : {
     631           0 :     SwDBNumSetFieldType* pTmp = new SwDBNumSetFieldType();
     632           0 :     return pTmp;
     633             : }
     634             : 
     635             : // SwDBNumSetField
     636             : 
     637           0 : SwDBNumSetField::SwDBNumSetField(SwDBNumSetFieldType* pTyp,
     638             :                                  const OUString& rCond,
     639             :                                  const OUString& rDBNum,
     640             :                                  const SwDBData& rDBData) :
     641             :     SwDBNameInfField(pTyp, rDBData),
     642             :     aCond(rCond),
     643             :     aPar2(rDBNum),
     644           0 :     bCondValid(true)
     645           0 : {}
     646             : 
     647           0 : OUString SwDBNumSetField::Expand() const
     648             : {
     649           0 :     return OUString();
     650             : }
     651             : 
     652           0 : SwField* SwDBNumSetField::Copy() const
     653             : {
     654           0 :     SwDBNumSetField *pTmp = new SwDBNumSetField((SwDBNumSetFieldType*)GetTyp(),
     655           0 :                                          aCond, aPar2, GetDBData());
     656           0 :     pTmp->bCondValid = bCondValid;
     657           0 :     pTmp->SetSubType(GetSubType());
     658           0 :     return pTmp;
     659             : }
     660             : 
     661           0 : void SwDBNumSetField::Evaluate(SwDoc* pDoc)
     662             : {
     663           0 :     SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
     664           0 :     const SwDBData& aTmpData = GetDBData();
     665             : 
     666           0 :     if( bCondValid && pMgr && pMgr->IsInMerge() &&
     667           0 :                         pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_True))
     668             :     {   // condition OK -> adjust current Set
     669           0 :         pMgr->ToRecordId(std::max((sal_uInt16)aPar2.toInt32(), sal_uInt16(1))-1);
     670             :     }
     671           0 : }
     672             : 
     673             : /// get LogDBName
     674           0 : OUString SwDBNumSetField::GetPar1() const
     675             : {
     676           0 :     return aCond;
     677             : }
     678             : 
     679             : /// set LogDBName
     680           0 : void SwDBNumSetField::SetPar1(const OUString& rStr)
     681             : {
     682           0 :     aCond = rStr;
     683           0 : }
     684             : 
     685             : /// get condition
     686           0 : OUString SwDBNumSetField::GetPar2() const
     687             : {
     688           0 :     return aPar2;
     689             : }
     690             : 
     691             : /// set condition
     692           0 : void SwDBNumSetField::SetPar2(const OUString& rStr)
     693             : {
     694           0 :     aPar2 = rStr;
     695           0 : }
     696             : 
     697           0 : bool SwDBNumSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     698             : {
     699           0 :     bool bRet = true;
     700           0 :     switch( nWhichId )
     701             :     {
     702             :     case FIELD_PROP_PAR3:
     703           0 :         rAny <<= aCond;
     704           0 :         break;
     705             :     case FIELD_PROP_FORMAT:
     706           0 :         rAny <<= aPar2.toInt32();
     707           0 :         break;
     708             :     default:
     709           0 :         bRet = SwDBNameInfField::QueryValue(rAny, nWhichId );
     710             :     }
     711           0 :     return bRet;
     712             : }
     713             : 
     714           0 : bool    SwDBNumSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     715             : {
     716           0 :     bool bRet = true;
     717           0 :     switch( nWhichId )
     718             :     {
     719             :     case FIELD_PROP_PAR3:
     720           0 :         rAny >>= aCond;
     721           0 :         break;
     722             :     case FIELD_PROP_FORMAT:
     723             :         {
     724           0 :             sal_Int32 nVal = 0;
     725           0 :             rAny >>= nVal;
     726           0 :             aPar2 = OUString::number(nVal);
     727             :         }
     728           0 :         break;
     729             :     default:
     730           0 :         bRet = SwDBNameInfField::PutValue(rAny, nWhichId );
     731             :     }
     732           0 :     return bRet;
     733             : }
     734             : 
     735             : // SwDBNameFieldType
     736             : 
     737        1852 : SwDBNameFieldType::SwDBNameFieldType(SwDoc* pDocument)
     738        1852 :     : SwFieldType( RES_DBNAMEFLD )
     739             : {
     740        1852 :     pDoc = pDocument;
     741        1852 : }
     742             : 
     743           0 : OUString SwDBNameFieldType::Expand(sal_uLong ) const
     744             : {
     745           0 :     const SwDBData aData = pDoc->GetDBData();
     746           0 :     return aData.sDataSource + "." + aData.sCommand;
     747             : }
     748             : 
     749           0 : SwFieldType* SwDBNameFieldType::Copy() const
     750             : {
     751           0 :     SwDBNameFieldType *pTmp = new SwDBNameFieldType(pDoc);
     752           0 :     return pTmp;
     753             : }
     754             : 
     755             : // name of the connected database
     756             : 
     757           0 : SwDBNameField::SwDBNameField(SwDBNameFieldType* pTyp, const SwDBData& rDBData, sal_uLong nFmt)
     758           0 :     : SwDBNameInfField(pTyp, rDBData, nFmt)
     759           0 : {}
     760             : 
     761           0 : OUString SwDBNameField::Expand() const
     762             : {
     763           0 :     if(0 ==(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE))
     764           0 :         return ((SwDBNameFieldType*)GetTyp())->Expand(GetFormat());
     765           0 :     return OUString();
     766             : }
     767             : 
     768           0 : SwField* SwDBNameField::Copy() const
     769             : {
     770           0 :     SwDBNameField *pTmp = new SwDBNameField((SwDBNameFieldType*)GetTyp(), GetDBData());
     771           0 :     pTmp->ChangeFormat(GetFormat());
     772           0 :     pTmp->SetLanguage(GetLanguage());
     773           0 :     pTmp->SetSubType(GetSubType());
     774           0 :     return pTmp;
     775             : }
     776             : 
     777           0 : bool SwDBNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     778             : {
     779           0 :     return SwDBNameInfField::QueryValue(rAny, nWhichId );
     780             : }
     781             : 
     782           0 : bool SwDBNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     783             : {
     784           0 :     return SwDBNameInfField::PutValue(rAny, nWhichId );
     785             : }
     786             : 
     787             : // SwDBSetNumberFieldType
     788             : 
     789        1852 : SwDBSetNumberFieldType::SwDBSetNumberFieldType()
     790        1852 :     : SwFieldType( RES_DBSETNUMBERFLD )
     791             : {
     792        1852 : }
     793             : 
     794           0 : SwFieldType* SwDBSetNumberFieldType::Copy() const
     795             : {
     796           0 :     SwDBSetNumberFieldType *pTmp = new SwDBSetNumberFieldType;
     797           0 :     return pTmp;
     798             : }
     799             : 
     800             : // set-number of the connected database
     801             : 
     802           0 : SwDBSetNumberField::SwDBSetNumberField(SwDBSetNumberFieldType* pTyp,
     803             :                                        const SwDBData& rDBData,
     804             :                                        sal_uLong nFmt)
     805           0 :     : SwDBNameInfField(pTyp, rDBData, nFmt), nNumber(0)
     806           0 : {}
     807             : 
     808           0 : OUString SwDBSetNumberField::Expand() const
     809             : {
     810           0 :     if(0 !=(GetSubType() & nsSwExtendedSubType::SUB_INVISIBLE) || nNumber == 0)
     811           0 :         return OUString();
     812           0 :     return FormatNumber((sal_uInt16)nNumber, GetFormat());
     813             : }
     814             : 
     815           0 : void SwDBSetNumberField::Evaluate(SwDoc* pDoc)
     816             : {
     817           0 :     SwNewDBMgr* pMgr = pDoc->GetNewDBMgr();
     818             : 
     819           0 :     const SwDBData& aTmpData = GetDBData();
     820           0 :     if (!pMgr || !pMgr->IsInMerge() ||
     821           0 :         !pMgr->IsDataSourceOpen(aTmpData.sDataSource, aTmpData.sCommand, sal_False))
     822           0 :         return;
     823           0 :     nNumber = pMgr->GetSelectedRecordId();
     824             : }
     825             : 
     826           0 : SwField* SwDBSetNumberField::Copy() const
     827             : {
     828             :     SwDBSetNumberField *pTmp =
     829           0 :         new SwDBSetNumberField((SwDBSetNumberFieldType*)GetTyp(), GetDBData(), GetFormat());
     830           0 :     pTmp->SetLanguage(GetLanguage());
     831           0 :     pTmp->SetSetNumber(nNumber);
     832           0 :     pTmp->SetSubType(GetSubType());
     833           0 :     return pTmp;
     834             : }
     835             : 
     836           0 : bool SwDBSetNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     837             : {
     838           0 :     bool bRet = true;
     839           0 :     switch( nWhichId )
     840             :     {
     841             :     case FIELD_PROP_USHORT1:
     842           0 :         rAny <<= (sal_Int16)GetFormat();
     843           0 :         break;
     844             :     case FIELD_PROP_FORMAT:
     845           0 :         rAny <<= nNumber;
     846           0 :         break;
     847             :     default:
     848           0 :         bRet = SwDBNameInfField::QueryValue( rAny, nWhichId );
     849             :     }
     850           0 :     return bRet;
     851             : }
     852             : 
     853           0 : bool SwDBSetNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     854             : {
     855           0 :     bool bRet = true;
     856           0 :     switch( nWhichId )
     857             :     {
     858             :     case FIELD_PROP_USHORT1:
     859             :         {
     860           0 :             sal_Int16 nSet = 0;
     861           0 :             rAny >>= nSet;
     862           0 :             if(nSet < (sal_Int16) SVX_NUMBER_NONE )
     863           0 :                 SetFormat(nSet);
     864             :             else {
     865             :             }
     866             :         }
     867           0 :         break;
     868             :     case FIELD_PROP_FORMAT:
     869           0 :         rAny >>= nNumber;
     870           0 :         break;
     871             :     default:
     872           0 :         bRet = SwDBNameInfField::PutValue( rAny, nWhichId );
     873             :     }
     874           0 :     return bRet;
     875             : }
     876             : 
     877             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10