summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-08-24 09:26:22 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-08-24 10:54:22 +0200
commit3c91b6362eab14a631577ca9a0caa7610fe3725a (patch)
treef392c6a5c59021e7bf2f68958539885d1e2d9611 /sc
parentce68889678bca3b51c258452f7bfdd21982e4a0d (diff)
split ScViewFunc::CopyToClip into two methods
and flatten it, to make it easier to read and reason about Change-Id: I5032472f26c9695ce719d905d20472b18356f017 Reviewed-on: https://gerrit.libreoffice.org/59539 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/ui/inc/viewfunc.hxx4
-rw-r--r--sc/source/ui/view/viewfun3.cxx360
2 files changed, 192 insertions, 172 deletions
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index 019681be07f4..e9cca10dd49c 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -103,6 +103,10 @@ public:
bool bIncludeObjects = false, bool bStopEdit = true );
SC_DLLPUBLIC bool CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRange, bool bCut,
bool bApi = false, bool bIncludeObjects = false, bool bStopEdit = true );
+ bool CopyToClipSingleRange( ScDocument* pClipDoc, const ScRangeList& rRanges, bool bCut,
+ bool bIncludeObjects );
+ bool CopyToClipMultiRange( ScDocument* pClipDoc, const ScRangeList& rRanges, bool bCut,
+ bool bApi, bool bIncludeObjects );
ScTransferObj* CopyToTransferable();
SC_DLLPUBLIC bool PasteFromClip( InsertDeleteFlags nFlags, ScDocument* pClipDoc,
ScPasteFunc nFunction = ScPasteFunc::NONE, bool bSkipEmpty = false,
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index f43dd6c125e1..570cf5f3f06e 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -185,218 +185,234 @@ bool ScViewFunc::CopyToClip( ScDocument* pClipDoc, const ScRangeList& rRanges, b
{
if ( rRanges.empty() )
return false;
- bool bDone = false;
if ( bStopEdit )
UpdateInputLine();
+ bool bDone;
+ if (rRanges.size() > 1) // isMultiRange
+ bDone = CopyToClipMultiRange(pClipDoc, rRanges, bCut, bApi, bIncludeObjects);
+ else
+ bDone = CopyToClipSingleRange(pClipDoc, rRanges, bCut, bIncludeObjects);
+ return bDone;
+}
+
+bool ScViewFunc::CopyToClipSingleRange( ScDocument* pClipDoc, const ScRangeList& rRanges, bool bCut, bool bIncludeObjects )
+{
ScRange aRange = rRanges[0];
ScClipParam aClipParam( aRange, bCut );
aClipParam.maRanges = rRanges;
-
ScDocument* pDoc = GetViewData().GetDocument();
ScMarkData& rMark = GetViewData().GetMarkData();
- if ( !aClipParam.isMultiRange() )
+ if ( !pDoc
+ || pDoc->HasSelectedBlockMatrixFragment( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), rMark ) )
+ return false;
+
+ bool bSysClip = false;
+ if ( !pClipDoc ) // no clip doc specified
{
- if ( pDoc && ( !pDoc->HasSelectedBlockMatrixFragment( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row(), rMark ) ) )
- {
- bool bSysClip = false;
- if ( !pClipDoc ) // no clip doc specified
- {
- // Create one (deleted by ScTransferObj).
- pClipDoc = new ScDocument( SCDOCMODE_CLIP );
- bSysClip = true; // and copy into system
- }
- if ( !bCut )
- {
- ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
- if ( pChangeTrack )
- pChangeTrack->ResetLastCut();
- }
+ // Create one (deleted by ScTransferObj).
+ pClipDoc = new ScDocument( SCDOCMODE_CLIP );
+ bSysClip = true; // and copy into system
+ }
+ if ( !bCut )
+ {
+ ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
+ if ( pChangeTrack )
+ pChangeTrack->ResetLastCut();
+ }
- if ( bSysClip && bIncludeObjects )
- {
- bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange );
- // Update ScGlobal::xDrawClipDocShellRef.
- ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
- }
+ if ( bSysClip && bIncludeObjects )
+ {
+ bool bAnyOle = pDoc->HasOLEObjectsInArea( aRange );
+ // Update ScGlobal::xDrawClipDocShellRef.
+ ScDrawLayer::SetGlobalDrawPersist( ScTransferObj::SetDrawClipDoc( bAnyOle ) );
+ }
- // is this necessary?, will setting the doc id upset the
- // following paste operation with range? would be nicer to just set this always
- // and lose the 'if' above
- aClipParam.setSourceDocID( pDoc->GetDocumentID() );
+ // is this necessary?, will setting the doc id upset the
+ // following paste operation with range? would be nicer to just set this always
+ // and lose the 'if' above
+ aClipParam.setSourceDocID( pDoc->GetDocumentID() );
- if (SfxObjectShell* pObjectShell = pDoc->GetDocumentShell())
- {
- // Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell).
- uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(pObjectShell->GetModel(), uno::UNO_QUERY);
- uno::Reference<util::XCloneable> xCloneable(xDocumentPropertiesSupplier->getDocumentProperties(), uno::UNO_QUERY);
- std::unique_ptr<ScClipOptions> pOptions(new ScClipOptions);
- pOptions->m_xDocumentProperties.set(xCloneable->createClone(), uno::UNO_QUERY);
- pClipDoc->SetClipOptions(std::move(pOptions));
- }
+ if (SfxObjectShell* pObjectShell = pDoc->GetDocumentShell())
+ {
+ // Copy document properties from pObjectShell to pClipDoc (to its clip options, as it has no object shell).
+ uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(pObjectShell->GetModel(), uno::UNO_QUERY);
+ uno::Reference<util::XCloneable> xCloneable(xDocumentPropertiesSupplier->getDocumentProperties(), uno::UNO_QUERY);
+ std::unique_ptr<ScClipOptions> pOptions(new ScClipOptions);
+ pOptions->m_xDocumentProperties.set(xCloneable->createClone(), uno::UNO_QUERY);
+ pClipDoc->SetClipOptions(std::move(pOptions));
+ }
- pDoc->CopyToClip( aClipParam, pClipDoc, &rMark, false, bIncludeObjects );
- if ( pDoc && pClipDoc )
+ pDoc->CopyToClip( aClipParam, pClipDoc, &rMark, false, bIncludeObjects );
+ if ( pDoc && pClipDoc )
+ {
+ ScDrawLayer* pDrawLayer = pClipDoc->GetDrawLayer();
+ if ( pDrawLayer )
+ {
+ ScClipParam& rClipDocClipParam = pClipDoc->GetClipParam();
+ ScRangeListVector& rRangesVector = rClipDocClipParam.maProtectedChartRangesVector;
+ SCTAB nTabCount = pClipDoc->GetTableCount();
+ for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
{
- ScDrawLayer* pDrawLayer = pClipDoc->GetDrawLayer();
- if ( pDrawLayer )
+ SdrPage* pPage = pDrawLayer->GetPage( static_cast< sal_uInt16 >( nTab ) );
+ if ( pPage )
{
- ScClipParam& rClipParam = pClipDoc->GetClipParam();
- ScRangeListVector& rRangesVector = rClipParam.maProtectedChartRangesVector;
- SCTAB nTabCount = pClipDoc->GetTableCount();
- for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
- {
- SdrPage* pPage = pDrawLayer->GetPage( static_cast< sal_uInt16 >( nTab ) );
- if ( pPage )
- {
- ScChartHelper::FillProtectedChartRangesVector( rRangesVector, pDoc, pPage );
- }
- }
+ ScChartHelper::FillProtectedChartRangesVector( rRangesVector, pDoc, pPage );
}
}
+ }
+ }
- if ( bSysClip )
- {
- ScDrawLayer::SetGlobalDrawPersist(nullptr);
- ScGlobal::SetClipDocName( pDoc->GetDocumentShell()->GetTitle( SFX_TITLE_FULLNAME ) );
- }
- pClipDoc->ExtendMerge( aRange, true );
-
- if ( bSysClip )
- {
- ScDocShell* pDocSh = GetViewData().GetDocShell();
- TransferableObjectDescriptor aObjDesc;
- pDocSh->FillTransferableObjectDescriptor( aObjDesc );
- aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
- // maSize is set in ScTransferObj ctor
+ if ( bSysClip )
+ {
+ ScDrawLayer::SetGlobalDrawPersist(nullptr);
+ ScGlobal::SetClipDocName( pDoc->GetDocumentShell()->GetTitle( SFX_TITLE_FULLNAME ) );
+ }
+ pClipDoc->ExtendMerge( aRange, true );
- ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
- uno::Reference<css::datatransfer::XTransferable2> xTransferObj = pTransferObj;
- if ( ScGlobal::xDrawClipDocShellRef.is() )
- {
- SfxObjectShellRef aPersistRef( ScGlobal::xDrawClipDocShellRef.get() );
- pTransferObj->SetDrawPersist( aPersistRef );// keep persist for ole objects alive
+ if ( bSysClip )
+ {
+ ScDocShell* pDocSh = GetViewData().GetDocShell();
+ TransferableObjectDescriptor aObjDesc;
+ pDocSh->FillTransferableObjectDescriptor( aObjDesc );
+ aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
+ // maSize is set in ScTransferObj ctor
+
+ ScTransferObj* pTransferObj = new ScTransferObj( pClipDoc, aObjDesc );
+ uno::Reference<css::datatransfer::XTransferable2> xTransferObj = pTransferObj;
+ if ( ScGlobal::xDrawClipDocShellRef.is() )
+ {
+ SfxObjectShellRef aPersistRef( ScGlobal::xDrawClipDocShellRef.get() );
+ pTransferObj->SetDrawPersist( aPersistRef );// keep persist for ole objects alive
+ }
+ pTransferObj->CopyToClipboard( GetActiveWin() );
+ }
- }
- pTransferObj->CopyToClipboard( GetActiveWin() );
- }
+ return true;
+}
- bDone = true;
- }
+bool ScViewFunc::CopyToClipMultiRange( ScDocument* pInputClipDoc, const ScRangeList& rRanges, bool bCut, bool bApi, bool bIncludeObjects )
+{
+ if (bCut)
+ {
+ // We don't support cutting of multi-selections.
+ if (!bApi)
+ ErrorMessage(STR_NOMULTISELECT);
+ return false;
}
- else
+ if (pInputClipDoc)
{
- bool bSuccess = false;
- aClipParam.mbCutMode = false;
+ // TODO: What's this for?
+ if (!bApi)
+ ErrorMessage(STR_NOMULTISELECT);
+ return false;
+ }
- do
+ ScClipParam aClipParam( rRanges[0], bCut );
+ aClipParam.maRanges = rRanges;
+ ScDocument* pDoc = GetViewData().GetDocument();
+ ScMarkData& rMark = GetViewData().GetMarkData();
+ bool bDone = false;
+ bool bSuccess = false;
+ aClipParam.mbCutMode = false;
+
+ do
+ {
+ ScDocumentUniquePtr pDocClip(new ScDocument(SCDOCMODE_CLIP));
+
+ // Check for geometrical feasibility of the ranges.
+ bool bValidRanges = true;
+ ScRange const * p = &aClipParam.maRanges.front();
+ SCCOL nPrevColDelta = 0;
+ SCROW nPrevRowDelta = 0;
+ SCCOL nPrevCol = p->aStart.Col();
+ SCROW nPrevRow = p->aStart.Row();
+ SCCOL nPrevColSize = p->aEnd.Col() - p->aStart.Col() + 1;
+ SCROW nPrevRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
+ for ( size_t i = 1; i < aClipParam.maRanges.size(); ++i )
{
- if (bCut)
- // We con't support cutting of multi-selections.
- break;
-
- if (pClipDoc)
- // TODO: What's this for?
- break;
-
- ScDocumentUniquePtr pDocClip(new ScDocument(SCDOCMODE_CLIP));
-
- // Check for geometrical feasibility of the ranges.
- bool bValidRanges = true;
- ScRange const * p = &aClipParam.maRanges.front();
- SCCOL nPrevColDelta = 0;
- SCROW nPrevRowDelta = 0;
- SCCOL nPrevCol = p->aStart.Col();
- SCROW nPrevRow = p->aStart.Row();
- SCCOL nPrevColSize = p->aEnd.Col() - p->aStart.Col() + 1;
- SCROW nPrevRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
- for ( size_t i = 1; i < aClipParam.maRanges.size(); ++i )
+ p = &aClipParam.maRanges[i];
+ if ( pDoc->HasSelectedBlockMatrixFragment(
+ p->aStart.Col(), p->aStart.Row(), p->aEnd.Col(), p->aEnd.Row(), rMark) )
{
- p = &aClipParam.maRanges[i];
- if ( pDoc->HasSelectedBlockMatrixFragment(
- p->aStart.Col(), p->aStart.Row(), p->aEnd.Col(), p->aEnd.Row(), rMark) )
- {
- if (!bApi)
- ErrorMessage(STR_MATRIXFRAGMENTERR);
- return false;
- }
-
- SCCOL nColDelta = p->aStart.Col() - nPrevCol;
- SCROW nRowDelta = p->aStart.Row() - nPrevRow;
-
- if ((nColDelta && nRowDelta) || (nPrevColDelta && nRowDelta) || (nPrevRowDelta && nColDelta))
- {
- bValidRanges = false;
- break;
- }
-
- if (aClipParam.meDirection == ScClipParam::Unspecified)
- {
- if (nColDelta)
- aClipParam.meDirection = ScClipParam::Column;
- if (nRowDelta)
- aClipParam.meDirection = ScClipParam::Row;
- }
+ if (!bApi)
+ ErrorMessage(STR_MATRIXFRAGMENTERR);
+ return false;
+ }
- SCCOL nColSize = p->aEnd.Col() - p->aStart.Col() + 1;
- SCROW nRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
+ SCCOL nColDelta = p->aStart.Col() - nPrevCol;
+ SCROW nRowDelta = p->aStart.Row() - nPrevRow;
- if (aClipParam.meDirection == ScClipParam::Column && nRowSize != nPrevRowSize)
- {
- // column-oriented ranges must have identical row size.
- bValidRanges = false;
- break;
- }
- if (aClipParam.meDirection == ScClipParam::Row && nColSize != nPrevColSize)
- {
- // likewise, row-oriented ranges must have identical
- // column size.
- bValidRanges = false;
- break;
- }
+ if ((nColDelta && nRowDelta) || (nPrevColDelta && nRowDelta) || (nPrevRowDelta && nColDelta))
+ {
+ bValidRanges = false;
+ break;
+ }
- nPrevCol = p->aStart.Col();
- nPrevRow = p->aStart.Row();
- nPrevColDelta = nColDelta;
- nPrevRowDelta = nRowDelta;
- nPrevColSize = nColSize;
- nPrevRowSize = nRowSize;
+ if (aClipParam.meDirection == ScClipParam::Unspecified)
+ {
+ if (nColDelta)
+ aClipParam.meDirection = ScClipParam::Column;
+ if (nRowDelta)
+ aClipParam.meDirection = ScClipParam::Row;
}
- if (!bValidRanges)
- break;
- pDoc->CopyToClip(aClipParam, pDocClip.get(), &rMark, false, bIncludeObjects );
- ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
- if ( pChangeTrack )
- pChangeTrack->ResetLastCut(); // no more cut-mode
+ SCCOL nColSize = p->aEnd.Col() - p->aStart.Col() + 1;
+ SCROW nRowSize = p->aEnd.Row() - p->aStart.Row() + 1;
+ if (aClipParam.meDirection == ScClipParam::Column && nRowSize != nPrevRowSize)
{
- ScDocShell* pDocSh = GetViewData().GetDocShell();
- TransferableObjectDescriptor aObjDesc;
- pDocSh->FillTransferableObjectDescriptor( aObjDesc );
- aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
- // maSize is set in ScTransferObj ctor
-
- ScTransferObj* pTransferObj = new ScTransferObj( pDocClip.release(), aObjDesc );
- uno::Reference<css::datatransfer::XTransferable2> xTransferObj = pTransferObj;
- if ( ScGlobal::xDrawClipDocShellRef.is() )
- {
- SfxObjectShellRef aPersistRef( ScGlobal::xDrawClipDocShellRef.get() );
- pTransferObj->SetDrawPersist( aPersistRef ); // keep persist for ole objects alive
- }
- pTransferObj->CopyToClipboard( GetActiveWin() ); // system clipboard
+ // column-oriented ranges must have identical row size.
+ bValidRanges = false;
+ break;
+ }
+ if (aClipParam.meDirection == ScClipParam::Row && nColSize != nPrevColSize)
+ {
+ // likewise, row-oriented ranges must have identical
+ // column size.
+ bValidRanges = false;
+ break;
}
- bSuccess = true;
+ nPrevCol = p->aStart.Col();
+ nPrevRow = p->aStart.Row();
+ nPrevColDelta = nColDelta;
+ nPrevRowDelta = nRowDelta;
+ nPrevColSize = nColSize;
+ nPrevRowSize = nRowSize;
}
- while (false);
+ if (!bValidRanges)
+ break;
+ pDoc->CopyToClip(aClipParam, pDocClip.get(), &rMark, false, bIncludeObjects );
- if (!bSuccess && !bApi)
- ErrorMessage(STR_NOMULTISELECT);
+ ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
+ if ( pChangeTrack )
+ pChangeTrack->ResetLastCut(); // no more cut-mode
- bDone = bSuccess;
+ ScDocShell* pDocSh = GetViewData().GetDocShell();
+ TransferableObjectDescriptor aObjDesc;
+ pDocSh->FillTransferableObjectDescriptor( aObjDesc );
+ aObjDesc.maDisplayName = pDocSh->GetMedium()->GetURLObject().GetURLNoPass();
+ // maSize is set in ScTransferObj ctor
+
+ ScTransferObj* pTransferObj = new ScTransferObj( pDocClip.release(), aObjDesc );
+ uno::Reference<css::datatransfer::XTransferable2> xTransferObj = pTransferObj;
+ if ( ScGlobal::xDrawClipDocShellRef.is() )
+ {
+ SfxObjectShellRef aPersistRef( ScGlobal::xDrawClipDocShellRef.get() );
+ pTransferObj->SetDrawPersist( aPersistRef ); // keep persist for ole objects alive
+ }
+ pTransferObj->CopyToClipboard( GetActiveWin() ); // system clipboard
+
+ bSuccess = true;
}
+ while (false);
+
+ if (!bSuccess && !bApi)
+ ErrorMessage(STR_NOMULTISELECT);
+
+ bDone = bSuccess;
return bDone;
}