Kaydet (Commit) ed86d235 authored tarafından Bjoern Michaelsen's avatar Bjoern Michaelsen Kaydeden (comit) Andras Timar

tdf#90377: fix exclude recipient in mail merge

- first, actually use the selection in MergeNew()
- secoond, bring back GetSelection() for that
- third, throw away lots of the old (dead) code that mostly just
  stumbled over itself
  - e.g. ExcludeRecord() wouldnt work on the last element due to a
    off-by-one error

Change-Id: I07d07e086b748b393f2ada7cb22fdb2ce285ad65
Reviewed-on: https://gerrit.libreoffice.org/16762Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 35430d7d
......@@ -276,6 +276,7 @@ void SwMailMergeWizard::CreateTargetDocument()
aDescriptor[ svx::daCursor ] <<= m_rConfigItem.GetResultSet();
aDescriptor[ svx::daCommand ] <<= m_rConfigItem.GetCurrentDBData().sCommand;
aDescriptor[ svx::daCommandType ] <<= m_rConfigItem.GetCurrentDBData().nCommandType;
aDescriptor[ svx::daSelection ] <<= m_rConfigItem.GetSelection();
SwMergeDescriptor aMergeDesc( DBMGR_MERGE_SHELL, GetSwView()->GetWrtShell(),
aDescriptor);
......
......@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <mmconfigitem.hxx>
#include <vector>
#include <swtypes.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/uno/Any.hxx>
......@@ -34,6 +36,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/types.hxx>
#include <com/sun/star/sdb/CommandType.hpp>
#include <comphelper/sequence.hxx>
#include <rtl/instance.hxx>
#include <unotools/configitem.hxx>
#include <mailmergehelper.hxx>
......@@ -1021,57 +1024,34 @@ sal_Int32 SwMailMergeConfigItem::GetResultSetPosition() const
return m_pImpl->nResultSetCursorPos;
}
bool SwMailMergeConfigItem::IsRecordExcluded(sal_Int32 nRecord)
{
bool bRet = false;
if(nRecord > 0 && nRecord < m_aSelection.getLength())
{
sal_Int32 nTemp = 0;
m_aSelection[nRecord - 1] >>= nTemp;
bRet = nTemp < 1;
}
return bRet;
}
bool SwMailMergeConfigItem::IsRecordExcluded(sal_Int32 nRecord) const
{ return m_aExcludedRecords.find(nRecord) != m_aExcludedRecords.end(); }
void SwMailMergeConfigItem::ExcludeRecord(sal_Int32 nRecord, bool bExclude)
{
//nRecord is based on 1
//the selection array contains Anys for all records
//excluded records contain a '-1'
if(!m_aSelection.getLength() || nRecord > m_aSelection.getLength())
{
if(bExclude)
{
//if no selection array is available we need to create one containing the
//entries for all available records
if(!m_pImpl->xResultSet.is())
GetResultSet();
if(m_pImpl->xResultSet.is())
{
m_pImpl->xResultSet->last();
sal_Int32 nEnd = m_pImpl->xResultSet->getRow();
sal_Int32 nStart = m_aSelection.getLength();
m_aSelection.realloc(nEnd);
Any* pSelection = m_aSelection.getArray();
for(sal_Int32 nIndex = nStart; nIndex < nEnd; ++nIndex)
{
if((nRecord - 1) != nIndex)
pSelection[nIndex] <<= nIndex + 1;
else
pSelection[nIndex] <<= (sal_Int32) -1;
}
}
}
}
if(bExclude)
m_aExcludedRecords.insert(nRecord);
else
{
if(nRecord > 0 && m_aSelection.getLength() > nRecord)
{
m_aSelection[nRecord - 1] <<= bExclude ? -1 : nRecord;
}
}
m_aExcludedRecords.erase(nRecord);
}
uno::Sequence<uno::Any> SwMailMergeConfigItem::GetSelection() const
{
if(!m_pImpl->xResultSet.is())
GetResultSet();
if(!m_pImpl->xResultSet.is())
return {};
m_pImpl->xResultSet->last();
sal_Int32 nResultSetSize = m_pImpl->xResultSet->getRow()+1;
std::vector<uno::Any> vResult;
vResult.reserve(nResultSetSize);
for(sal_Int32 nIdx=1; nIdx<nResultSetSize;++nIdx)
if(!IsRecordExcluded(nIdx))
vResult.push_back(uno::makeAny<sal_Int32>(nIdx));
return comphelper::containerToSequence(vResult);
}
const uno::Sequence< OUString>&
SwMailMergeConfigItem::GetSavedDocuments() const
{
......
......@@ -22,6 +22,7 @@
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/uno/Reference.hxx>
#include <tools/resary.hxx>
#include <set>
#include <swdbdata.hxx>
#include "swdllapi.h"
#include "sharedconnection.hxx"
......@@ -56,7 +57,7 @@ class SW_DLLPUBLIC SwMailMergeConfigItem
bool m_bGreetingInserted;
sal_Int32 m_nGreetingMoves;
OUString m_rAddressBlockFrame;
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> m_aSelection;
std::set<sal_Int32> m_aExcludedRecords;
sal_uInt16 m_nStartPrint;
sal_uInt16 m_nEndPrint;
......@@ -112,8 +113,9 @@ public:
sal_Int32 GetResultSetPosition()const;
bool IsResultSetFirstLast(bool& bIsFirst, bool& bIsLast);
bool IsRecordExcluded(sal_Int32 nRecord);
bool IsRecordExcluded(sal_Int32 nRecord) const;
void ExcludeRecord(sal_Int32 nRecord, bool bExclude);
css::uno::Sequence< css::uno::Any> GetSelection() const;
const com::sun::star::uno::Sequence< OUString>&
GetSavedDocuments() const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment