diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-04-17 15:25:23 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2014-04-17 15:30:10 +0200 |
commit | cbfcb837fb06a14daf5281ae13fc1886328cee6f (patch) | |
tree | 3171e96486943e54ee8f6aa913c7f46275168dd7 | |
parent | 5550ce08310a852ae24849a84dc53dc6b87bc4ec (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)
Change-Id: If1be1e1d9742182a4085bbbff53e26a8fa8665b8
-rw-r--r-- | sw/source/core/fields/reffld.cxx | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/sw/source/core/fields/reffld.cxx b/sw/source/core/fields/reffld.cxx index b9faba3f548d..ad19f9fbd76c 100644 --- a/sw/source/core/fields/reffld.cxx +++ b/sw/source/core/fields/reffld.cxx @@ -1013,6 +1013,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; } @@ -1050,53 +1061,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 ); - - // register the new SeqNo, so that it's "in use" - AddId( n, nSeqNo ); - rFld.SetSeqNo( n ); + sal_uInt16 const nSeqNo = rFld.GetSeqNo(); - // and move the footnotes/endnotes to the new ID - 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 ); |