summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2014-04-17 15:25:23 +0200
committerCaolán McNamara <caolanm@redhat.com>2014-04-24 14:15:37 +0000
commit18fe7ba3b0e2c502f275a0d7be09147cc7fc866a (patch)
tree823861bb09deb8e82fdb21c92e1c737f2052d946
parent527d8d77ac0ef3954bee54cf3e7bedb3302b0517 (diff)
fdo#77342: sw: fix copy/paste of footnote cross references
The fix for sequence fields broke the footnote references some more; simplify it by handling the footnotes in the same way as the sequence fields, and not remapping GetExp fields for which the corresponding SetExp field / footnote is missing. Also, don't do any remapping when the target is a clipboard document, to prevent modifying the source document. (regression from bb665affbd8870652ade3951d626d76e99143f67) (cherry picked from commit cbfcb837fb06a14daf5281ae13fc1886328cee6f) Conflicts: sw/source/core/fields/reffld.cxx Change-Id: If1be1e1d9742182a4085bbbff53e26a8fa8665b8 Reviewed-on: https://gerrit.libreoffice.org/9085 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> (cherry picked from commit e8252361548e3ca7849ced1a31d90fa5e5aacb09) Reviewed-on: https://gerrit.libreoffice.org/9086 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r--sw/source/core/fields/reffld.cxx72
1 files changed, 34 insertions, 38 deletions
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx
index e20accbeb30e..9fbd6cd4d435 100644
--- a/sw/source/core/fields/reffld.cxx
+++ b/sw/source/core/fields/reffld.cxx
@@ -1009,6 +1009,17 @@ void _RefIdsMap::Init( SwDoc& rDoc, SwDoc& rDestDoc, bool bField )
{
GetNoteIdsFromDoc( rDestDoc, aIds );
GetNoteIdsFromDoc( rDoc, aDstIds );
+
+ for (std::set<sal_uInt16>::iterator pIt = aDstIds.begin(); pIt != aDstIds.end(); ++pIt)
+ AddId( GetFirstUnusedId(aIds), *pIt );
+
+ // Change the footnotes/endnotes in the source doc to the new ID
+ for (sal_uInt16 i = 0, nCnt = rDoc.GetFtnIdxs().size(); i < nCnt; ++i)
+ {
+ SwTxtFtn *const pFtnIdx = rDoc.GetFtnIdxs()[i];
+ sal_uInt16 const n = pFtnIdx->GetSeqRefNo();
+ pFtnIdx->SetSeqNo(sequencedIds[n]);
+ }
}
bInit = true;
}
@@ -1046,53 +1057,38 @@ void _RefIdsMap::Check( SwDoc& rDoc, SwDoc& rDestDoc, SwGetRefField& rFld,
{
Init( rDoc, rDestDoc, bField);
- sal_uInt16 nSeqNo = rFld.GetSeqNo();
-
- // Check if the number is used in both documents
- // Note: For fields, aIds contains both the ids of SetExp from rDestDoc
- // and the targets of the already remapped ones from rDoc.
- // It is possible that aDstIds contains numbers that aIds does not contain!
- // For example, copying a selection to clipboard that does not contain
- // the first SwSetExpField will result in id 0 missing, then pasting that
- // into empty document gives a mapping 1->0 ... N->N-1 (fdo#63553).
- if (aIds.count(nSeqNo) || aDstIds.count(nSeqNo))
- {
- // Number already taken, so need a new one.
- if( sequencedIds.count(nSeqNo) )
- rFld.SetSeqNo( sequencedIds[nSeqNo] );
- else
- {
- assert(!bField || !aDstIds.count(nSeqNo)); // postcond of Init
-
- sal_uInt16 n = GetFirstUnusedId( aIds );
-
- // die neue SeqNo eintragen, damit die "belegt" ist
- AddId( n, nSeqNo );
- rFld.SetSeqNo( n );
+ sal_uInt16 const nSeqNo = rFld.GetSeqNo();
- // und noch die Fuss-/EndNote auf die neue Id umsetzen
- if( !bField )
- {
- SwTxtFtn* pFtnIdx;
- for( sal_uInt16 i = 0, nCnt = rDoc.GetFtnIdxs().size(); i < nCnt; ++i )
- if( nSeqNo == (pFtnIdx = rDoc.GetFtnIdxs()[ i ])->GetSeqRefNo() )
- {
- pFtnIdx->SetSeqNo( n );
- break;
- }
- }
- }
- }
- else
+ // check if it needs to be remapped
+ // if sequencedIds doesn't contain the number, it means there is no
+ // SetExp field / footnote in the source document: do not modify
+ // the number, which works well for copy from/paste to same document
+ // (and if it is not the same document, there's no "correct" result anyway)
+ if (sequencedIds.count(nSeqNo))
{
- AddId( nSeqNo, nSeqNo ); // this requires that nSeqNo is unused in both!
+ rFld.SetSeqNo( sequencedIds[nSeqNo] );
}
}
+/// 1. if _both_ SetExp + GetExp / Footnote + GetExp field are copied,
+/// enusure that both get a new unused matching number
+/// 2. if only SetExp / Footnote is copied, it gets a new unused number
+/// 3. if only GetExp field is copied, for the case of copy from / paste to
+/// same document it's desirable to keep the same number;
+/// for other cases of copy/paste or master documents it's not obvious
+/// what is most desirable since it's going to be wrong anyway
void SwGetRefFieldType::MergeWithOtherDoc( SwDoc& rDestDoc )
{
if( &rDestDoc != pDoc )
{
+ if (rDestDoc.IsClipBoard())
+ {
+ // when copying _to_ clipboard, expectation is that no fields exist
+ // so no re-mapping is required to avoid collisions
+ assert(!rDestDoc.GetSysFldType(RES_GETREFFLD)->GetDepends());
+ return; // don't modify the fields in the source doc
+ }
+
// then there are RefFields in the DescDox - so all RefFields in the SourceDoc
// need to be converted to have unique IDs for both documents
_RefIdsMap aFntMap( aEmptyOUStr );