summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2015-12-03 23:18:16 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2016-01-11 09:09:43 +0000
commitcce1320efa93cc42300e457b898d892ca580ddca (patch)
tree20a86a0968c93049f2cf5cf1f8c29d65fb11144a
parent107664a977c4893a0bc02f10cd20411c330b6d94 (diff)
tdf#92623 Handle StartOfContent node for copying bookmarks
For SwDoc::AppendDoc we use the StartOfContent node as the starting copy node to prevent merging of the first node in CopyRange and to get a 2nd node needed for CopyRange in case of single content node documents. This correctly counts StartOfContent as a non-copy node when adapting the bookmark ranges for copying. Change-Id: Ia3ee0328a1be5548f8751aa2240812c4662fb73f Reviewed-on: https://gerrit.libreoffice.org/20383 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> (cherry picked from commit 689962feae2054f965a7378c3408b0ccfad2bbd5) tdf#92623 MM: add unit test Adds the missing unit test to the bugfix. Actually the original bug was a crash, so this just does some test on the resulting MM document. Change-Id: I4c9f031e57157fe5744aa8290b7503b7e1990fc7 (cherry picked from commit 480e943f0100154fa82942db092ed1f66b76ef66) Reviewed-on: https://gerrit.libreoffice.org/21076 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Miklos Vajna <vmiklos@collabora.co.uk> (cherry picked from commit bdcafdff89836518cb94f362ca7ea4c09a82fa03) Reviewed-on: https://gerrit.libreoffice.org/21138 Tested-by: Jenkins <ci@libreoffice.org>
-rw-r--r--sw/qa/extras/mailmerge/data/tdf92623.odtbin0 -> 12615 bytes
-rw-r--r--sw/qa/extras/mailmerge/mailmerge.cxx51
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx10
3 files changed, 60 insertions, 1 deletions
diff --git a/sw/qa/extras/mailmerge/data/tdf92623.odt b/sw/qa/extras/mailmerge/data/tdf92623.odt
new file mode 100644
index 000000000000..3dea8317c533
--- /dev/null
+++ b/sw/qa/extras/mailmerge/data/tdf92623.odt
Binary files differ
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx
index 42d2385387a1..92fc7c314c10 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -412,5 +412,56 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf90230, "empty.odt", "10-testing-addresses.od
executeMailMerge();
}
+DECLARE_SHELL_MAILMERGE_TEST(testTdf92623, "tdf92623.odt", "10-testing-addresses.ods", "testing-addresses")
+{
+ // Copying bookmarks for MM was broken because of the StartOfContent node copy
+ // copyied marks were off by one
+ executeMailMerge();
+
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ IDocumentMarkAccess const *pIDMA = pTextDoc->GetDocShell()->GetDoc()->getIDocumentMarkAccess();
+ // There is just one mark...
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pIDMA->getAllMarksCount());
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pIDMA->getBookmarksCount());
+ IDocumentMarkAccess::const_iterator_t mark = pIDMA->getAllMarksBegin();
+ // and it's a TEXT_FIELDMARK
+ CPPUNIT_ASSERT_EQUAL( sal_Int32(IDocumentMarkAccess::GetType( **mark )),
+ sal_Int32(IDocumentMarkAccess::MarkType::TEXT_FIELDMARK ) );
+ sal_uLong src_pos = (*mark)->GetMarkPos().nNode.GetIndex();
+
+ // Get the size of the document in nodes
+ SwDoc *doc = pTextDoc->GetDocShell()->GetDoc();
+ sal_uLong size = doc->GetNodes().GetEndOfContent().GetIndex() - doc->GetNodes().GetEndOfExtras().GetIndex();
+ CPPUNIT_ASSERT_EQUAL( sal_uLong(13), size );
+ size -= 2; // For common start and end nodes
+
+ // Iterate over all field marks in the target document and check that they
+ // are positioned at a multitude of the document size
+ SwXTextDocument* pMMTextDoc = dynamic_cast<SwXTextDocument *>(mxMMComponent.get());
+ CPPUNIT_ASSERT(pMMTextDoc);
+ pIDMA = pMMTextDoc->GetDocShell()->GetDoc()->getIDocumentMarkAccess();
+ // The target document has the duplicated amount of bookmarks
+ // as the helping uno bookmark from the mail merge is left in the doc
+ // TODO should be fixed!
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(20), pIDMA->getAllMarksCount());
+ std::set<sal_uLong> pages;
+ sal_Int32 countFieldMarks = 0;
+ for( mark = pIDMA->getAllMarksBegin(); mark != pIDMA->getAllMarksEnd(); ++mark )
+ {
+ IDocumentMarkAccess::MarkType markType = IDocumentMarkAccess::GetType( **mark );
+ if( markType == IDocumentMarkAccess::MarkType::TEXT_FIELDMARK )
+ {
+ sal_uLong pos = (*mark)->GetMarkPos().nNode.GetIndex() - src_pos;
+ CPPUNIT_ASSERT_EQUAL(sal_uLong(0), pos % size);
+ CPPUNIT_ASSERT(pages.insert(pos).second);
+ countFieldMarks++;
+ }
+ else // see previous TODO
+ CPPUNIT_ASSERT_EQUAL( sal_Int32(markType), sal_Int32(IDocumentMarkAccess::MarkType::UNO_BOOKMARK) );
+ }
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(10), countFieldMarks);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 77228f05caa3..ec56feef5731 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -122,7 +122,8 @@ namespace
/*
The lcl_CopyBookmarks function has to copy bookmarks from the source to the destination nodes
array. It is called after a call of the _CopyNodes(..) function. But this function does not copy
- every node (at least at the moment: 2/08/2006 ), section start and end nodes will not be copied if the corresponding end/start node is outside the copied pam.
+ every node (at least at the moment: 2/08/2006 ), section start and end nodes will not be copied
+ if the corresponding end/start node is outside the copied pam.
The lcl_NonCopyCount function counts the number of these nodes, given the copied pam and a node
index inside the pam.
rPam is the original source pam, rLastIdx is the last calculated position, rDelCount the number
@@ -136,6 +137,13 @@ namespace
sal_uLong nEnd = rPam.End()->nNode.GetIndex();
if( rLastIdx.GetIndex() < nNewIdx ) // Moving forward?
{
+ // We never copy the StartOfContent node
+ // Special handling for SwDoc::AppendDoc
+ if( rPam.GetDoc()->GetNodes().GetEndOfExtras().GetIndex() + 1 == nStart )
+ {
+ ++rDelCount;
+ ++rLastIdx;
+ }
do // count "non-copy" nodes
{
SwNode& rNode = rLastIdx.GetNode();