diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-04-20 17:44:29 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-04-20 17:17:19 +0000 |
commit | 100eb15b4d8529d7a11d98a28742f31f0f792fa1 (patch) | |
tree | f0de11fb70b685bf58a3e7a39e64bb00ff55e400 /sd/qa | |
parent | e8425c48102321d4f5a8bd687c8ca1ac7bae797e (diff) |
tdf#99396 SdrTableObj::EndTextEdit: restore cell format undo items
As seen by the user: after finishing the text edit of an Impress table
cell, the text changes are still on the undo stack, but the table ones
(like background color or vertical alignment) get lost.
This happens as SdrUndoManager::SetEndTextEditHdl() removes all undo
items from the stack which are created after the start of the text edit,
and creates a single item, but that doesn't include the table changes,
just the text ones.
Fix the problem by creating a copy of the CellUndo objects when it text
edit mode, and pushing them to the undo stack in
SdrTableObj::EndTextEdit(), which already writes the undo stack and runs
after the undo manager cleared the text edit items from the undo stack.
Change-Id: I7d2768c86b5b262e98be1d09d7fa08d581430bb5
Reviewed-on: https://gerrit.libreoffice.org/24264
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'sd/qa')
-rw-r--r-- | sd/qa/unit/misc-tests.cxx | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx index 105c071d1a8e..857fbdd2103c 100644 --- a/sd/qa/unit/misc-tests.cxx +++ b/sd/qa/unit/misc-tests.cxx @@ -27,6 +27,10 @@ #include <svx/sdr/table/tablecontroller.hxx> #include <sfx2/request.hxx> #include <svx/svxids.hrc> +#include <editeng/eeitem.hxx> +#include <editeng/adjustitem.hxx> +#include <editeng/outlobj.hxx> +#include <editeng/editobj.hxx> #include <ImpressViewShellBase.hxx> #include <SlideSorterViewShell.hxx> #include <SlideSorter.hxx> @@ -45,11 +49,13 @@ public: void testTdf96206(); void testTdf96708(); void testTdf99396(); + void testTdf99396TextEdit(); CPPUNIT_TEST_SUITE(SdMiscTest); CPPUNIT_TEST(testTdf96206); CPPUNIT_TEST(testTdf96708); CPPUNIT_TEST(testTdf99396); + CPPUNIT_TEST(testTdf99396TextEdit); CPPUNIT_TEST_SUITE_END(); private: @@ -164,6 +170,75 @@ void SdMiscTest::testTdf99396() xDocSh->DoClose(); } +void SdMiscTest::testTdf99396TextEdit() +{ + // Load the document and select the table. + sd::DrawDocShellRef xDocSh = Load(m_directories.getURLFromSrc("/sd/qa/unit/data/tdf99396.odp"), ODP); + sd::ViewShell* pViewShell = xDocSh->GetViewShell(); + SdPage* pPage = pViewShell->GetActualPage(); + SdrObject* pObject = pPage->GetObj(0); + auto pTableObject = dynamic_cast<sdr::table::SdrTableObj*>(pObject); + SdrView* pView = pViewShell->GetView(); + pView->MarkObj(pObject, pView->GetSdrPageView()); + + // Make sure that the undo stack is empty. + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), xDocSh->GetDoc()->GetUndoManager()->GetUndoActionCount()); + + // Set horizontal and vertical adjustment during text edit. + pView->SdrBeginTextEdit(pObject); + CPPUNIT_ASSERT(pView->GetTextEditObject()); + { + SfxRequest aRequest(pViewShell->GetViewFrame(), SID_ATTR_PARA_ADJUST_RIGHT); + SfxItemSet aEditAttr(xDocSh->GetDoc()->GetPool()); + pView->GetAttributes(aEditAttr); + SfxItemSet aNewAttr(*(aEditAttr.GetPool()), aEditAttr.GetRanges()); + aNewAttr.Put(SvxAdjustItem(SVX_ADJUST_RIGHT, EE_PARA_JUST)); + aRequest.Done(aNewAttr); + const SfxItemSet* pArgs = aRequest.GetArgs(); + pView->SetAttributes(*pArgs); + } + { + auto pTableController = dynamic_cast<sdr::table::SvxTableController*>(pView->getSelectionController().get()); + SfxRequest aRequest(pViewShell->GetViewFrame(), SID_TABLE_VERT_BOTTOM); + pTableController->Execute(aRequest); + } + pView->SdrEndTextEdit(); + + // Check that the result is what we expect. + { + uno::Reference<table::XTable> xTable = pTableObject->getTable(); + uno::Reference<beans::XPropertySet> xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY); + drawing::TextVerticalAdjust eAdjust = xCell->getPropertyValue("TextVerticalAdjust").get<drawing::TextVerticalAdjust>(); + CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_BOTTOM, eAdjust); + } + { + const EditTextObject& rEdit = pTableObject->getText(0)->GetOutlinerParaObject()->GetTextObject(); + const SfxItemSet& rParaAttribs = rEdit.GetParaAttribs(0); + auto pAdjust = static_cast<const SvxAdjustItem*>(rParaAttribs.GetItem(EE_PARA_JUST)); + CPPUNIT_ASSERT_EQUAL(SVX_ADJUST_RIGHT, pAdjust->GetAdjust()); + } + + // Now undo. + xDocSh->GetUndoManager()->Undo(); + + // Check again that the result is what we expect. + { + uno::Reference<table::XTable> xTable = pTableObject->getTable(); + uno::Reference<beans::XPropertySet> xCell(xTable->getCellByPosition(0, 0), uno::UNO_QUERY); + drawing::TextVerticalAdjust eAdjust = xCell->getPropertyValue("TextVerticalAdjust").get<drawing::TextVerticalAdjust>(); + // This failed: Undo() did not change it from drawing::TextVerticalAdjust_BOTTOM. + CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_TOP, eAdjust); + } + { + const EditTextObject& rEdit = pTableObject->getText(0)->GetOutlinerParaObject()->GetTextObject(); + const SfxItemSet& rParaAttribs = rEdit.GetParaAttribs(0); + auto pAdjust = static_cast<const SvxAdjustItem*>(rParaAttribs.GetItem(EE_PARA_JUST)); + CPPUNIT_ASSERT_EQUAL(SVX_ADJUST_CENTER, pAdjust->GetAdjust()); + } + + xDocSh->DoClose(); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SdMiscTest); CPPUNIT_PLUGIN_IMPLEMENT(); |