X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d65381ac3415e9be42a378511e91755eb114b72b..109bfc88a4a8583cc2fd5ca3fa6dbd74f5c7274c:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 38de2d611a..7890fe7b42 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -48,6 +48,9 @@ WX_DEFINE_LIST(wxRichTextLineList) // Switch off if the platform doesn't like it for some reason #define wxRICHTEXT_USE_OPTIMIZED_DRAWING 1 +// Use GetPartialTextExtents for platforms that support it natively +#define wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS 1 + const wxChar wxRichTextLineBreakChar = (wxChar) 29; // Helpers for efficiency @@ -61,6 +64,7 @@ inline void wxCheckSetFont(wxDC& dc, const wxFont& font) font1.GetFamily() == font.GetFamily() && font1.GetStyle() == font.GetStyle() && font1.GetWeight() == font.GetWeight() && + font1.GetUnderlined() == font.GetUnderlined() && font1.GetFaceName() == font.GetFaceName()) return; } @@ -308,7 +312,8 @@ int wxRichTextCompositeObject::HitTest(wxDC& dc, const wxPoint& pt, long& textPo node = node->GetNext(); } - return wxRICHTEXT_HITTEST_NONE; + textPosition = GetRange().GetEnd()-1; + return wxRICHTEXT_HITTEST_AFTER|wxRICHTEXT_HITTEST_OUTSIDE; } /// Finds the absolute position and row height for the given character position @@ -420,26 +425,31 @@ wxString wxRichTextCompositeObject::GetTextForRange(const wxRichTextRange& range } /// Recursively merge all pieces that can be merged. -bool wxRichTextCompositeObject::Defragment() +bool wxRichTextCompositeObject::Defragment(const wxRichTextRange& range) { wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); while (node) { wxRichTextObject* child = node->GetData(); - wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject); - if (composite) - composite->Defragment(); - - if (node->GetNext()) + if (!child->GetRange().IsOutside(range)) { - wxRichTextObject* nextChild = node->GetNext()->GetData(); - if (child->CanMerge(nextChild) && child->Merge(nextChild)) + wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject); + if (composite) + composite->Defragment(); + + if (node->GetNext()) { - nextChild->Dereference(); - m_children.Erase(node->GetNext()); + wxRichTextObject* nextChild = node->GetNext()->GetData(); + if (child->CanMerge(nextChild) && child->Merge(nextChild)) + { + nextChild->Dereference(); + m_children.Erase(node->GetNext()); - // Don't set node -- we'll see if we can merge again with the next - // child. + // Don't set node -- we'll see if we can merge again with the next + // child. + } + else + node = node->GetNext(); } else node = node->GetNext(); @@ -508,13 +518,13 @@ bool wxRichTextBox::Layout(wxDC& dc, const wxRect& rect, int style) } /// Get/set the size for the given range. Assume only has one child. -bool wxRichTextBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position) const +bool wxRichTextBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position, wxArrayInt* partialExtents) const { wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); if (node) { wxRichTextObject* child = node->GetData(); - return child->GetRangeSize(range, size, descent, dc, flags, position); + return child->GetRangeSize(range, size, descent, dc, flags, position, partialExtents); } else return false; @@ -739,7 +749,7 @@ void wxRichTextParagraphLayoutBox::Copy(const wxRichTextParagraphLayoutBox& obj) } /// Get/set the size for the given range. -bool wxRichTextParagraphLayoutBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position) const +bool wxRichTextParagraphLayoutBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position, wxArrayInt* WXUNUSED(partialExtents)) const { wxSize sz; @@ -958,7 +968,17 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraph(const wxString& text, wxTextAttr defaultCharStyle; wxTextAttr defaultParaStyle; - wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); + // If the default style is a named paragraph style, don't apply any character formatting + // to the initial text string. + if (GetDefaultStyle().HasParagraphStyleName() && GetStyleSheet()) + { + wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(GetDefaultStyle().GetParagraphStyleName()); + if (def) + defaultParaStyle = def->GetStyleMergedWithBase(GetStyleSheet()); + } + else + wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); + wxTextAttr* pStyle = paraStyle ? paraStyle : (wxTextAttr*) & defaultParaStyle; wxTextAttr* cStyle = & defaultCharStyle; @@ -981,7 +1001,17 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text wxTextAttr defaultCharStyle; wxTextAttr defaultParaStyle; - wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); + + // If the default style is a named paragraph style, don't apply any character formatting + // to the initial text string. + if (GetDefaultStyle().HasParagraphStyleName() && GetStyleSheet()) + { + wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(GetDefaultStyle().GetParagraphStyleName()); + if (def) + defaultParaStyle = def->GetStyleMergedWithBase(GetStyleSheet()); + } + else + wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); wxTextAttr* pStyle = paraStyle ? paraStyle : (wxTextAttr*) & defaultParaStyle; wxTextAttr* cStyle = & defaultCharStyle; @@ -1006,15 +1036,18 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text wxChar ch = text[i]; if (ch == wxT('\n') || ch == wxT('\r')) { - wxRichTextPlainText* plainText = (wxRichTextPlainText*) para->GetChildren().GetFirst()->GetData(); - plainText->SetText(line); + if (i != (len-1)) + { + wxRichTextPlainText* plainText = (wxRichTextPlainText*) para->GetChildren().GetFirst()->GetData(); + plainText->SetText(line); - para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle); + para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle); - AppendChild(para); + AppendChild(para); - lastPara = para; - line = wxEmptyString; + lastPara = para; + line = wxEmptyString; + } } else line += ch; @@ -1044,7 +1077,17 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddImage(const wxImage& image, wxT wxTextAttr defaultCharStyle; wxTextAttr defaultParaStyle; - wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); + + // If the default style is a named paragraph style, don't apply any character formatting + // to the initial text string. + if (GetDefaultStyle().HasParagraphStyleName() && GetStyleSheet()) + { + wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(GetDefaultStyle().GetParagraphStyleName()); + if (def) + defaultParaStyle = def->GetStyleMergedWithBase(GetStyleSheet()); + } + else + wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle); wxTextAttr* pStyle = paraStyle ? paraStyle : (wxTextAttr*) & defaultParaStyle; wxTextAttr* cStyle = & defaultCharStyle; @@ -1072,6 +1115,8 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag wxRichTextParagraph* para = GetParagraphAtPosition(position); if (para) { + wxTextAttrEx originalAttr = para->GetAttributes(); + wxRichTextObjectList::compatibility_iterator node = m_children.Find(para); // Now split at this position, returning the object to insert the new @@ -1092,11 +1137,6 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag wxRichTextParagraph* firstPara = wxDynamicCast(firstParaNode->GetData(), wxRichTextParagraph); wxASSERT (firstPara != NULL); - // Apply the new paragraph attributes to the existing paragraph - wxTextAttr attr(para->GetAttributes()); - wxRichTextApplyStyle(attr, firstPara->GetAttributes()); - para->SetAttributes(attr); - wxRichTextObjectList::compatibility_iterator objectNode = firstPara->GetChildren().GetFirst(); while (objectNode) { @@ -1144,7 +1184,19 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag wxRichTextParagraph* firstPara = wxDynamicCast(firstParaNode->GetData(), wxRichTextParagraph); wxASSERT(firstPara != NULL); + if (!(fragment.GetAttributes().GetFlags() & wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE)) + para->SetAttributes(firstPara->GetAttributes()); + + // Save empty paragraph attributes for appending later + // These are character attributes deliberately set for a new paragraph. Without this, + // we couldn't pass default attributes when appending a new paragraph. + wxTextAttrEx emptyParagraphAttributes; + wxRichTextObjectList::compatibility_iterator objectNode = firstPara->GetChildren().GetFirst(); + + if (objectNode && firstPara->GetChildren().GetCount() == 1 && objectNode->GetData()->IsEmpty()) + emptyParagraphAttributes = objectNode->GetData()->GetAttributes(); + while (objectNode) { wxRichTextObject* newObj = objectNode->GetData()->Clone(); @@ -1164,50 +1216,57 @@ bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParag wxRichTextObjectList::compatibility_iterator i = fragment.GetChildren().GetFirst()->GetNext(); wxRichTextParagraph* finalPara = para; + bool needExtraPara = (!i || !fragment.GetPartialParagraph()); + // If there was only one paragraph, we need to insert a new one. - if (!i) + while (i) { - finalPara = new wxRichTextParagraph; + wxRichTextParagraph* para = wxDynamicCast(i->GetData(), wxRichTextParagraph); + wxASSERT( para != NULL ); - // TODO: These attributes should come from the subsequent paragraph - // when originally deleted, since the subsequent para takes on - // the previous para's attributes. - finalPara->SetAttributes(firstPara->GetAttributes()); + finalPara = (wxRichTextParagraph*) para->Clone(); if (nextParagraph) InsertChild(finalPara, nextParagraph); else AppendChild(finalPara); + + i = i->GetNext(); } - else while (i) - { - wxRichTextParagraph* para = wxDynamicCast(i->GetData(), wxRichTextParagraph); - wxASSERT( para != NULL ); - finalPara = (wxRichTextParagraph*) para->Clone(); + // If there was only one paragraph, or we have full paragraphs in our fragment, + // we need to insert a new one. + if (needExtraPara) + { + finalPara = new wxRichTextParagraph; if (nextParagraph) InsertChild(finalPara, nextParagraph); else AppendChild(finalPara); - - i = i->GetNext(); } // 4. Add back the remaining content. if (finalPara) { - finalPara->MoveFromList(savedObjects); + if (nextObject) + finalPara->MoveFromList(savedObjects); // Ensure there's at least one object if (finalPara->GetChildCount() == 0) { wxRichTextPlainText* text = new wxRichTextPlainText(wxEmptyString); + text->SetAttributes(emptyParagraphAttributes); finalPara->AppendChild(text); } } + if ((fragment.GetAttributes().GetFlags() & wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE) && firstPara) + finalPara->SetAttributes(firstPara->GetAttributes()); + else if (finalPara && finalPara != para) + finalPara->SetAttributes(originalAttr); + return true; } } @@ -1391,6 +1450,7 @@ bool wxRichTextParagraphLayoutBox::DeleteRange(const wxRichTextRange& range) { wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); + wxRichTextParagraph* firstPara = NULL; while (node) { wxRichTextParagraph* obj = wxDynamicCast(node->GetData(), wxRichTextParagraph); @@ -1405,58 +1465,82 @@ bool wxRichTextParagraphLayoutBox::DeleteRange(const wxRichTextRange& range) // Deletes the content of this object within the given range obj->DeleteRange(range); + wxRichTextRange thisRange = obj->GetRange(); + wxTextAttrEx thisAttr = obj->GetAttributes(); + // If the whole paragraph is within the range to delete, // delete the whole thing. - if (range.GetStart() <= obj->GetRange().GetStart() && range.GetEnd() >= obj->GetRange().GetEnd()) + if (range.GetStart() <= thisRange.GetStart() && range.GetEnd() >= thisRange.GetEnd()) { // Delete the whole object RemoveChild(obj, true); + obj = NULL; } + else if (!firstPara) + firstPara = obj; + // If the range includes the paragraph end, we need to join this // and the next paragraph. - else if (range.Contains(obj->GetRange().GetEnd())) + if (range.GetEnd() <= thisRange.GetEnd()) { // We need to move the objects from the next paragraph // to this paragraph - if (next) + wxRichTextParagraph* nextParagraph = NULL; + if ((range.GetEnd() < thisRange.GetEnd()) && obj) + nextParagraph = obj; + else { - wxRichTextParagraph* nextParagraph = wxDynamicCast(next->GetData(), wxRichTextParagraph); - next = next->GetNext(); - if (nextParagraph) - { - // Delete the stuff we need to delete - nextParagraph->DeleteRange(range); + // We're ending at the end of the paragraph, so merge the _next_ paragraph. + if (next) + nextParagraph = wxDynamicCast(next->GetData(), wxRichTextParagraph); + } - // Move the objects to the previous para - wxRichTextObjectList::compatibility_iterator node1 = nextParagraph->GetChildren().GetFirst(); + bool applyFinalParagraphStyle = firstPara && nextParagraph && nextParagraph != firstPara; - while (node1) - { - wxRichTextObject* obj1 = node1->GetData(); + wxTextAttrEx nextParaAttr; + if (applyFinalParagraphStyle) + { + // Special case when deleting the end of a paragraph - use _this_ paragraph's style, + // not the next one. + if (range.GetStart() == range.GetEnd() && range.GetStart() == thisRange.GetEnd()) + nextParaAttr = thisAttr; + else + nextParaAttr = nextParagraph->GetAttributes(); + } - // If the object is empty, optimise it out - if (obj1->IsEmpty()) - { - delete obj1; - } - else - { - obj->AppendChild(obj1); - } + if (firstPara && nextParagraph && firstPara != nextParagraph) + { + // Move the objects to the previous para + wxRichTextObjectList::compatibility_iterator node1 = nextParagraph->GetChildren().GetFirst(); - wxRichTextObjectList::compatibility_iterator next1 = node1->GetNext(); - nextParagraph->GetChildren().Erase(node1); + while (node1) + { + wxRichTextObject* obj1 = node1->GetData(); - node1 = next1; - } + firstPara->AppendChild(obj1); - // Delete the paragraph - RemoveChild(nextParagraph, true); + wxRichTextObjectList::compatibility_iterator next1 = node1->GetNext(); + nextParagraph->GetChildren().Erase(node1); + node1 = next1; } + + // Delete the paragraph + RemoveChild(nextParagraph, true); + } + + // Avoid empty paragraphs + if (firstPara && firstPara->GetChildren().GetCount() == 0) + { + wxRichTextPlainText* text = new wxRichTextPlainText(wxEmptyString); + firstPara->AppendChild(text); } + if (applyFinalParagraphStyle) + firstPara->SetAttributes(nextParaAttr); + + return true; } } @@ -1732,7 +1816,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const splitPoint ++; // Find last object - if (splitPoint == newPara->GetRange().GetEnd() || splitPoint == (newPara->GetRange().GetEnd() - 1)) + if (splitPoint == newPara->GetRange().GetEnd()) lastObject = newPara->GetChildren().GetLast()->GetData(); else // lastObject is set as a side-effect of splitting. It's @@ -2418,6 +2502,15 @@ void wxRichTextParagraphLayoutBox::Reset() { Clear(); + wxRichTextBuffer* buffer = wxDynamicCast(this, wxRichTextBuffer); + if (buffer && GetRichTextCtrl()) + { + wxRichTextEvent event(wxEVT_COMMAND_RICHTEXT_BUFFER_RESET, GetRichTextCtrl()->GetId()); + event.SetEventObject(GetRichTextCtrl()); + + buffer->SendEvent(event, true); + } + AddParagraph(wxEmptyString); Invalidate(wxRICHTEXT_ALL); @@ -2473,6 +2566,29 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh int foundCount = 0; + wxRichTextAttr attr(GetBasicStyle()); + if (GetBasicStyle().HasParagraphStyleName()) + { + wxRichTextParagraphStyleDefinition* paraDef = styleSheet->FindParagraphStyle(GetBasicStyle().GetParagraphStyleName()); + if (paraDef) + { + attr.Apply(paraDef->GetStyleMergedWithBase(styleSheet)); + SetBasicStyle(attr); + foundCount ++; + } + } + + if (GetBasicStyle().HasCharacterStyleName()) + { + wxRichTextCharacterStyleDefinition* charDef = styleSheet->FindCharacterStyle(GetBasicStyle().GetCharacterStyleName()); + if (charDef) + { + attr.Apply(charDef->GetStyleMergedWithBase(styleSheet)); + SetBasicStyle(attr); + foundCount ++; + } + } + wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); while (node) { @@ -3077,6 +3193,8 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR // Loop through objects until we get to the one within range wxRichTextObjectList::compatibility_iterator node2 = m_children.GetFirst(); + + int i = 0; while (node2) { wxRichTextObject* child = node2->GetData(); @@ -3088,14 +3206,24 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR objectRange.LimitTo(lineRange); wxSize objectSize; - int descent = 0; - child->GetRangeSize(objectRange, objectSize, descent, dc, wxRICHTEXT_UNFORMATTED, objectPosition); +#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING && wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS + if (i < (int) line->GetObjectSizes().GetCount()) + { + objectSize.x = line->GetObjectSizes()[(size_t) i]; + } + else +#endif + { + int descent = 0; + child->GetRangeSize(objectRange, objectSize, descent, dc, wxRICHTEXT_UNFORMATTED, objectPosition); + } // Use the child object's width, but the whole line's height wxRect childRect(objectPosition, wxSize(objectSize.x, line->GetSize().y)); child->Draw(dc, objectRange, selectionRange, childRect, maxDescent, style); objectPosition.x += objectSize.x; + i ++; } else if (child->GetRange().GetStart() > lineRange.GetEnd()) // Can break out of inner loop now since we've passed this line's range @@ -3165,7 +3293,19 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) int lineCount = 0; - wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); + wxRichTextObjectList::compatibility_iterator node; + +#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS + wxUnusedVar(style); + wxArrayInt partialExtents; + + wxSize paraSize; + int paraDescent; + + // This calculates the partial text extents + GetRangeSize(GetRange(), paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_CACHE_SIZE, wxPoint(0,0), & partialExtents); +#else + node = m_children.GetFirst(); while (node) { wxRichTextObject* child = node->GetData(); @@ -3176,6 +3316,8 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) node = node->GetNext(); } +#endif + // Split up lines // We may need to go back to a previous child, in which case create the new line, @@ -3233,7 +3375,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) // Find a place to wrap. This may walk back to previous children, // for example if a word spans several objects. - if (!FindWrapPosition(wxRichTextRange(lastCompletedEndPos+1, child->GetRange().GetEnd()), dc, availableSpaceForText, wrapPosition)) + if (!FindWrapPosition(wxRichTextRange(lastCompletedEndPos+1, child->GetRange().GetEnd()), dc, availableSpaceForText, wrapPosition, & partialExtents)) { // If the function failed, just cut it off at the end of this child. wrapPosition = child->GetRange().GetEnd(); @@ -3344,6 +3486,48 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) m_dirty = false; +#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS +#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING + // Use the text extents to calculate the size of each fragment in each line + wxRichTextLineList::compatibility_iterator lineNode = m_cachedLines.GetFirst(); + while (lineNode) + { + wxRichTextLine* line = lineNode->GetData(); + wxRichTextRange lineRange = line->GetAbsoluteRange(); + + // Loop through objects until we get to the one within range + wxRichTextObjectList::compatibility_iterator node2 = m_children.GetFirst(); + + while (node2) + { + wxRichTextObject* child = node2->GetData(); + + if (!child->GetRange().IsOutside(lineRange)) + { + wxRichTextRange rangeToUse = lineRange; + rangeToUse.LimitTo(child->GetRange()); + + // Find the size of the child from the text extents, and store in an array + // for drawing later + int left = 0; + if (rangeToUse.GetStart() > GetRange().GetStart()) + left = partialExtents[(rangeToUse.GetStart()-1) - GetRange().GetStart()]; + int right = partialExtents[rangeToUse.GetEnd() - GetRange().GetStart()]; + int sz = right - left; + line->GetObjectSizes().Add(sz); + } + else if (child->GetRange().GetStart() > lineRange.GetEnd()) + // Can break out of inner loop now since we've passed this line's range + break; + + node2 = node2->GetNext(); + } + + lineNode = lineNode->GetNext(); + } +#endif +#endif + return true; } @@ -3460,7 +3644,7 @@ void wxRichTextParagraph::ClearLines() /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. -bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position) const +bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position, wxArrayInt* partialExtents) const { if (!range.IsWithin(GetRange())) return false; @@ -3472,9 +3656,17 @@ bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& siz wxSize sz; + wxArrayInt childExtents; + wxArrayInt* p; + if (partialExtents) + p = & childExtents; + else + p = NULL; + wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); while (node) { + wxRichTextObject* child = node->GetData(); if (!child->GetRange().IsOutside(range)) { @@ -3484,12 +3676,36 @@ bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& siz rangeToUse.LimitTo(child->GetRange()); int childDescent = 0; - if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, wxPoint(position.x + sz.x, position.y))) + if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, wxPoint(position.x + sz.x, position.y), p)) { sz.y = wxMax(sz.y, childSize.y); sz.x += childSize.x; descent = wxMax(descent, childDescent); + + if ((flags & wxRICHTEXT_CACHE_SIZE) && (rangeToUse == child->GetRange())) + { + child->SetCachedSize(childSize); + child->SetDescent(childDescent); + } + + if (partialExtents) + { + int lastSize; + if (partialExtents->GetCount() > 0) + lastSize = (*partialExtents)[partialExtents->GetCount()-1]; + else + lastSize = 0; + + size_t i; + for (i = 0; i < childExtents.GetCount(); i++) + { + partialExtents->Add(childExtents[i] + lastSize); + } + } } + + if (p) + p->Clear(); } node = node->GetNext(); @@ -3658,7 +3874,7 @@ int wxRichTextParagraph::HitTest(wxDC& dc, const wxPoint& pt, long& textPosition wxSize lineSize = line->GetSize(); wxRichTextRange lineRange = line->GetAbsoluteRange(); - if (pt.y >= linePos.y && pt.y <= linePos.y + lineSize.y) + if (pt.y <= linePos.y + lineSize.y) { if (pt.x < linePos.x) { @@ -3672,6 +3888,39 @@ int wxRichTextParagraph::HitTest(wxDC& dc, const wxPoint& pt, long& textPosition } else { +#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS + wxArrayInt partialExtents; + + wxSize paraSize; + int paraDescent; + + // This calculates the partial text extents + GetRangeSize(lineRange, paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED, wxPoint(0,0), & partialExtents); + + int lastX = linePos.x; + size_t i; + for (i = 0; i < partialExtents.GetCount(); i++) + { + int nextX = partialExtents[i] + linePos.x; + + if (pt.x >= lastX && pt.x <= nextX) + { + textPosition = i + lineRange.GetStart(); // minus 1? + + // So now we know it's between i-1 and i. + // Let's see if we can be more precise about + // which side of the position it's on. + + int midPoint = (nextX - lastX)/2 + lastX; + if (pt.x >= midPoint) + return wxRICHTEXT_HITTEST_AFTER; + else + return wxRICHTEXT_HITTEST_BEFORE; + } + + lastX = nextX; + } +#else long i; int lastX = linePos.x; for (i = lineRange.GetStart(); i <= lineRange.GetEnd(); i++) @@ -3704,6 +3953,7 @@ int wxRichTextParagraph::HitTest(wxDC& dc, const wxPoint& pt, long& textPosition lastX = nextX; } } +#endif } } @@ -3873,55 +4123,84 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex } /// Find a suitable wrap position. -bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition) +bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& dc, int availableSpace, long& wrapPosition, wxArrayInt* partialExtents) { + if (range.GetLength() <= 0) + return false; + // Find the first position where the line exceeds the available space. wxSize sz; long breakPosition = range.GetEnd(); - // Binary chop for speed - long minPos = range.GetStart(); - long maxPos = range.GetEnd(); - while (true) +#if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS + if (partialExtents && partialExtents->GetCount() >= (size_t) (GetRange().GetLength()-1)) // the final position in a paragraph is the newline { - if (minPos == maxPos) - { - int descent = 0; - GetRangeSize(wxRichTextRange(range.GetStart(), minPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); + int widthBefore; - if (sz.x > availableSpace) - breakPosition = minPos - 1; - break; - } - else if ((maxPos - minPos) == 1) + if (range.GetStart() > GetRange().GetStart()) + widthBefore = (*partialExtents)[range.GetStart() - GetRange().GetStart() - 1]; + else + widthBefore = 0; + + size_t i; + for (i = (size_t) range.GetStart(); i < (size_t) range.GetEnd(); i++) { - int descent = 0; - GetRangeSize(wxRichTextRange(range.GetStart(), minPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); + int widthFromStartOfThisRange = (*partialExtents)[i - GetRange().GetStart()] - widthBefore; - if (sz.x > availableSpace) - breakPosition = minPos - 1; - else + if (widthFromStartOfThisRange > availableSpace) { - GetRangeSize(wxRichTextRange(range.GetStart(), maxPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); - if (sz.x > availableSpace) - breakPosition = maxPos-1; + breakPosition = i-1; + break; } - break; } - else + } + else +#endif + { + // Binary chop for speed + long minPos = range.GetStart(); + long maxPos = range.GetEnd(); + while (true) { - long nextPos = minPos + ((maxPos - minPos) / 2); - - int descent = 0; - GetRangeSize(wxRichTextRange(range.GetStart(), nextPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); + if (minPos == maxPos) + { + int descent = 0; + GetRangeSize(wxRichTextRange(range.GetStart(), minPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); - if (sz.x > availableSpace) + if (sz.x > availableSpace) + breakPosition = minPos - 1; + break; + } + else if ((maxPos - minPos) == 1) { - maxPos = nextPos; + int descent = 0; + GetRangeSize(wxRichTextRange(range.GetStart(), minPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); + + if (sz.x > availableSpace) + breakPosition = minPos - 1; + else + { + GetRangeSize(wxRichTextRange(range.GetStart(), maxPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); + if (sz.x > availableSpace) + breakPosition = maxPos-1; + } + break; } else { - minPos = nextPos; + long nextPos = minPos + ((maxPos - minPos) / 2); + + int descent = 0; + GetRangeSize(wxRichTextRange(range.GetStart(), nextPos), sz, descent, dc, wxRICHTEXT_UNFORMATTED); + + if (sz.x > availableSpace) + { + maxPos = nextPos; + } + else + { + minPos = nextPos; + } } } } @@ -4146,12 +4425,18 @@ void wxRichTextLine::Init(wxRichTextParagraph* parent) m_pos = wxPoint(0, 0); m_size = wxSize(0, 0); m_descent = 0; +#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING + m_objectSizes.Clear(); +#endif } /// Copy void wxRichTextLine::Copy(const wxRichTextLine& obj) { m_range = obj.m_range; +#if wxRICHTEXT_USE_OPTIMIZED_LINE_DRAWING + m_objectSizes = obj.m_objectSizes; +#endif } /// Get the absolute object position @@ -4203,22 +4488,50 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR wxString str = m_text; wxString toRemove = wxRichTextLineBreakChar; str.Replace(toRemove, wxT(" ")); + if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) + str.MakeUpper(); long len = range.GetLength(); wxString stringChunk = str.Mid(range.GetStart() - offset, (size_t) len); - if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_CAPITALS)) - stringChunk.MakeUpper(); - - int charHeight = dc.GetCharHeight(); - - int x = rect.x; - int y = rect.y + (rect.height - charHeight - (descent - m_descent)); // Test for the optimized situations where all is selected, or none // is selected. - wxFont font(GetBuffer()->GetFontTable().FindFont(textAttr)); - wxCheckSetFont(dc, font); + wxFont textFont(GetBuffer()->GetFontTable().FindFont(textAttr)); + wxCheckSetFont(dc, textFont); + int charHeight = dc.GetCharHeight(); + + int x, y; + if ( textFont.Ok() ) + { + if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) ) + { + double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; + textFont.SetPointSize( static_cast(size) ); + x = rect.x; + y = rect.y; + wxCheckSetFont(dc, textFont); + } + else if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) + { + double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; + textFont.SetPointSize( static_cast(size) ); + x = rect.x; + int sub_height = static_cast( static_cast(charHeight) / wxSCRIPT_MUL_FACTOR); + y = rect.y + (rect.height - sub_height + (descent - m_descent)); + wxCheckSetFont(dc, textFont); + } + else + { + x = rect.x; + y = rect.y + (rect.height - charHeight - (descent - m_descent)); + } + } + else + { + x = rect.x; + y = rect.y + (rect.height - charHeight - (descent - m_descent)); + } // (a) All selected. if (selectionRange.GetStart() <= range.GetStart() && selectionRange.GetEnd() >= range.GetEnd()) @@ -4236,7 +4549,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR // (c) Part selected, part not // Let's draw unselected chunk, selected chunk, then unselected chunk. - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); // 1. Initial unselected chunk, if any, up until start of selection. if (selectionRange.GetStart() > range.GetStart() && selectionRange.GetStart() <= range.GetEnd()) @@ -4353,7 +4666,7 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con wxCheckSetBrush(dc, wxBrush(highlightColour)); wxCheckSetPen(dc, wxPen(highlightColour)); dc.SetTextForeground(highlightTextColour); - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); } else { @@ -4361,11 +4674,11 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con if (attr.HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) && attr.GetBackgroundColour().IsOk()) { - dc.SetBackgroundMode(wxSOLID); + dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID); dc.SetTextBackground(attr.GetBackgroundColour()); } else - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); } while (hasTabs) @@ -4459,7 +4772,7 @@ void wxRichTextPlainText::Copy(const wxRichTextPlainText& obj) /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. -bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int WXUNUSED(flags), wxPoint position) const +bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int WXUNUSED(flags), wxPoint position, wxArrayInt* partialExtents) const { if (!range.IsWithin(GetRange())) return false; @@ -4473,9 +4786,26 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz // of line breaks - and we don't need it, since we'll calculate size within // formatted text by doing it in chunks according to the line ranges + bool bScript(false); wxFont font(GetBuffer()->GetFontTable().FindFont(textAttr)); - wxCheckSetFont(dc, font); + if (font.Ok()) + { + if ( textAttr.HasTextEffects() && ( (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) + || (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) ) + { + wxFont textFont = font; + double size = static_cast(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR; + textFont.SetPointSize( static_cast(size) ); + wxCheckSetFont(dc, textFont); + bScript = true; + } + else + { + wxCheckSetFont(dc, font); + } + } + bool haveDescent = false; int startPos = range.GetStart() - GetRange().GetStart(); long len = range.GetLength(); @@ -4512,13 +4842,40 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz while (stringChunk.Find(wxT('\t')) >= 0) { + int absoluteWidth = 0; + // the string has a tab // break up the string at the Tab wxString stringFragment = stringChunk.BeforeFirst(wxT('\t')); stringChunk = stringChunk.AfterFirst(wxT('\t')); - dc.GetTextExtent(stringFragment, & w, & h); - width += w; - int absoluteWidth = width + position.x; + + if (partialExtents) + { + int oldWidth; + if (partialExtents->GetCount() > 0) + oldWidth = (*partialExtents)[partialExtents->GetCount()-1]; + else + oldWidth = 0; + + // Add these partial extents + wxArrayInt p; + dc.GetPartialTextExtents(stringFragment, p); + size_t j; + for (j = 0; j < p.GetCount(); j++) + partialExtents->Add(oldWidth + p[j]); + + if (partialExtents->GetCount() > 0) + absoluteWidth = (*partialExtents)[(*partialExtents).GetCount()-1] + position.x; + else + absoluteWidth = position.x; + } + else + { + dc.GetTextExtent(stringFragment, & w, & h); + width += w; + absoluteWidth = width + position.x; + haveDescent = true; + } bool notFound = true; for (int i = 0; i < tabCount && notFound; ++i) @@ -4538,13 +4895,58 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz notFound = false; width = nextTabPos - position.x; + + if (partialExtents) + partialExtents->Add(width); } } } } - dc.GetTextExtent(stringChunk, & w, & h, & descent); - width += w; - size = wxSize(width, dc.GetCharHeight()); + + if (!stringChunk.IsEmpty()) + { + if (partialExtents) + { + int oldWidth; + if (partialExtents->GetCount() > 0) + oldWidth = (*partialExtents)[partialExtents->GetCount()-1]; + else + oldWidth = 0; + + // Add these partial extents + wxArrayInt p; + dc.GetPartialTextExtents(stringChunk, p); + size_t j; + for (j = 0; j < p.GetCount(); j++) + partialExtents->Add(oldWidth + p[j]); + } + else + { + dc.GetTextExtent(stringChunk, & w, & h, & descent); + width += w; + haveDescent = true; + } + } + + if (partialExtents) + { + int charHeight = dc.GetCharHeight(); + if ((*partialExtents).GetCount() > 0) + w = (*partialExtents)[partialExtents->GetCount()-1]; + else + w = 0; + size = wxSize(w, charHeight); + } + else + { + size = wxSize(width, dc.GetCharHeight()); + } + + if (!haveDescent) + dc.GetTextExtent(wxT("X"), & w, & h, & descent); + + if ( bScript ) + dc.SetFont(font); return true; } @@ -4629,6 +5031,7 @@ bool wxRichTextPlainText::Merge(wxRichTextObject* object) if (textObject) { m_text += textObject->GetText(); + wxRichTextApplyStyle(m_attributes, textObject->GetAttributes()); return true; } else @@ -4761,21 +5164,14 @@ bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagr action->GetNewParagraphs() = paragraphs; - if (p) - { - wxRichTextObjectList::compatibility_iterator node = m_children.GetLast(); - while (node) - { - wxRichTextParagraph* obj = (wxRichTextParagraph*) node->GetData(); - obj->SetAttributes(*p); - node = node->GetPrevious(); - } - } - action->SetPosition(pos); + wxRichTextRange range = wxRichTextRange(pos, pos + paragraphs.GetRange().GetEnd() - 1); + if (!paragraphs.GetPartialParagraph()) + range.SetEnd(range.GetEnd()+1); + // Set the range we'll need to delete in Undo - action->SetRange(wxRichTextRange(pos, pos + paragraphs.GetRange().GetEnd() - 1)); + action->SetRange(range); SubmitAction(action); @@ -4840,13 +5236,47 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int action->GetNewParagraphs().AppendChild(newPara); action->GetNewParagraphs().UpdateRanges(); action->GetNewParagraphs().SetPartialParagraph(false); - action->SetPosition(pos); + wxRichTextParagraph* para = GetParagraphAtPosition(pos, false); + long pos1 = pos; if (p) newPara->SetAttributes(*p); + if (flags & wxRICHTEXT_INSERT_INTERACTIVE) + { + if (para && para->GetRange().GetEnd() == pos) + pos1 ++; + if (newPara->GetAttributes().HasBulletNumber()) + newPara->GetAttributes().SetBulletNumber(newPara->GetAttributes().GetBulletNumber()+1); + } + + action->SetPosition(pos); + + // Use the default character style + // Use the default character style + if (!GetDefaultStyle().IsDefault() && newPara->GetChildren().GetFirst()) + { + // Check whether the default style merely reflects the paragraph/basic style, + // in which case don't apply it. + wxTextAttrEx defaultStyle(GetDefaultStyle()); + wxTextAttrEx toApply; + if (para) + { + wxRichTextAttr combinedAttr = para->GetCombinedAttributes(); + wxTextAttrEx newAttr; + // This filters out attributes that are accounted for by the current + // paragraph/basic style + wxRichTextApplyStyle(toApply, defaultStyle, & combinedAttr); + } + else + toApply = defaultStyle; + + if (!toApply.IsDefault()) + newPara->GetChildren().GetFirst()->GetData()->SetAttributes(toApply); + } + // Set the range we'll need to delete in Undo - action->SetRange(wxRichTextRange(pos, pos)); + action->SetRange(wxRichTextRange(pos1, pos1)); SubmitAction(action); @@ -4965,22 +5395,18 @@ bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, wxRichT // Copy the fragment that we'll need to restore in Undo CopyFragment(range, action->GetOldParagraphs()); - // Special case: if there is only one (non-partial) paragraph, - // we must save the *next* paragraph's style, because that - // is the style we must apply when inserting the content back - // when undoing the delete. (This is because we're merging the - // paragraph with the previous paragraph and throwing away - // the style, and we need to restore it.) - if (!action->GetOldParagraphs().GetPartialParagraph() && action->GetOldParagraphs().GetChildCount() == 1) + // See if we're deleting a paragraph marker, in which case we need to + // make a note not to copy the attributes from the 2nd paragraph to the 1st. + if (range.GetStart() == range.GetEnd()) { - wxRichTextParagraph* lastPara = GetParagraphAtPosition(range.GetStart()); - if (lastPara) + wxRichTextParagraph* para = GetParagraphAtPosition(range.GetStart()); + if (para && para->GetRange().GetEnd() == range.GetEnd()) { - wxRichTextParagraph* nextPara = GetParagraphAtPosition(range.GetEnd()+1); - if (nextPara) + wxRichTextParagraph* nextPara = GetParagraphAtPosition(range.GetStart()+1); + if (nextPara && nextPara != para) { - wxRichTextParagraph* para = (wxRichTextParagraph*) action->GetOldParagraphs().GetChild(0); - para->SetAttributes(nextPara->GetAttributes()); + action->GetOldParagraphs().GetChildren().GetFirst()->GetData()->SetAttributes(nextPara->GetAttributes()); + action->GetOldParagraphs().GetAttributes().SetFlags(action->GetOldParagraphs().GetAttributes().GetFlags() | wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE); } } } @@ -4998,7 +5424,7 @@ bool wxRichTextBuffer::BeginBatchUndo(const wxString& cmdName) wxASSERT(m_batchedCommand == NULL); if (m_batchedCommand) { - GetCommandProcessor()->Submit(m_batchedCommand); + GetCommandProcessor()->Store(m_batchedCommand); } m_batchedCommand = new wxRichTextCommand(cmdName); } @@ -5018,7 +5444,7 @@ bool wxRichTextBuffer::EndBatchUndo() if (m_batchedCommandDepth == 0) { - GetCommandProcessor()->Submit(m_batchedCommand); + GetCommandProcessor()->Store(m_batchedCommand); m_batchedCommand = NULL; } @@ -5029,7 +5455,15 @@ bool wxRichTextBuffer::EndBatchUndo() bool wxRichTextBuffer::SubmitAction(wxRichTextAction* action) { if (BatchingUndo() && m_batchedCommand && !SuppressingUndo()) + { + wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName()); + cmd->AddAction(action); + cmd->Do(); + cmd->GetActions().Clear(); + delete cmd; + m_batchedCommand->AddAction(action); + } else { wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName()); @@ -5595,6 +6029,8 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) if (richTextBuffer) { InsertParagraphsWithUndo(position+1, *richTextBuffer, GetRichTextCtrl(), wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE); + if (GetRichTextCtrl()) + GetRichTextCtrl()->ShowPosition(position + richTextBuffer->GetRange().GetEnd()); delete richTextBuffer; } } @@ -5603,9 +6039,23 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) wxTextDataObject data; wxTheClipboard->GetData(data); wxString text(data.GetText()); - text.Replace(_T("\r\n"), _T("\n")); +#ifdef __WXMSW__ + wxString text2; + text2.Alloc(text.Length()+1); + size_t i; + for (i = 0; i < text.Length(); i++) + { + wxChar ch = text[i]; + if (ch != wxT('\r')) + text2 += ch; + } +#else + wxString text2 = text; +#endif + InsertTextWithUndo(position+1, text2, GetRichTextCtrl()); - InsertTextWithUndo(position+1, text, GetRichTextCtrl()); + if (GetRichTextCtrl()) + GetRichTextCtrl()->ShowPosition(position + text2.Length()); success = true; } @@ -5863,7 +6313,7 @@ bool wxRichTextStdRenderer::DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& if (attr.GetTextColour().Ok()) dc.SetTextForeground(attr.GetTextColour()); - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); int charHeight = dc.GetCharHeight(); wxCoord tw, th; @@ -6051,7 +6501,7 @@ bool wxRichTextAction::Do() wxPoint firstVisiblePt = m_ctrl->GetFirstVisiblePoint(); int lastY = firstVisiblePt.y + clientSize.y; - wxRichTextParagraph* para = m_buffer->GetParagraphAtPosition(GetPosition()); + wxRichTextParagraph* para = m_buffer->GetParagraphAtPosition(GetRange().GetStart()); wxRichTextObjectList::compatibility_iterator node = m_buffer->GetChildren().Find(para); while (node) { @@ -6084,9 +6534,9 @@ bool wxRichTextAction::Do() } #endif - m_buffer->InsertFragment(GetPosition(), m_newParagraphs); + m_buffer->InsertFragment(GetRange().GetStart(), m_newParagraphs); m_buffer->UpdateRanges(); - m_buffer->Invalidate(GetRange()); + m_buffer->Invalidate(wxRichTextRange(wxMax(0, GetRange().GetStart()-1), GetRange().GetEnd())); long newCaretPosition = GetPosition() + m_newParagraphs.GetRange().GetLength(); @@ -6128,7 +6578,11 @@ bool wxRichTextAction::Do() m_buffer->UpdateRanges(); m_buffer->Invalidate(wxRichTextRange(GetRange().GetStart(), GetRange().GetStart())); - UpdateAppearance(GetRange().GetStart()-1, true /* send update event */); + long caretPos = GetRange().GetStart()-1; + if (caretPos >= m_buffer->GetRange().GetEnd()) + caretPos --; + + UpdateAppearance(caretPos, true /* send update event */); wxRichTextEvent cmdEvent( wxEVT_COMMAND_RICHTEXT_CONTENT_DELETED, @@ -6246,7 +6700,6 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent if (!m_ctrl->IsFrozen()) { m_ctrl->LayoutContent(); - m_ctrl->PositionCaret(); #if wxRICHTEXT_USE_OPTIMIZED_DRAWING // Find refresh rectangle if we are in a position to optimise refresh @@ -6485,11 +6938,19 @@ bool wxRichTextImage::Layout(wxDC& WXUNUSED(dc), const wxRect& rect, int WXUNUSE /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. -bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& WXUNUSED(descent), wxDC& WXUNUSED(dc), int WXUNUSED(flags), wxPoint WXUNUSED(position)) const +bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& WXUNUSED(descent), wxDC& WXUNUSED(dc), int WXUNUSED(flags), wxPoint WXUNUSED(position), wxArrayInt* partialExtents) const { if (!range.IsWithin(GetRange())) return false; + if (partialExtents) + { + if (m_image.Ok()) + partialExtents->Add(m_image.GetWidth()); + else + partialExtents->Add(0); + } + if (!m_image.Ok()) return false; @@ -7165,7 +7626,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxRichTextFontTable, wxObject) wxRichTextFontTable::wxRichTextFontTable() { m_refData = new wxRichTextFontTableData; - m_refData->IncRef(); } wxRichTextFontTable::wxRichTextFontTable(const wxRichTextFontTable& table)