diff options
author | Henry Castro <hcastro@collabora.com> | 2015-02-13 20:22:04 -0400 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2015-04-03 07:32:23 +0000 |
commit | bff29a3b30c8e57ab78937dca862fd738f26d89e (patch) | |
tree | 6188c3af93f0d18dc2f9c643906e4ae64ed2ab9d | |
parent | 0c32c2133e3be1ddbc719772007ba3833d2bb848 (diff) |
tdf#51460 Calc fails to set undo step after changing image anchor mode
Fixed. Note that the undo button is still grayed out. Calc has not set an undo step.
Change-Id: I7ff713a906b365b460351e5202161c9152542395
Reviewed-on: https://gerrit.libreoffice.org/14489
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | sc/CppunitTest_sc_condformats.mk | 2 | ||||
-rw-r--r-- | sc/inc/drwlayer.hxx | 14 | ||||
-rw-r--r-- | sc/inc/sc.hrc | 5 | ||||
-rw-r--r-- | sc/qa/extras/sccondformats.cxx | 110 | ||||
-rw-r--r-- | sc/source/core/data/drwlayer.cxx | 43 | ||||
-rw-r--r-- | sc/source/ui/src/scstring.src | 10 | ||||
-rw-r--r-- | sc/source/ui/view/drawvie3.cxx | 10 |
7 files changed, 194 insertions, 0 deletions
diff --git a/sc/CppunitTest_sc_condformats.mk b/sc/CppunitTest_sc_condformats.mk index 0ee259ea9562..799306a4aad9 100644 --- a/sc/CppunitTest_sc_condformats.mk +++ b/sc/CppunitTest_sc_condformats.mk @@ -33,6 +33,8 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_condformats, \ salhelper \ sax \ sb \ + sc \ + scqahelper \ sfx \ sot \ subsequenttest \ diff --git a/sc/inc/drwlayer.hxx b/sc/inc/drwlayer.hxx index 6917c2aaa4f2..4d355b948443 100644 --- a/sc/inc/drwlayer.hxx +++ b/sc/inc/drwlayer.hxx @@ -76,6 +76,20 @@ public: virtual void Redo() SAL_OVERRIDE; }; +class ScUndoAnchorData : public SdrUndoObj +{ +private: + bool mbWasCellAnchored; + ScDocument* mpDoc; + SCTAB mnTab; +public: + ScUndoAnchorData( SdrObject* pObj, ScDocument* pDoc, SCTAB nTab ); + virtual ~ScUndoAnchorData(); + + virtual void Undo() SAL_OVERRIDE; + virtual void Redo() SAL_OVERRIDE; +}; + class SC_DLLPUBLIC ScDrawLayer : public FmFormModel { private: diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc index f76a45a3f7aa..242d8e8deee3 100644 --- a/sc/inc/sc.hrc +++ b/sc/inc/sc.hrc @@ -908,6 +908,11 @@ #define STR_CELL (STR_START + 219) #define STR_CONTENT (STR_START + 220) +// Undo Anchor + +#define SCSTR_UNDO_PAGE_ANCHOR (STR_START + 221) +#define SCSTR_UNDO_CELL_ANCHOR (STR_START + 222) + // navigator - in the same order as SC_CONTENT_... #define SCSTR_CONTENT_ROOT (STR_START + 250) #define SCSTR_CONTENT_TABLE (STR_START + 251) diff --git a/sc/qa/extras/sccondformats.cxx b/sc/qa/extras/sccondformats.cxx index 4a664c43cc87..8b6f66647f2c 100644 --- a/sc/qa/extras/sccondformats.cxx +++ b/sc/qa/extras/sccondformats.cxx @@ -8,6 +8,9 @@ */ #include <test/calc_unoapi_test.hxx> +#include <svx/svdograf.hxx> +#include <svx/svdpage.hxx> +#include <sfx2/dispatch.hxx> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/sheet/ConditionOperator.hpp> @@ -17,6 +20,11 @@ #include <com/sun/star/table/CellAddress.hpp> #include <unonames.hxx> +#include "tabvwsh.hxx" +#include "docsh.hxx" + +#include "sc.hrc" + using namespace css; namespace sc_apitest { @@ -33,9 +41,11 @@ public: uno::Reference< uno::XInterface > init(); void testCondFormat(); + void testUndoAnchor(); CPPUNIT_TEST_SUITE(ScConditionalFormatTest); CPPUNIT_TEST(testCondFormat); + CPPUNIT_TEST(testUndoAnchor); CPPUNIT_TEST_SUITE_END(); private: @@ -110,6 +120,106 @@ void ScConditionalFormatTest::testCondFormat() CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xSheetConditionalEntries->getCount()); } +void ScConditionalFormatTest::testUndoAnchor() +{ + const OString sFailedMessage = OString("Failed on :"); + OUString aFileURL; + createFileURL(OUString("document_with_linked_graphic.ods"), aFileURL); + // open the document with graphic included + uno::Reference< com::sun::star::lang::XComponent > xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + + ScDocShell* xDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(xDocSh != NULL); + + // Check whether graphic imported well + ScDocument& rDoc = xDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDrawLayer != NULL ); + + const SdrPage *pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pPage != NULL ); + + SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pObject != NULL ); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pObject->IsLinkedGraphic() ); + + const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), !rGraphicObj.IsSwappedOut()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + // Get the document controller + ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pViewShell != NULL ); + + // Get the draw view of the document + ScDrawView* pDrawView = pViewShell->GetViewData().GetScDrawView(); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDrawView != NULL ); + + // Select graphic object + pDrawView->MarkNextObj(false); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), pDrawView->AreObjectsMarked() ); + + // Set Cell Anchor + ScDrawLayer::SetCellAnchoredFromPosition(*pObject, rDoc, 0); + // Check state + ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == SCA_CELL ); + + // Change all selected objects to page anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_PAGE); + // Check state + ScAnchorType newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == SCA_PAGE ); + + // Undo and check its result. + SfxUndoManager* pUndoMgr = rDoc.GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + ScDrawLayer::SetPageAnchored(*pObject); + // Check state + oldType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == SCA_PAGE ); + + // Change all selected objects to cell anchor + pViewShell->GetViewData().GetDispatcher().Execute(SID_ANCHOR_CELL); + // Check state + newType = ScDrawLayer::GetAnchorType(*pObject); + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == SCA_CELL ); + + pUndoMgr->Undo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), oldType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); + + pUndoMgr->Redo(); + + // Check anchor type + CPPUNIT_ASSERT_MESSAGE( sFailedMessage.getStr(), newType == ScDrawLayer::GetAnchorType(*pObject) ); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), GRAPHIC_BITMAP, rGraphicObj.GetGraphic().GetType()); + CPPUNIT_ASSERT_EQUAL_MESSAGE( sFailedMessage.getStr(), sal_uLong(864900), rGraphicObj.GetSizeBytes()); +} + void ScConditionalFormatTest::setUp() { nTest++; diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 1ec9d131249b..e70254a24558 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -129,6 +129,49 @@ void ScUndoObjData::Redo() } } +ScUndoAnchorData::ScUndoAnchorData( SdrObject* pObjP, ScDocument* pDoc, SCTAB nTab ) : + SdrUndoObj( *pObjP ), + mpDoc( pDoc ), + mnTab( nTab ) +{ + mbWasCellAnchored = ScDrawLayer::IsCellAnchored( *pObjP ); +} + +ScUndoAnchorData::~ScUndoAnchorData() +{ +} + +void ScUndoAnchorData::Undo() +{ + // Trigger Object Change + if(pObj && pObj->IsInserted() && pObj->GetPage() && pObj->GetModel()) + { + SdrHint aHint(*pObj); + pObj->GetModel()->Broadcast(aHint); + } + + if (mbWasCellAnchored) + ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab); + else + ScDrawLayer::SetPageAnchored( *pObj ); +} + +void ScUndoAnchorData::Redo() +{ + if (mbWasCellAnchored) + ScDrawLayer::SetPageAnchored( *pObj ); + else + ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *mpDoc, mnTab); + + // Trigger Object Change + if(pObj && pObj->IsInserted() && pObj->GetPage() && pObj->GetModel()) + { + SdrHint aHint(*pObj); + pObj->GetModel()->Broadcast(aHint); + } +} + + ScTabDeletedHint::ScTabDeletedHint( SCTAB nTabNo ) : nTab( nTabNo ) { diff --git a/sc/source/ui/src/scstring.src b/sc/source/ui/src/scstring.src index 8b9c6e18ccd3..91ef6c505da1 100644 --- a/sc/source/ui/src/scstring.src +++ b/sc/source/ui/src/scstring.src @@ -907,4 +907,14 @@ String STR_CONTENT Text [ en-US ] = "Content" ; }; +String SCSTR_UNDO_PAGE_ANCHOR +{ + Text [ en-US ] = "Page Anchor" ; +}; + +String SCSTR_UNDO_CELL_ANCHOR +{ + Text [ en-US ] = "Cell Anchor" ; +}; + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/view/drawvie3.cxx b/sc/source/ui/view/drawvie3.cxx index f0b1835a2695..74ad8e683f19 100644 --- a/sc/source/ui/view/drawvie3.cxx +++ b/sc/source/ui/view/drawvie3.cxx @@ -22,6 +22,8 @@ #include <sfx2/app.hxx> #include <sfx2/viewfrm.hxx> +#include "sc.hrc" +#include "scresid.hxx" #include "drawview.hxx" #include "drwlayer.hxx" #include "imapwrap.hxx" @@ -59,11 +61,15 @@ void ScDrawView::SetPageAnchored() { const SdrMarkList* pMark = &GetMarkedObjectList(); const size_t nCount = pMark->GetMarkCount(); + + BegUndo( OUString(ScResId( SCSTR_UNDO_PAGE_ANCHOR )) ); for( size_t i=0; i<nCount; ++i ) { SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); + AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab )); ScDrawLayer::SetPageAnchored( *pObj ); } + EndUndo(); if ( pViewData ) pViewData->GetDocShell()->SetDrawModified(); @@ -83,11 +89,15 @@ void ScDrawView::SetCellAnchored() { const SdrMarkList* pMark = &GetMarkedObjectList(); const size_t nCount = pMark->GetMarkCount(); + + BegUndo( OUString(ScResId( SCSTR_UNDO_CELL_ANCHOR )) ); for( size_t i=0; i<nCount; ++i ) { SdrObject* pObj = pMark->GetMark(i)->GetMarkedSdrObj(); + AddUndo (new ScUndoAnchorData( pObj, pDoc, nTab )); ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *pDoc, nTab); } + EndUndo(); if ( pViewData ) pViewData->GetDocShell()->SetDrawModified(); |