diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-01-18 15:34:49 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-01-21 10:42:02 +0100 |
commit | 0c6ee963e1f089cb73e0c68a28af29d0f8d9e0df (patch) | |
tree | f17f1c9b5d3c9851fb2d41b43b2c7b100756e00d /sc/source/ui | |
parent | d769e75de28a1afbb1df31b48840626cb35ed7ba (diff) |
sc: fix VBA Copy-Paste using same and separate document
This fixes 2 issues with VBA copy-paste:
- VBA command Range(..).Copy issue where the range wasn't selected
when copying and the copied cells were from the previous selection.
The Copy command now does the same selection as the Cut command.
- VBA PasteSpecial issue where the wrong view was used to get the
clip document.
- VBA Workbooks.Add issue where the new workbook wasn't activated
after it was created, which causes an issue when running tests, but
not when running in LO application. The Add command does now the same
as the Workbooks.Open command.
All the issues are supported by new test cases.
Change-Id: I36ec45c01f18f7f76e4f95a25a28402a6ee0e2e2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128720
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/vba/excelvbahelper.cxx | 25 | ||||
-rw-r--r-- | sc/source/ui/vba/vbarange.cxx | 7 | ||||
-rw-r--r-- | sc/source/ui/vba/vbaworkbooks.cxx | 11 |
3 files changed, 27 insertions, 16 deletions
diff --git a/sc/source/ui/vba/excelvbahelper.cxx b/sc/source/ui/vba/excelvbahelper.cxx index d337a0f6836e..37d3a5fcf1de 100644 --- a/sc/source/ui/vba/excelvbahelper.cxx +++ b/sc/source/ui/vba/excelvbahelper.cxx @@ -210,25 +210,28 @@ void implnPasteSpecial( const uno::Reference< frame::XModel>& xModel, InsertDele { PasteCellsWarningReseter resetWarningBox; - ScTabViewShell* pTabViewShell = getBestViewShell( xModel ); - ScDocShell* pDocShell = getDocShell( xModel ); - if ( !(pTabViewShell && pDocShell) ) + ScTabViewShell* pTabViewShell = getBestViewShell(xModel); + if (!pTabViewShell) + return; + + ScDocShell* pDocShell = getDocShell(xModel); + if (!pDocShell) return; ScViewData& rView = pTabViewShell->GetViewData(); vcl::Window* pWin = rView.GetActiveWin(); - if (pWin) + if (!pWin) + return; + + const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(ScTabViewShell::GetClipData(pWin)); + if (pOwnClip) { - const ScTransferObj* pOwnClip = ScTransferObj::GetOwnClipboard(pDocShell->GetClipData()); - ScDocument* pDoc = nullptr; - if ( pOwnClip ) - pDoc = pOwnClip->GetDocument(); - pTabViewShell->PasteFromClip( nFlags, pDoc, + pTabViewShell->PasteFromClip(nFlags, pOwnClip->GetDocument(), nFunction, bSkipEmpty, bTranspose, false, - INS_NONE, InsertDeleteFlags::NONE, true ); + INS_NONE, InsertDeleteFlags::NONE, true); + pTabViewShell->CellContentChanged(); } - } ScDocShell* diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index d264682a1f7a..d15420bb698c 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -2535,7 +2535,9 @@ ScVbaRange::Copy(const ::uno::Any& Destination) } else { - excel::implnCopy( getUnoModel() ); + uno::Reference<frame::XModel> xModel = getModelFromRange(mxRange); + Select(); + excel::implnCopy(getUnoModel()); } } @@ -2893,7 +2895,8 @@ ScVbaRange::PasteSpecial( const uno::Any& Paste, const uno::Any& Operation, cons InsertDeleteFlags nFlags = getPasteFlags(nPaste); ScPasteFunc nFormulaBits = getPasteFormulaBits(nOperation); - excel::implnPasteSpecial(pShell->GetModel(), nFlags,nFormulaBits,bSkipBlanks,bTranspose); + + excel::implnPasteSpecial(xModel, nFlags, nFormulaBits, bSkipBlanks, bTranspose); } uno::Reference< excel::XRange > diff --git a/sc/source/ui/vba/vbaworkbooks.cxx b/sc/source/ui/vba/vbaworkbooks.cxx index bd52292cfa5a..e3b608b33942 100644 --- a/sc/source/ui/vba/vbaworkbooks.cxx +++ b/sc/source/ui/vba/vbaworkbooks.cxx @@ -144,9 +144,14 @@ ScVbaWorkbooks::Add( const uno::Any& Template ) // need to set up the document modules ( and vba mode ) here excel::setUpDocumentModules( xSpreadDoc ); - if( xSpreadDoc.is() ) - return getWorkbook( mxContext, xSpreadDoc, mxParent ); - return uno::Any(); + if (!xSpreadDoc.is()) + return uno::Any(); + + uno::Any aRet = getWorkbook( mxContext, xSpreadDoc, mxParent ); + uno::Reference< excel::XWorkbook > xWBook( aRet, uno::UNO_QUERY ); + if (xWBook.is()) + xWBook->Activate(); + return aRet; } void SAL_CALL |