tdf#113877 Insert doc: merge list into text with specifc style
When inserting document, in the current position the text could have custom
style but really it is the same Standard style. Therefore we should not
merge first inserted node into the insert position and just overwrite
style in the insert position with text style from the inserted node.
Change-Id: Ib67c56bed3d30f356f83dc0b4d4a1710def10853
Reviewed-on: https://gerrit.libreoffice.org/56052
Tested-by: Jenkins
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
diff --git a/sw/qa/extras/uiwriter/data/tdf113877_blank.odt b/sw/qa/extras/uiwriter/data/tdf113877_blank.odt
new file mode 100755
index 0000000..741d7d5
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf113877_blank.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/data/tdf113877_blank_ownStandard.odt b/sw/qa/extras/uiwriter/data/tdf113877_blank_ownStandard.odt
new file mode 100755
index 0000000..3dbebda
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf113877_blank_ownStandard.odt
Binary files differ
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
old mode 100644
new mode 100755
index d208604..e6ab7cd
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -302,6 +302,8 @@ public:
void testTdf72942();
void testTdf113877();
void testTdf113877NoMerge();
void testTdf113877_default_style();
void testTdf113877_Standard_style();
void testMsWordCompTrailingBlanks();
void testCreateDocxAnnotation();
void testTdf107976();
@@ -496,6 +498,8 @@ public:
CPPUNIT_TEST(testTdf72942);
CPPUNIT_TEST(testTdf113877);
CPPUNIT_TEST(testTdf113877NoMerge);
CPPUNIT_TEST(testTdf113877_default_style);
CPPUNIT_TEST(testTdf113877_Standard_style);
CPPUNIT_TEST(testMsWordCompTrailingBlanks);
CPPUNIT_TEST(testCreateDocxAnnotation);
CPPUNIT_TEST(testTdf107976);
@@ -5577,6 +5581,70 @@ void SwUiWriterTest::testTdf113877NoMerge()
CPPUNIT_ASSERT(listId6 != listId7);
}
// Related test to testTdf113877(): Inserting into empty document a new document with list.
// Insert position has NO its own paragraph style ("Standard" will be used).
//
// Resulting document should be the same for following tests:
// - testTdf113877_default_style()
// - testTdf113877_Standard_style()
//
void SwUiWriterTest::testTdf113877_default_style()
{
load(DATA_DIRECTORY, "tdf113877_blank.odt");
// set a page cursor into the end of the document
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
xCursor->jumpToEndOfPage();
// insert the same document at current cursor position
{
const OUString insertFileid = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf113877_insert_numbered_list_abcd.odt";
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({ { "Name", uno::makeAny(insertFileid) } }));
lcl_dispatchCommand(mxComponent, ".uno:InsertDoc", aPropertyValues);
}
const OUString listId1 = getProperty<OUString>(getParagraph(1), "ListId");
const OUString listId2 = getProperty<OUString>(getParagraph(2), "ListId");
const OUString listId3 = getProperty<OUString>(getParagraph(3), "ListId");
CPPUNIT_ASSERT_EQUAL(listId1, listId2);
CPPUNIT_ASSERT_EQUAL(listId1, listId3);
}
// Related test to testTdf113877(): Inserting into empty document a new document with list.
// Insert position has its own paragraph style derived from "Standard", but this style is the same as "Standard".
//
// Resulting document should be the same for following tests:
// - testTdf113877_default_style()
// - testTdf113877_Standard_style()
//
void SwUiWriterTest::testTdf113877_Standard_style()
{
load(DATA_DIRECTORY, "tdf113877_blank_ownStandard.odt");
// set a page cursor into the end of the document
uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY);
uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY);
xCursor->jumpToEndOfPage();
// insert the same document at current cursor position
{
const OUString insertFileid = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf113877_insert_numbered_list_abcd.odt";
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({ { "Name", uno::makeAny(insertFileid) } }));
lcl_dispatchCommand(mxComponent, ".uno:InsertDoc", aPropertyValues);
}
const OUString listId1 = getProperty<OUString>(getParagraph(1), "ListId");
const OUString listId2 = getProperty<OUString>(getParagraph(2), "ListId");
const OUString listId3 = getProperty<OUString>(getParagraph(3), "ListId");
CPPUNIT_ASSERT_EQUAL(listId1, listId2);
CPPUNIT_ASSERT_EQUAL(listId1, listId3);
}
void SwUiWriterTest::testTdf108524()
{
createDoc("tdf108524.odt");
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
old mode 100644
new mode 100755
index ed08bd9..e8106bb
--- a/sw/source/core/txtnode/ndtxt.cxx
+++ b/sw/source/core/txtnode/ndtxt.cxx
@@ -2131,8 +2131,49 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart,
// copy hard attributes on whole paragraph
if (HasSwAttrSet())
{
bool hasSwAttrSet = pDest->HasSwAttrSet();
if (hasSwAttrSet)
{
// if we have our own property set it doesn't mean
// that this set defines any style different to Standard one.
hasSwAttrSet = false;
// so, let's check deeper if property set has defined any property
if (pDest->GetpSwAttrSet())
{
// check all items in the property set
SfxItemIter aIter( *pDest->GetpSwAttrSet() );
const SfxPoolItem* pItem = aIter.GetCurItem();
while( true )
{
// check current item
sal_uInt16 nWhich = IsInvalidItem( pItem )
? pDest->GetpSwAttrSet()->GetWhichByPos( aIter.GetCurPos() )
: pItem->Which();
if( RES_FRMATR_STYLE_NAME != nWhich &&
RES_FRMATR_CONDITIONAL_STYLE_NAME != nWhich &&
SfxItemState::SET == pDest->GetpSwAttrSet()->GetItemState( nWhich, false ) )
{
// check if parent value (original value in style) has the same value as in [pItem]
const SfxPoolItem& rParentItem = pDest->GetpSwAttrSet()->GetParent()->Get( nWhich, true );
hasSwAttrSet = (rParentItem != *pItem);
// property set is not empty => no need to make anymore checks
if (hasSwAttrSet)
break;
}
// let's check next item
if( aIter.IsAtEnd() )
break;
pItem = aIter.NextItem();
}
}
}
// all or just the Char attributes?
if( nInitSize || pDest->HasSwAttrSet() ||
if( nInitSize || hasSwAttrSet ||
nLen != pDest->GetText().getLength())
{
SfxItemSet aCharSet(