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 <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
This commit is contained in:
Miklos Vajna
2016-08-03 11:39:07 +02:00
parent 405db7afbd
commit 4acac00df5
3 changed files with 29 additions and 3 deletions

View File

@@ -55,11 +55,10 @@ class SVX_DLLPUBLIC SdrUndoAction : public SfxUndoAction
{ {
protected: protected:
SdrModel& rMod; SdrModel& rMod;
sal_Int32 m_nViewShellId;
protected: protected:
SdrUndoAction(SdrModel& rNewMod) SdrUndoAction(SdrModel& rNewMod);
: rMod(rNewMod)
{}
public: public:
virtual ~SdrUndoAction(); virtual ~SdrUndoAction();
@@ -72,6 +71,9 @@ public:
virtual bool CanSdrRepeat(SdrView& rView) const; virtual bool CanSdrRepeat(SdrView& rView) const;
virtual void SdrRepeat(SdrView& rView); virtual void SdrRepeat(SdrView& rView);
/// See SfxUndoAction::GetViewShellId().
sal_Int32 GetViewShellId() const override;
}; };
/** /**

View File

@@ -34,6 +34,7 @@
#include <sdpage.hxx> #include <sdpage.hxx>
#include <unomodel.hxx> #include <unomodel.hxx>
#include <drawdoc.hxx> #include <drawdoc.hxx>
#include <undo/undomanager.hxx>
using namespace css; using namespace css;
@@ -412,6 +413,18 @@ void SdTiledRenderingTest::testSetGraphicSelection()
// Resize. // Resize.
pXImpressDocument->setGraphicSelection(LOK_SETGRAPHICSELECTION_START, convertMm100ToTwip(pHdl->GetPos().getX()), convertMm100ToTwip(pHdl->GetPos().getY())); 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)); 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<size_t>(1), pUndoManager->GetUndoActionCount());
auto pListAction = dynamic_cast<SfxListUndoAction*>(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(); Rectangle aShapeAfter = pObject->GetSnapRect();
// Check that a resize happened, but aspect ratio is not kept. // Check that a resize happened, but aspect ratio is not kept.
CPPUNIT_ASSERT_EQUAL(aShapeBefore.getWidth(), aShapeAfter.getWidth()); CPPUNIT_ASSERT_EQUAL(aShapeBefore.getWidth(), aShapeAfter.getWidth());

View File

@@ -45,6 +45,7 @@
#include <sdr/contact/viewcontactofgraphic.hxx> #include <sdr/contact/viewcontactofgraphic.hxx>
#include <svx/svdotable.hxx> // #i124389# #include <svx/svdotable.hxx> // #i124389#
#include <vcl/svapp.hxx> #include <vcl/svapp.hxx>
#include <sfx2/viewsh.hxx>
// iterates over all views and unmarks this SdrObject if it is marked // 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() {} SdrUndoAction::~SdrUndoAction() {}
@@ -95,6 +102,10 @@ OUString SdrUndoAction::GetSdrRepeatComment(SdrView& /*rView*/) const
return OUString(); return OUString();
} }
sal_Int32 SdrUndoAction::GetViewShellId() const
{
return m_nViewShellId;
}
SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod) SdrUndoGroup::SdrUndoGroup(SdrModel& rNewMod)
: SdrUndoAction(rNewMod), : SdrUndoAction(rNewMod),