From 4acac00df5a85ff006ecead06c4018e88caaf401 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 3 Aug 2016 11:39:07 +0200 Subject: [PATCH] svx: track view shell id in SdrUndoAction This is used in Impress e.g. when resizing a picture. Change-Id: I2e0a9228ed0ff9ecfd72696ef84e56f88e4c0f70 Reviewed-on: https://gerrit.libreoffice.org/27822 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- include/svx/svdundo.hxx | 8 +++++--- sd/qa/unit/tiledrendering/tiledrendering.cxx | 13 +++++++++++++ svx/source/svdraw/svdundo.cxx | 11 +++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/svx/svdundo.hxx b/include/svx/svdundo.hxx index 9d63557f8fc6..fa6cc8a424c7 100644 --- a/include/svx/svdundo.hxx +++ b/include/svx/svdundo.hxx @@ -55,11 +55,10 @@ class SVX_DLLPUBLIC SdrUndoAction : public SfxUndoAction { protected: SdrModel& rMod; + sal_Int32 m_nViewShellId; protected: - SdrUndoAction(SdrModel& rNewMod) - : rMod(rNewMod) - {} + SdrUndoAction(SdrModel& rNewMod); public: virtual ~SdrUndoAction(); @@ -72,6 +71,9 @@ public: virtual bool CanSdrRepeat(SdrView& rView) const; virtual void SdrRepeat(SdrView& rView); + + /// See SfxUndoAction::GetViewShellId(). + sal_Int32 GetViewShellId() const override; }; /** diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 603efff3f0bd..c8dc99369057 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -34,6 +34,7 @@ #include #include #include +#include using namespace css; @@ -412,6 +413,18 @@ void SdTiledRenderingTest::testSetGraphicSelection() // Resize. pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(pHdl->GetPos().getX()), convertMm100ToTwip(pHdl->GetPos().getY())); pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_END, convertMm100ToTwip(pHdl->GetPos().getX()), convertMm100ToTwip(pHdl->GetPos().getY() + 1000)); + + // Assert that view shell ID tracking works. + sal_Int32 nView1 = SfxLokHelper::getView(); + SdDrawDocument* pDocument = pXImpressDocument->GetDoc(); + sd::UndoManager* pUndoManager = pDocument->GetUndoManager(); + CPPUNIT_ASSERT_EQUAL(static_cast(1), pUndoManager->GetUndoActionCount()); + auto pListAction = dynamic_cast(pUndoManager->GetUndoAction()); + CPPUNIT_ASSERT(pListAction); + for (size_t i = 0; i < pListAction->aUndoActions.size(); ++i) + // The second item was -1 here, view shell ID wasn't known. + CPPUNIT_ASSERT_EQUAL(nView1, pListAction->aUndoActions.GetUndoAction(i)->GetViewShellId()); + Rectangle aShapeAfter = pObject->GetSnapRect(); // Check that a resize happened, but aspect ratio is not kept. CPPUNIT_ASSERT_EQUAL(aShapeBefore.getWidth(), aShapeAfter.getWidth()); diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx index ec5f2fe61751..42b8337db3b1 100644 --- a/svx/source/svdraw/svdundo.cxx +++ b/svx/source/svdraw/svdundo.cxx @@ -45,6 +45,7 @@ #include #include // #i124389# #include +#include // iterates over all views and unmarks this SdrObject if it is marked @@ -57,6 +58,12 @@ static void ImplUnmarkObject( SdrObject* pObj ) } } +SdrUndoAction::SdrUndoAction(SdrModel& rNewMod) + : rMod(rNewMod), m_nViewShellId(-1) +{ + if (SfxViewShell* pViewShell = SfxViewShell::Current()) + m_nViewShellId = pViewShell->GetViewShellId(); +} SdrUndoAction::~SdrUndoAction() {} @@ -95,6 +102,10 @@ OUString SdrUndoAction::GetSdrRepeatComment(SdrView& /*rView*/) const return OUString(); } +sal_Int32 SdrUndoAction::GetViewShellId() const +{ + return m_nViewShellId; +} SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod) : SdrUndoAction(rNewMod),