Kaydet (Commit) bff29a3b authored tarafından Henry Castro's avatar Henry Castro Kaydeden (comit) Caolán McNamara

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/14489Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 0c32c213
......@@ -33,6 +33,8 @@ $(eval $(call gb_CppunitTest_use_libraries,sc_condformats, \
salhelper \
sax \
sb \
sc \
scqahelper \
sfx \
sot \
subsequenttest \
......
......@@ -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:
......
......@@ -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)
......
......@@ -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++;
......
......@@ -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 )
{
......
......@@ -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: */
......@@ -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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment