Kaydet (Commit) 33141f99 authored tarafından Miklos Vajna's avatar Miklos Vajna

SwDrawView::DeleteMarked: delete textbox of shape as well

If we delete a shape that had a textbox, then delete that textbox as
well. Without that, the doc model would be still consistent, but most
probably would not be what the user expects.

Change-Id: Id5075233ce66d7a398c88ff3e63b05a6b2133571
üst 295b97b2
......@@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uiwriter, \
cppuhelper \
sal \
svt \
svxcore \
sw \
test \
unotest \
......
......@@ -12,6 +12,9 @@
#include <crsskip.hxx>
#include <shellio.hxx>
#include <expfld.hxx>
#include <drawdoc.hxx>
#include <svx/svdpage.hxx>
#include "UndoManager.hxx"
......@@ -32,6 +35,7 @@ public:
void testFdo75110();
void testFdo75898();
void testFdo74981();
void testShapeTextboxDelete();
CPPUNIT_TEST_SUITE(SwUiWriterTest);
CPPUNIT_TEST(testReplaceForward);
......@@ -43,6 +47,7 @@ public:
CPPUNIT_TEST(testFdo75110);
CPPUNIT_TEST(testFdo75898);
CPPUNIT_TEST(testFdo74981);
CPPUNIT_TEST(testShapeTextboxDelete);
CPPUNIT_TEST_SUITE_END();
private:
......@@ -271,6 +276,23 @@ void SwUiWriterTest::testFdo74981()
CPPUNIT_ASSERT(!pTxtNode->HasHints());
}
void SwUiWriterTest::testShapeTextboxDelete()
{
SwDoc* pDoc = createDoc("shape-textbox-delete.odt");
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
SdrPage* pPage = pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
SdrObject* pObject = pPage->GetObj(0);
pWrtShell->SelectObj(Point(), 0, pObject);
sal_Int32 nActual = pPage->GetObjCount();
// Two objects on the draw page: the shape and its textbox.
CPPUNIT_ASSERT_EQUAL(sal_Int32(2), nActual);
pWrtShell->DelSelectedObj();
nActual = pPage->GetObjCount();
// Both (not only the shape) should be removed by now (the textbox wasn't removed, so this was 1).
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), nActual);
}
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
......
......@@ -34,6 +34,7 @@
#include "frmfmt.hxx"
#include "dflyobj.hxx"
#include "dcontact.hxx"
#include "textboxhelper.hxx"
#include "frmatr.hxx"
#include "viewsh.hxx"
#include "viewimp.hxx"
......@@ -939,10 +940,27 @@ void SwDrawView::DeleteMarked()
}
}
}
// Check what textboxes have to be deleted afterwards.
const SdrMarkList& rMarkList = GetMarkedObjectList();
std::vector<SwFrmFmt*> aTextBoxesToDelete;
for (sal_uInt16 i = 0; i < rMarkList.GetMarkCount(); ++i)
{
SdrObject *pObject = rMarkList.GetMark(i)->GetMarkedSdrObj();
SwDrawContact* pDrawContact = static_cast<SwDrawContact*>(GetUserCall(pObject));
SwFrmFmt* pFmt = pDrawContact->GetFmt();
if (SwFrmFmt* pTextBox = SwTextBoxHelper::findTextBox(pFmt))
aTextBoxesToDelete.push_back(pTextBox);
}
if ( pDoc->DeleteSelection( *this ) )
{
FmFormView::DeleteMarked();
::FrameNotify( Imp().GetShell(), FLY_DRAG_END );
// Only delete these now: earlier deletion would clear the mark list as well.
for (std::vector<SwFrmFmt*>::iterator i = aTextBoxesToDelete.begin(); i != aTextBoxesToDelete.end(); ++i)
pDoc->DelLayoutFmt(*i);
}
pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_EMPTY, NULL);
if( pTmpRoot )
......
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