X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d2d0adc7765dfe904f0f7e97d85a2638c934a7d6..1b1b531857cd17285816fcfd6a1a4cc623c6848b:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index d250a15a0e..39129eb982 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -103,11 +103,21 @@ void wxRichTextObject::SetMargins(int leftMargin, int rightMargin, int topMargin m_bottomMargin = bottomMargin; } -// Convert units in tends of a millimetre to device units +// Convert units in tenths of a millimetre to device units int wxRichTextObject::ConvertTenthsMMToPixels(wxDC& dc, int units) { - int ppi = dc.GetPPI().x; + int p = ConvertTenthsMMToPixels(dc.GetPPI().x, units); + // Unscale + wxRichTextBuffer* buffer = GetBuffer(); + if (buffer) + p = (int) ((double)p / buffer->GetScale()); + return p; +} + +// Convert units in tenths of a millimetre to device units +int wxRichTextObject::ConvertTenthsMMToPixels(int ppi, int units) +{ // There are ppi pixels in 254.1 "1/10 mm" double pixels = ((double) units * (double)ppi) / 254.1; @@ -123,6 +133,14 @@ void wxRichTextObject::Dump(wxTextOutputStream& stream) stream << wxString::Format(wxT("Text colour: %d,%d,%d."), (int) m_attributes.GetTextColour().Red(), (int) m_attributes.GetTextColour().Green(), (int) m_attributes.GetTextColour().Blue()) << wxT("\n"); } +/// Gets the containing buffer +wxRichTextBuffer* wxRichTextObject::GetBuffer() const +{ + const wxRichTextObject* obj = this; + while (obj && !obj->IsKindOf(CLASSINFO(wxRichTextBuffer))) + obj = obj->GetParent(); + return wxDynamicCast(obj, wxRichTextBuffer); +} /*! * wxRichTextCompositeObject @@ -508,12 +526,12 @@ bool wxRichTextParagraphLayoutBox::Draw(wxDC& dc, const wxRichTextRange& range, { wxRect childRect(child->GetPosition(), child->GetCachedSize()); - if (childRect.GetTop() > rect.GetBottom() || childRect.GetBottom() < rect.GetTop()) + if (((style & wxRICHTEXT_DRAW_IGNORE_CACHE) == 0) && childRect.GetTop() > rect.GetBottom() || childRect.GetBottom() < rect.GetTop()) { // Skip } else - child->Draw(dc, child->GetRange(), selectionRange, childRect, descent, style); + child->Draw(dc, range, selectionRange, childRect, descent, style); } node = node->GetNext(); @@ -528,7 +546,10 @@ bool wxRichTextParagraphLayoutBox::Layout(wxDC& dc, const wxRect& rect, int styl bool formatRect = (style & wxRICHTEXT_LAYOUT_SPECIFIED_RECT) == wxRICHTEXT_LAYOUT_SPECIFIED_RECT; // If only laying out a specific area, the passed rect has a different meaning: - // the visible part of the buffer. + // the visible part of the buffer. This is used in wxRichTextCtrl::OnSize, + // so that during a size, only the visible part will be relaid out, or + // it would take too long causing flicker. As an approximation, we assume that + // everything up to the start of the visible area is laid out correctly. if (formatRect) { availableSpace = wxRect(0 + m_leftMargin, @@ -2399,6 +2420,8 @@ void wxRichTextParagraphLayoutBox::Reset() Clear(); AddParagraph(wxEmptyString); + + Invalidate(wxRICHTEXT_ALL); } /// Invalidate the buffer. With no argument, invalidates whole buffer. @@ -2975,7 +2998,7 @@ wxRichTextParagraph::~wxRichTextParagraph() } /// Draw the item -bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& WXUNUSED(range), const wxRichTextRange& selectionRange, const wxRect& WXUNUSED(rect), int WXUNUSED(descent), int style) +bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& WXUNUSED(rect), int WXUNUSED(descent), int style) { #if wxRICHTEXT_USE_DYNAMIC_STYLES wxTextAttrEx attr = GetCombinedAttributes(); @@ -3060,7 +3083,8 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& WXUNUSED(range), while (node2) { wxRichTextObject* child = node2->GetData(); - if (!child->GetRange().IsOutside(lineRange)) + + if (!child->GetRange().IsOutside(lineRange) && !lineRange.IsOutside(range)) { // Draw this part of the line at the correct position wxRichTextRange objectRange(child->GetRange()); @@ -3328,7 +3352,7 @@ void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttrEx& attr, const wx } else if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_RIGHT) { - pos.x = rect.GetRight() - size.x; + pos.x = pos.x + rect.GetWidth() - size.x; line->SetPosition(pos); } @@ -4510,6 +4534,7 @@ void wxRichTextBuffer::Init() m_batchedCommand = NULL; m_suppressUndo = 0; m_handlerFlags = 0; + m_scale = 1.0; } /// Initialisation @@ -4522,19 +4547,12 @@ wxRichTextBuffer::~wxRichTextBuffer() ClearEventHandlers(); } -void wxRichTextBuffer::Clear() +void wxRichTextBuffer::ResetAndClearCommands() { - DeleteChildren(); + Reset(); + GetCommandProcessor()->ClearCommands(); - Modify(false); - Invalidate(wxRICHTEXT_ALL); -} -void wxRichTextBuffer::Reset() -{ - DeleteChildren(); - AddParagraph(wxEmptyString); - GetCommandProcessor()->ClearCommands(); Modify(false); Invalidate(wxRICHTEXT_ALL); } @@ -4794,7 +4812,7 @@ wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPos { wxRichTextAttr numberingAttr; if (FindNextParagraphNumber(para, numberingAttr)) - wxRichTextApplyStyle(attr, numberingAttr); + wxRichTextApplyStyle(attr, (const wxRichTextAttr&) numberingAttr); } return attr; @@ -5629,7 +5647,7 @@ void wxRichTextBuffer::SetRenderer(wxRichTextRenderer* renderer) sm_renderer = renderer; } -bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* WXUNUSED(paragraph), wxDC& dc, const wxTextAttrEx& bulletAttr, const wxRect& rect) +bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& bulletAttr, const wxRect& rect) { if (bulletAttr.GetTextColour().Ok()) { @@ -5664,7 +5682,7 @@ bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* WXUNUSED(par y = y + (charHeight+1)/2 - (bulletHeight+1)/2; // The margin between a bullet and text. - int margin = wxRichTextObject::ConvertTenthsMMToPixels(dc, wxRichTextBuffer::GetBulletRightMargin()); + int margin = paragraph->ConvertTenthsMMToPixels(dc, wxRichTextBuffer::GetBulletRightMargin()); if (bulletAttr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT) x = rect.x + rect.width - bulletWidth - margin; @@ -5702,7 +5720,7 @@ bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* WXUNUSED(par return true; } -bool wxRichTextStdRenderer::DrawTextBullet(wxRichTextParagraph* WXUNUSED(paragraph), wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text) +bool wxRichTextStdRenderer::DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxTextAttrEx& attr, const wxRect& rect, const wxString& text) { if (!text.empty()) { @@ -5735,7 +5753,7 @@ bool wxRichTextStdRenderer::DrawTextBullet(wxRichTextParagraph* WXUNUSED(paragra int y = rect.y + (rect.height - charHeight); // The margin between a bullet and text. - int margin = wxRichTextObject::ConvertTenthsMMToPixels(dc, wxRichTextBuffer::GetBulletRightMargin()); + int margin = paragraph->ConvertTenthsMMToPixels(dc, wxRichTextBuffer::GetBulletRightMargin()); if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT) x = (rect.x + rect.width) - tw - margin; @@ -6509,6 +6527,14 @@ bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxTextAttrEx& style) return true; } +bool wxRichTextApplyStyle(wxRichTextAttr& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith) +{ + wxTextAttrEx attr(destStyle); + wxRichTextApplyStyle(attr, style, compareWith); + destStyle = attr; + return true; +} + bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, wxRichTextAttr* compareWith) { // Whole font. Avoiding setting individual attributes if possible, since