[Libreoffice-commits] core.git: Branch 'libreoffice-5-1' - include/svx sd/inc sd/qa sd/source svx/source
Miklos Vajna
vmiklos at collabora.co.uk
Tue Apr 26 08:03:45 UTC 2016
include/svx/svdotable.hxx | 4 +
sd/inc/drawdoc.hxx | 2
sd/qa/unit/data/tdf99396.odp |binary
sd/qa/unit/misc-tests.cxx | 104 +++++++++++++++++++++++++++++++++
sd/source/ui/table/TableDesignPane.cxx | 10 ++-
svx/source/table/cell.cxx | 5 +
svx/source/table/svdotable.cxx | 12 +++
svx/source/table/tablecontroller.cxx | 18 +++++
8 files changed, 152 insertions(+), 3 deletions(-)
New commits:
commit 64b2f209b72c5a5662afcb0ac1706b882e0e059b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Tue Apr 19 17:38:14 2016 +0200
tdf#99396 SvxTableController::SetVertical: implement undo support
All the table and cell objects know how to undo this change, what was
missing is the begin/end undo calls and the broadcast of the cell
format change.
(cherry picked from commits 3057b5cdb989d44613518900b25ebad8b7c600a2,
d60d70d92cec7bbc471f8f0c653d443282227d34,
6819992113947e7a6272bf750fee712c2df41905 and
100eb15b4d8529d7a11d98a28742f31f0f792fa1)
Conflicts:
sd/qa/unit/misc-tests.cxx
Change-Id: I3dfd203faf5c579da2937fedab5647129a8e903a
Reviewed-on: https://gerrit.libreoffice.org/24276
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Andras Timar <andras.timar at collabora.com>
diff --git a/include/svx/svdotable.hxx b/include/svx/svdotable.hxx
index 78a7e53c..f70d768 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 e2ff20c..ee8a876 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 0000000..6362600
Binary files /dev/null and b/sd/qa/unit/data/tdf99396.odp differ
diff --git a/sd/qa/unit/misc-tests.cxx b/sd/qa/unit/misc-tests.cxx
index e1d8b2a..bdda086 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 2bd52b5..4ae2e1d 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 b2d1604..c783cb1 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 15bbb7f..5b979fe 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 0238e85..beb75e0 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();
}
}
More information about the Libreoffice-commits
mailing list