From 4851cde7b98226b0f82ae2b191c290173e9b06c6 Mon Sep 17 00:00:00 2001 From: Jan-Marek Glogowski Date: Sat, 12 Jul 2014 23:17:31 +0200 Subject: fdo#70346 MM: add mail merge data to condition dict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently section hide conditions are just evaluated based on document field data. This adds the current mail merge dataset to the condition dictionary, so this can be used in the condition evaluation. The dataset values are named from their columns and added initially, therefore DB fields with identical names will overwrite the values in the dictionary! Change-Id: I82a5f9f6962628a76c836e8e2a7c9e264fdc16e0 Reviewed-on: https://gerrit.libreoffice.org/10978 Reviewed-by: Björn Michaelsen Tested-by: Björn Michaelsen --- sw/source/uibase/dbui/dbmgr.cxx | 100 +++++++++++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 12 deletions(-) (limited to 'sw/source/uibase') diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 9171bcd03055..fcb47c6c4b11 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -128,6 +128,10 @@ #include #include #include +#include +#include +#include +#include #include @@ -442,7 +446,15 @@ bool SwDBManager::MergeNew(const SwMergeDescriptor& rMergeDesc ) break; } - EndMerge(); + DELETEZ( pImpl->pMergeData ); + + // Recalculate original section visibility states, as field changes aren't + // tracked (not undo-able). Has to be done, after pImpl->pMergeData is + // gone, otherwise merge data is used for calculation! + rMergeDesc.rSh.SwViewShell::UpdateFlds(); + + bInMerge = false; + return bRet; } @@ -1060,7 +1072,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, pWorkDoc->SetDBManager( this ); pWorkDoc->getIDocumentLinksAdministration().EmbedAllLinks(); - // #i69485# lock fields to prevent access to the result set while calculating layout + // #i69458# lock fields to prevent access to the result set while calculating layout rWorkShell.LockExpFlds(); rWorkShell.CalcLayout(); rWorkShell.UnlockExpFlds(); @@ -1729,15 +1741,6 @@ OUString SwDBManager::GetDBField(uno::Reference xColumnProps, return sRet; } -// releases the merge data source table or query after merge is completed -void SwDBManager::EndMerge() -{ - OSL_ENSURE(bInMerge, "merge is not active"); - bInMerge = false; - delete pImpl->pMergeData; - pImpl->pMergeData = 0; -} - // checks if a desired data source table or query is open bool SwDBManager::IsDataSourceOpen(const OUString& rDataSource, const OUString& rTableOrQuery, bool bMergeOnly) @@ -1849,6 +1852,79 @@ bool SwDBManager::ToNextMergeRecord() return ToNextRecord(pImpl->pMergeData); } +bool SwDBManager::FillCalcWithMergeData( SvNumberFormatter *pDocFormatter, + sal_uInt16 nLanguage, bool asString, SwCalc &rCalc ) +{ + if (!(pImpl->pMergeData && pImpl->pMergeData->xResultSet.is())) + return false; + + uno::Reference< XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, UNO_QUERY ); + if(xColsSupp.is()) + { + uno::Reference xCols = xColsSupp->getColumns(); + const Sequence aColNames = xCols->getElementNames(); + const OUString* pColNames = aColNames.getConstArray(); + OUString aString; + + const bool bExistsNextRecord = ExistsNextRecord(); + + for( int nCol = 0; nCol < aColNames.getLength(); nCol++ ) + { + const OUString &rColName = pColNames[nCol]; + + // empty variables, if no more records; + if( !bExistsNextRecord ) + { + rCalc.VarChange( rColName, 0 ); + continue; + } + + double aNumber = DBL_MAX; + if( lcl_GetColumnCnt(pImpl->pMergeData, rColName, nLanguage, aString, &aNumber) ) + { + // get the column type + sal_Int32 nColumnType; + Any aCol = xCols->getByName( pColNames[nCol] ); + uno::Reference xCol; + aCol >>= xCol; + Any aType = xCol->getPropertyValue( "Type" ); + aType >>= nColumnType; + + sal_uInt32 nFmt; + if( !GetMergeColumnCnt(pColNames[nCol], nLanguage, aString, &aNumber, &nFmt) ) + continue; + + // aNumber is overwritten by SwDBField::FormatValue, so store initial status + bool colIsNumber = aNumber != DBL_MAX; + bool bValidValue = SwDBField::FormatValue( pDocFormatter, aString, nFmt, + aNumber, nColumnType, NULL ); + if( colIsNumber ) + { + if( bValidValue ) + { + SwSbxValue aValue; + if( !asString ) + aValue.PutDouble( aNumber ); + else + aValue.PutString( aString ); + SAL_INFO( "sw.dbmgr", "'" << pColNames[nCol] << "': " << aNumber << " / " << aString ); + rCalc.VarChange( pColNames[nCol], aValue ); + } + } + else + { + SwSbxValue aValue; + aValue.PutString( aString ); + SAL_INFO( "sw.dbmgr", "'" << pColNames[nCol] << "': " << aString ); + rCalc.VarChange( pColNames[nCol], aValue ); + } + } + } + return bExistsNextRecord; + } + return false; +} + bool SwDBManager::ToNextRecord( const OUString& rDataSource, const OUString& rCommand, sal_Int32 /*nCommandType*/) { @@ -2829,7 +2905,7 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig, } } - // #i69485# lock fields to prevent access to the result set while calculating layout + // #i69458# lock fields to prevent access to the result set while calculating layout rWorkShell.LockExpFlds(); // create a layout rWorkShell.CalcLayout(); -- cgit