summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/svx/svdotable.hxx4
-rw-r--r--sd/inc/drawdoc.hxx2
-rw-r--r--sd/qa/unit/data/tdf99396.odpbin0 -> 10956 bytes
-rw-r--r--sd/qa/unit/misc-tests.cxx104
-rw-r--r--sd/source/ui/table/TableDesignPane.cxx10
-rw-r--r--svx/source/table/cell.cxx5
-rw-r--r--svx/source/table/svdotable.cxx12
-rw-r--r--svx/source/table/tablecontroller.cxx18
8 files changed, 152 insertions, 3 deletions
diff --git a/include/svx/svdotable.hxx b/include/svx/svdotable.hxx
index 78a7e53c4133..f70d76840338 100644
--- a/include/svx/svdotable.hxx
+++ b/include/svx/svdotable.hxx
@@ -31,6 +31,7 @@
class SvStream;
class SfxStyleSheet;
+class SdrUndoAction;
namespace sdr { namespace contact {
class ViewContactOfTableObj;
@@ -257,6 +258,9 @@ public:
css::text::WritingMode GetWritingMode() const;
+ /// Add an undo action that should be on the undo stack after ending text edit.
+ void AddUndo(SdrUndoAction* pUndo);
+
virtual void onEditOutlinerStatusEvent( EditStatus* pEditStatus ) override;
diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index e2ff20cd2b55..ee8a876e2ade 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -571,7 +571,7 @@ public:
languages set at this document */
SAL_DLLPRIVATE void getDefaultFonts( vcl::Font& rLatinFont, vcl::Font& rCJKFont, vcl::Font& rCTLFont );
- SAL_DLLPRIVATE sd::UndoManager* GetUndoManager() const;
+ sd::UndoManager* GetUndoManager() const;
/** converts the given western font height to a corresponding ctl font height, depending on the system language */
SAL_DLLPRIVATE static sal_uInt32 convertFontHeightToCTL( sal_uInt32 nWesternFontHeight );
diff --git a/sd/qa/unit/data/tdf99396.odp b/sd/qa/unit/data/tdf99396.odp
new file mode 100644
index 000000000000..636260020c02
--- /dev/null
+++ b/sd/qa/unit/data/tdf99396.odp
Binary files differ
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index e1d8b2abed40..bdda086d930c 100644
--- a/sd/qa/unit/misc-tests.cxx
+++ b/sd/qa/unit/misc-tests.cxx
@@ -25,12 +25,20 @@
#include <FactoryIds.hxx>
#include <sdmod.hxx>
#include <tools/shl.hxx>
+#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>
#include <controller/SlideSorterController.hxx>
#include <controller/SlsClipboard.hxx>
#include <controller/SlsPageSelector.hxx>
+#include <undo/undomanager.hxx>
using namespace ::com::sun::star;
@@ -40,10 +48,14 @@ class SdMiscTest : public SdModelTestBase
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:
@@ -137,6 +149,98 @@ void SdMiscTest::testTdf96708()
xDocSh->DoClose();
}
+void SdMiscTest::testTdf99396()
+{
+ // Load the document and select the table.
+ sd::DrawDocShellRef xDocSh = Load(getURLFromSrc("/sd/qa/unit/data/tdf99396.odp"), ODP);
+ sd::ViewShell *pViewShell = xDocSh->GetViewShell();
+ SdPage* pPage = pViewShell->GetActualPage();
+ SdrObject* pObject = pPage->GetObj(0);
+ 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 the vertical alignment of the cells to bottom.
+ sdr::table::SvxTableController* pTableController = dynamic_cast<sdr::table::SvxTableController*>(pView->getSelectionController().get());
+ SfxRequest aRequest(pViewShell->GetViewFrame(), SID_TABLE_VERT_BOTTOM);
+ pTableController->Execute(aRequest);
+ // This was 0, it wasn't possible to undo a vertical alignment change.
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), xDocSh->GetDoc()->GetUndoManager()->GetUndoActionCount());
+
+ xDocSh->DoClose();
+}
+
+void SdMiscTest::testTdf99396TextEdit()
+{
+ // Load the document and select the table.
+ sd::DrawDocShellRef xDocSh = Load(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();
diff --git a/sd/source/ui/table/TableDesignPane.cxx b/sd/source/ui/table/TableDesignPane.cxx
index 2bd52b51a924..4ae2e1d68323 100644
--- a/sd/source/ui/table/TableDesignPane.cxx
+++ b/sd/source/ui/table/TableDesignPane.cxx
@@ -806,7 +806,15 @@ short TableDesignDialog::Execute()
VclPtr<vcl::Window> createTableDesignPanel( vcl::Window* pParent, ViewShellBase& rBase )
{
- return VclPtr<TableDesignPane>::Create( pParent, rBase );
+ VclPtr<TableDesignPane> pRet = nullptr;
+ try
+ {
+ pRet = VclPtr<TableDesignPane>::Create( pParent, rBase );
+ }
+ catch (const uno::Exception&)
+ {
+ }
+ return pRet;
}
void showTableDesignDialog( vcl::Window* pParent, ViewShellBase& rBase )
diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx
index b2d1604a0bdc..c783cb1fb7d6 100644
--- a/svx/source/table/cell.cxx
+++ b/svx/source/table/cell.cxx
@@ -799,6 +799,11 @@ void Cell::AddUndo()
{
CellRef xCell( this );
GetModel()->AddUndo( new CellUndo( &rObj, xCell ) );
+
+ // Undo action for the after-text-edit-ended stack.
+ SdrTableObj* pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(&rObj);
+ if (pTableObj && pTableObj->IsTextEditActive())
+ pTableObj->AddUndo(new CellUndo(pTableObj, xCell));
}
}
diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx
index 15bbb7f640c3..5b979febf860 100644
--- a/svx/source/table/svdotable.cxx
+++ b/svx/source/table/svdotable.cxx
@@ -205,6 +205,7 @@ public:
CellPos maEditPos;
TableStyleSettings maTableStyle;
Reference< XIndexAccess > mxTableStyle;
+ std::vector<std::unique_ptr<SdrUndoAction>> maUndos;
void SetModel(SdrModel* pOldModel, SdrModel* pNewModel);
@@ -1860,7 +1861,14 @@ void SdrTableObj::EndTextEdit(SdrOutliner& rOutl)
if(rOutl.IsModified())
{
if( GetModel() && GetModel()->IsUndoEnabled() )
+ {
+ // These actions should be on the undo stack after text edit.
+ for (std::unique_ptr<SdrUndoAction>& pAction : mpImpl->maUndos)
+ GetModel()->AddUndo(pAction.release());
+ mpImpl->maUndos.clear();
+
GetModel()->AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*this) );
+ }
OutlinerParaObject* pNewText = nullptr;
Paragraph* p1stPara = rOutl.GetParagraph( 0 );
@@ -2085,6 +2093,10 @@ WritingMode SdrTableObj::GetWritingMode() const
return eWritingMode;
}
+void SdrTableObj::AddUndo(SdrUndoAction* pUndo)
+{
+ mpImpl->maUndos.push_back(std::unique_ptr<SdrUndoAction>(pUndo));
+}
// gets base transformation and rectangle of object. If it's an SdrPathObj it fills the PolyPolygon
diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx
index 0238e851e4ff..beb75e035f04 100644
--- a/svx/source/table/tablecontroller.cxx
+++ b/svx/source/table/tablecontroller.cxx
@@ -1177,6 +1177,13 @@ void SvxTableController::SetVertical( sal_uInt16 nSId )
{
TableModelNotifyGuard aGuard( mxTable.get() );
+ bool bUndo = mpModel && mpModel->IsUndoEnabled();
+ if (bUndo)
+ {
+ mpModel->BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT));
+ mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoAttrObject(*pTableObj));
+ }
+
CellPos aStart, aEnd;
getSelectedCells( aStart, aEnd );
@@ -1203,11 +1210,20 @@ void SvxTableController::SetVertical( sal_uInt16 nSId )
{
CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) );
if( xCell.is() )
- xCell->SetMergedItem(aItem);
+ {
+ if (bUndo)
+ xCell->AddUndo();
+ SfxItemSet aSet(xCell->GetItemSet());
+ aSet.Put(aItem);
+ xCell->SetMergedItemSetAndBroadcast(aSet, /*bClearAllItems=*/false);
+ }
}
}
UpdateTableShape();
+
+ if (bUndo)
+ mpModel->EndUndo();
}
}