diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-06-23 15:40:45 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-06-23 17:07:43 +0200 |
commit | 33141f999b22ce10cdbfbd76081fff211c4b5067 (patch) | |
tree | 94800cef6eed6bae27acfa62e8687b89eef06e25 | |
parent | 295b97b2a654e00ac5a8e6a3545284fa583fce78 (diff) |
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
-rw-r--r-- | sw/CppunitTest_sw_uiwriter.mk | 1 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/data/shape-textbox-delete.odt | bin | 0 -> 10723 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 22 | ||||
-rw-r--r-- | sw/source/core/draw/dview.cxx | 18 |
4 files changed, 41 insertions, 0 deletions
diff --git a/sw/CppunitTest_sw_uiwriter.mk b/sw/CppunitTest_sw_uiwriter.mk index 7bfa0eaff9c9..4ddff3a188b0 100644 --- a/sw/CppunitTest_sw_uiwriter.mk +++ b/sw/CppunitTest_sw_uiwriter.mk @@ -21,6 +21,7 @@ $(eval $(call gb_CppunitTest_use_libraries,sw_uiwriter, \ cppuhelper \ sal \ svt \ + svxcore \ sw \ test \ unotest \ diff --git a/sw/qa/extras/uiwriter/data/shape-textbox-delete.odt b/sw/qa/extras/uiwriter/data/shape-textbox-delete.odt Binary files differnew file mode 100644 index 000000000000..0fe0e9b9cb89 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/shape-textbox-delete.odt diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 11fa7dfc798e..7fd4a7012f2c 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -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(); diff --git a/sw/source/core/draw/dview.cxx b/sw/source/core/draw/dview.cxx index 944634350cdb..299d244c8eab 100644 --- a/sw/source/core/draw/dview.cxx +++ b/sw/source/core/draw/dview.cxx @@ -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 ) |