diff options
author | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-07-04 23:22:53 +0200 |
---|---|---|
committer | Bjoern Michaelsen <bjoern.michaelsen@canonical.com> | 2015-07-04 23:58:50 +0200 |
commit | 88298839b51ef511161cddd5b20f001462384eea (patch) | |
tree | 29db811af8c099bcc10672218bb90c5f2089527d | |
parent | 4999ebf208c5626ecb72fa6b2da11610268d8ad0 (diff) |
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
-rw-r--r-- | sw/source/ui/dbui/mailmergewizard.cxx | 1 | ||||
-rw-r--r-- | sw/source/uibase/dbui/mmconfigitem.cxx | 70 | ||||
-rw-r--r-- | sw/source/uibase/inc/mmconfigitem.hxx | 6 |
3 files changed, 30 insertions, 47 deletions
diff --git a/sw/source/ui/dbui/mailmergewizard.cxx b/sw/source/ui/dbui/mailmergewizard.cxx index 341bedef6873..04bd7f80153e 100644 --- a/sw/source/ui/dbui/mailmergewizard.cxx +++ b/sw/source/ui/dbui/mailmergewizard.cxx @@ -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); diff --git a/sw/source/uibase/dbui/mmconfigitem.cxx b/sw/source/uibase/dbui/mmconfigitem.cxx index d765dc0f0eb8..879870bd2cd4 100644 --- a/sw/source/uibase/dbui/mmconfigitem.cxx +++ b/sw/source/uibase/dbui/mmconfigitem.cxx @@ -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 { diff --git a/sw/source/uibase/inc/mmconfigitem.hxx b/sw/source/uibase/inc/mmconfigitem.hxx index 7b4115ed7689..07f216c199e3 100644 --- a/sw/source/uibase/inc/mmconfigitem.hxx +++ b/sw/source/uibase/inc/mmconfigitem.hxx @@ -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; |