From 0e190fa2b480ec155f9808de4bb378731dc1154f Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Sun, 6 Mar 2011 09:09:42 +0000 Subject: [PATCH] Fixed #13017: wxRichTextCtrl CopyToClipboard regression git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67132 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/richtext/richtextbuffer.cpp | 52 ++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 85c67e3122..207a8899b1 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -2637,49 +2637,61 @@ bool wxRichTextParagraphLayoutBox::CopyFragment(const wxRichTextRange& range, wx // Now top and tail the first and last paragraphs in our new fragment (which might be the same). if (!fragment.IsEmpty()) { - wxRichTextRange topTailRange(range); - wxRichTextParagraph* firstPara = wxDynamicCast(fragment.GetChildren().GetFirst()->GetData(), wxRichTextParagraph); wxASSERT( firstPara != NULL ); + wxRichTextParagraph* lastPara = wxDynamicCast(fragment.GetChildren().GetLast()->GetData(), wxRichTextParagraph); + wxASSERT( lastPara != NULL ); + + if (!firstPara || !lastPara) + return false; + + bool isFragment = (range.GetEnd() < lastPara->GetRange().GetEnd()); + + long firstPos = firstPara->GetRange().GetStart(); + + // Adjust for renumbering from zero + wxRichTextRange topTailRange(range.GetStart() - firstPos, range.GetEnd() - firstPos); + + long end; + fragment.CalculateRange(0, end); + // Chop off the start of the paragraph - if (topTailRange.GetStart() > firstPara->GetRange().GetStart()) + if (topTailRange.GetStart() > 0) { - wxRichTextRange r(firstPara->GetRange().GetStart(), topTailRange.GetStart()-1); + wxRichTextRange r(0, topTailRange.GetStart()-1); firstPara->DeleteRange(r); // Make sure the numbering is correct - long end; - fragment.CalculateRange(firstPara->GetRange().GetStart(), end); + fragment.CalculateRange(0, end); // Now, we've deleted some positions, so adjust the range // accordingly. - topTailRange.SetEnd(topTailRange.GetEnd() - r.GetLength()); + topTailRange.SetStart(range.GetLength()); + topTailRange.SetEnd(fragment.GetOwnRange().GetEnd()); + } + else + { + topTailRange.SetStart(range.GetLength()); + topTailRange.SetEnd(fragment.GetOwnRange().GetEnd()); } - wxRichTextParagraph* lastPara = wxDynamicCast(fragment.GetChildren().GetLast()->GetData(), wxRichTextParagraph); - wxASSERT( lastPara != NULL ); - - if (topTailRange.GetEnd() < (lastPara->GetRange().GetEnd()-1)) + if (topTailRange.GetStart() < (lastPara->GetRange().GetEnd()-1)) { - wxRichTextRange r(topTailRange.GetEnd()+1, lastPara->GetRange().GetEnd()-1); /* -1 since actual text ends 1 position before end of para marker */ - lastPara->DeleteRange(r); + lastPara->DeleteRange(topTailRange); // Make sure the numbering is correct long end; - fragment.CalculateRange(firstPara->GetRange().GetStart(), end); + fragment.CalculateRange(0, end); // We only have part of a paragraph at the end fragment.SetPartialParagraph(true); } else { - if (topTailRange.GetEnd() == (lastPara->GetRange().GetEnd() - 1)) - // We have a partial paragraph (don't save last new paragraph marker) - fragment.SetPartialParagraph(true); - else - // We have a complete paragraph - fragment.SetPartialParagraph(false); + // We have a partial paragraph (don't save last new paragraph marker) + // or complete paragraph + fragment.SetPartialParagraph(isFragment); } } -- 2.45.2