1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/richtext/richtextbuffer.cpp
3 // Purpose: Buffer for wxRichTextCtrl
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
21 #include "wx/richtext/richtextbuffer.h"
27 #include "wx/dataobj.h"
28 #include "wx/module.h"
31 #include "wx/filename.h"
32 #include "wx/clipbrd.h"
33 #include "wx/wfstream.h"
34 #include "wx/mstream.h"
35 #include "wx/sstream.h"
36 #include "wx/textfile.h"
38 #include "wx/richtext/richtextctrl.h"
39 #include "wx/richtext/richtextstyles.h"
41 #include "wx/listimpl.cpp"
43 WX_DEFINE_LIST(wxRichTextObjectList
)
44 WX_DEFINE_LIST(wxRichTextLineList
)
48 * This is the base for drawable objects.
51 IMPLEMENT_CLASS(wxRichTextObject
, wxObject
)
53 wxRichTextObject::wxRichTextObject(wxRichTextObject
* parent
)
65 wxRichTextObject::~wxRichTextObject()
69 void wxRichTextObject::Dereference()
77 void wxRichTextObject::Copy(const wxRichTextObject
& obj
)
81 m_dirty
= obj
.m_dirty
;
82 m_range
= obj
.m_range
;
83 m_attributes
= obj
.m_attributes
;
84 m_descent
= obj
.m_descent
;
86 if (!m_attributes.GetFont().Ok())
87 wxLogDebug(wxT("No font!"));
88 if (!obj.m_attributes.GetFont().Ok())
89 wxLogDebug(wxT("Parent has no font!"));
93 void wxRichTextObject::SetMargins(int margin
)
95 m_leftMargin
= m_rightMargin
= m_topMargin
= m_bottomMargin
= margin
;
98 void wxRichTextObject::SetMargins(int leftMargin
, int rightMargin
, int topMargin
, int bottomMargin
)
100 m_leftMargin
= leftMargin
;
101 m_rightMargin
= rightMargin
;
102 m_topMargin
= topMargin
;
103 m_bottomMargin
= bottomMargin
;
106 // Convert units in tends of a millimetre to device units
107 int wxRichTextObject::ConvertTenthsMMToPixels(wxDC
& dc
, int units
)
109 int ppi
= dc
.GetPPI().x
;
111 // There are ppi pixels in 254.1 "1/10 mm"
113 double pixels
= ((double) units
* (double)ppi
) / 254.1;
118 /// Dump to output stream for debugging
119 void wxRichTextObject::Dump(wxTextOutputStream
& stream
)
121 stream
<< GetClassInfo()->GetClassName() << wxT("\n");
122 stream
<< wxString::Format(wxT("Size: %d,%d. Position: %d,%d, Range: %ld,%ld"), m_size
.x
, m_size
.y
, m_pos
.x
, m_pos
.y
, m_range
.GetStart(), m_range
.GetEnd()) << wxT("\n");
123 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");
128 * wxRichTextCompositeObject
129 * This is the base for drawable objects.
132 IMPLEMENT_CLASS(wxRichTextCompositeObject
, wxRichTextObject
)
134 wxRichTextCompositeObject::wxRichTextCompositeObject(wxRichTextObject
* parent
):
135 wxRichTextObject(parent
)
139 wxRichTextCompositeObject::~wxRichTextCompositeObject()
144 /// Get the nth child
145 wxRichTextObject
* wxRichTextCompositeObject::GetChild(size_t n
) const
147 wxASSERT ( n
< m_children
.GetCount() );
149 return m_children
.Item(n
)->GetData();
152 /// Append a child, returning the position
153 size_t wxRichTextCompositeObject::AppendChild(wxRichTextObject
* child
)
155 m_children
.Append(child
);
156 child
->SetParent(this);
157 return m_children
.GetCount() - 1;
160 /// Insert the child in front of the given object, or at the beginning
161 bool wxRichTextCompositeObject::InsertChild(wxRichTextObject
* child
, wxRichTextObject
* inFrontOf
)
165 wxRichTextObjectList::compatibility_iterator node
= m_children
.Find(inFrontOf
);
166 m_children
.Insert(node
, child
);
169 m_children
.Insert(child
);
170 child
->SetParent(this);
176 bool wxRichTextCompositeObject::RemoveChild(wxRichTextObject
* child
, bool deleteChild
)
178 wxRichTextObjectList::compatibility_iterator node
= m_children
.Find(child
);
181 wxRichTextObject
* obj
= node
->GetData();
182 m_children
.Erase(node
);
191 /// Delete all children
192 bool wxRichTextCompositeObject::DeleteChildren()
194 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
197 wxRichTextObjectList::compatibility_iterator oldNode
= node
;
199 wxRichTextObject
* child
= node
->GetData();
200 child
->Dereference(); // Only delete if reference count is zero
202 node
= node
->GetNext();
203 m_children
.Erase(oldNode
);
209 /// Get the child count
210 size_t wxRichTextCompositeObject::GetChildCount() const
212 return m_children
.GetCount();
216 void wxRichTextCompositeObject::Copy(const wxRichTextCompositeObject
& obj
)
218 wxRichTextObject::Copy(obj
);
222 wxRichTextObjectList::compatibility_iterator node
= obj
.m_children
.GetFirst();
225 wxRichTextObject
* child
= node
->GetData();
226 wxRichTextObject
* newChild
= child
->Clone();
227 newChild
->SetParent(this);
228 m_children
.Append(newChild
);
230 node
= node
->GetNext();
234 /// Hit-testing: returns a flag indicating hit test details, plus
235 /// information about position
236 int wxRichTextCompositeObject::HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
)
238 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
241 wxRichTextObject
* child
= node
->GetData();
243 int ret
= child
->HitTest(dc
, pt
, textPosition
);
244 if (ret
!= wxRICHTEXT_HITTEST_NONE
)
247 node
= node
->GetNext();
250 return wxRICHTEXT_HITTEST_NONE
;
253 /// Finds the absolute position and row height for the given character position
254 bool wxRichTextCompositeObject::FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
)
256 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
259 wxRichTextObject
* child
= node
->GetData();
261 if (child
->FindPosition(dc
, index
, pt
, height
, forceLineStart
))
264 node
= node
->GetNext();
271 void wxRichTextCompositeObject::CalculateRange(long start
, long& end
)
273 long current
= start
;
274 long lastEnd
= current
;
276 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
279 wxRichTextObject
* child
= node
->GetData();
282 child
->CalculateRange(current
, childEnd
);
285 current
= childEnd
+ 1;
287 node
= node
->GetNext();
292 // An object with no children has zero length
293 if (m_children
.GetCount() == 0)
296 m_range
.SetRange(start
, end
);
299 /// Delete range from layout.
300 bool wxRichTextCompositeObject::DeleteRange(const wxRichTextRange
& range
)
302 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
306 wxRichTextObject
* obj
= (wxRichTextObject
*) node
->GetData();
307 wxRichTextObjectList::compatibility_iterator next
= node
->GetNext();
309 // Delete the range in each paragraph
311 // When a chunk has been deleted, internally the content does not
312 // now match the ranges.
313 // However, so long as deletion is not done on the same object twice this is OK.
314 // If you may delete content from the same object twice, recalculate
315 // the ranges inbetween DeleteRange calls by calling CalculateRanges, and
316 // adjust the range you're deleting accordingly.
318 if (!obj
->GetRange().IsOutside(range
))
320 obj
->DeleteRange(range
);
322 // Delete an empty object, or paragraph within this range.
323 if (obj
->IsEmpty() ||
324 (range
.GetStart() <= obj
->GetRange().GetStart() && range
.GetEnd() >= obj
->GetRange().GetEnd()))
326 // An empty paragraph has length 1, so won't be deleted unless the
327 // whole range is deleted.
328 RemoveChild(obj
, true);
338 /// Get any text in this object for the given range
339 wxString
wxRichTextCompositeObject::GetTextForRange(const wxRichTextRange
& range
) const
342 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
345 wxRichTextObject
* child
= node
->GetData();
346 wxRichTextRange childRange
= range
;
347 if (!child
->GetRange().IsOutside(range
))
349 childRange
.LimitTo(child
->GetRange());
351 wxString childText
= child
->GetTextForRange(childRange
);
355 node
= node
->GetNext();
361 /// Recursively merge all pieces that can be merged.
362 bool wxRichTextCompositeObject::Defragment()
364 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
367 wxRichTextObject
* child
= node
->GetData();
368 wxRichTextCompositeObject
* composite
= wxDynamicCast(child
, wxRichTextCompositeObject
);
370 composite
->Defragment();
374 wxRichTextObject
* nextChild
= node
->GetNext()->GetData();
375 if (child
->CanMerge(nextChild
) && child
->Merge(nextChild
))
377 nextChild
->Dereference();
378 m_children
.Erase(node
->GetNext());
380 // Don't set node -- we'll see if we can merge again with the next
384 node
= node
->GetNext();
387 node
= node
->GetNext();
393 /// Dump to output stream for debugging
394 void wxRichTextCompositeObject::Dump(wxTextOutputStream
& stream
)
396 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
399 wxRichTextObject
* child
= node
->GetData();
401 node
= node
->GetNext();
408 * This defines a 2D space to lay out objects
411 IMPLEMENT_DYNAMIC_CLASS(wxRichTextBox
, wxRichTextCompositeObject
)
413 wxRichTextBox::wxRichTextBox(wxRichTextObject
* parent
):
414 wxRichTextCompositeObject(parent
)
419 bool wxRichTextBox::Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& WXUNUSED(rect
), int descent
, int style
)
421 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
424 wxRichTextObject
* child
= node
->GetData();
426 wxRect childRect
= wxRect(child
->GetPosition(), child
->GetCachedSize());
427 child
->Draw(dc
, range
, selectionRange
, childRect
, descent
, style
);
429 node
= node
->GetNext();
435 bool wxRichTextBox::Layout(wxDC
& dc
, const wxRect
& rect
, int style
)
437 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
440 wxRichTextObject
* child
= node
->GetData();
441 child
->Layout(dc
, rect
, style
);
443 node
= node
->GetNext();
449 /// Get/set the size for the given range. Assume only has one child.
450 bool wxRichTextBox::GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
) const
452 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
455 wxRichTextObject
* child
= node
->GetData();
456 return child
->GetRangeSize(range
, size
, descent
, dc
, flags
, position
);
463 void wxRichTextBox::Copy(const wxRichTextBox
& obj
)
465 wxRichTextCompositeObject::Copy(obj
);
470 * wxRichTextParagraphLayoutBox
471 * This box knows how to lay out paragraphs.
474 IMPLEMENT_DYNAMIC_CLASS(wxRichTextParagraphLayoutBox
, wxRichTextBox
)
476 wxRichTextParagraphLayoutBox::wxRichTextParagraphLayoutBox(wxRichTextObject
* parent
):
477 wxRichTextBox(parent
)
482 /// Initialize the object.
483 void wxRichTextParagraphLayoutBox::Init()
487 // For now, assume is the only box and has no initial size.
488 m_range
= wxRichTextRange(0, -1);
490 m_invalidRange
.SetRange(-1, -1);
495 m_partialParagraph
= false;
499 bool wxRichTextParagraphLayoutBox::Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int style
)
501 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
504 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
505 wxASSERT (child
!= NULL
);
507 if (child
&& !child
->GetRange().IsOutside(range
))
509 wxRect
childRect(child
->GetPosition(), child
->GetCachedSize());
511 if (childRect
.GetTop() > rect
.GetBottom() || childRect
.GetBottom() < rect
.GetTop())
516 child
->Draw(dc
, child
->GetRange(), selectionRange
, childRect
, descent
, style
);
519 node
= node
->GetNext();
525 bool wxRichTextParagraphLayoutBox::Layout(wxDC
& dc
, const wxRect
& rect
, int style
)
527 wxRect availableSpace
;
528 bool formatRect
= (style
& wxRICHTEXT_LAYOUT_SPECIFIED_RECT
) == wxRICHTEXT_LAYOUT_SPECIFIED_RECT
;
530 // If only laying out a specific area, the passed rect has a different meaning:
531 // the visible part of the buffer.
534 availableSpace
= wxRect(0 + m_leftMargin
,
536 rect
.width
- m_leftMargin
- m_rightMargin
,
539 // Invalidate the part of the buffer from the first visible line
540 // to the end. If other parts of the buffer are currently invalid,
541 // then they too will be taken into account if they are above
542 // the visible point.
544 wxRichTextLine
* line
= GetLineAtYPosition(rect
.y
);
546 startPos
= line
->GetAbsoluteRange().GetStart();
548 Invalidate(wxRichTextRange(startPos
, GetRange().GetEnd()));
551 availableSpace
= wxRect(rect
.x
+ m_leftMargin
,
552 rect
.y
+ m_topMargin
,
553 rect
.width
- m_leftMargin
- m_rightMargin
,
554 rect
.height
- m_topMargin
- m_bottomMargin
);
558 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
560 bool layoutAll
= true;
562 // Get invalid range, rounding to paragraph start/end.
563 wxRichTextRange invalidRange
= GetInvalidRange(true);
565 if (invalidRange
== wxRICHTEXT_NONE
&& !formatRect
)
568 if (invalidRange
== wxRICHTEXT_ALL
)
570 else // If we know what range is affected, start laying out from that point on.
571 if (invalidRange
.GetStart() > GetRange().GetStart())
573 wxRichTextParagraph
* firstParagraph
= GetParagraphAtPosition(invalidRange
.GetStart());
576 wxRichTextObjectList::compatibility_iterator firstNode
= m_children
.Find(firstParagraph
);
577 wxRichTextObjectList::compatibility_iterator previousNode
;
579 previousNode
= firstNode
->GetPrevious();
580 if (firstNode
&& previousNode
)
582 wxRichTextParagraph
* previousParagraph
= wxDynamicCast(previousNode
->GetData(), wxRichTextParagraph
);
583 availableSpace
.y
= previousParagraph
->GetPosition().y
+ previousParagraph
->GetCachedSize().y
;
585 // Now we're going to start iterating from the first affected paragraph.
593 // A way to force speedy rest-of-buffer layout (the 'else' below)
594 bool forceQuickLayout
= false;
598 // Assume this box only contains paragraphs
600 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
601 wxCHECK_MSG( child
, false, _T("Unknown object in layout") );
603 // TODO: what if the child hasn't been laid out (e.g. involved in Undo) but still has 'old' lines
604 if ( !forceQuickLayout
&&
606 child
->GetLines().IsEmpty() ||
607 !child
->GetRange().IsOutside(invalidRange
)) )
609 child
->Layout(dc
, availableSpace
, style
);
611 // Layout must set the cached size
612 availableSpace
.y
+= child
->GetCachedSize().y
;
613 maxWidth
= wxMax(maxWidth
, child
->GetCachedSize().x
);
615 // If we're just formatting the visible part of the buffer,
616 // and we're now past the bottom of the window, start quick
618 if (formatRect
&& child
->GetPosition().y
> rect
.GetBottom())
619 forceQuickLayout
= true;
623 // We're outside the immediately affected range, so now let's just
624 // move everything up or down. This assumes that all the children have previously
625 // been laid out and have wrapped line lists associated with them.
626 // TODO: check all paragraphs before the affected range.
628 int inc
= availableSpace
.y
- child
->GetPosition().y
;
632 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
635 if (child
->GetLines().GetCount() == 0)
636 child
->Layout(dc
, availableSpace
, style
);
638 child
->SetPosition(wxPoint(child
->GetPosition().x
, child
->GetPosition().y
+ inc
));
640 availableSpace
.y
+= child
->GetCachedSize().y
;
641 maxWidth
= wxMax(maxWidth
, child
->GetCachedSize().x
);
644 node
= node
->GetNext();
649 node
= node
->GetNext();
652 SetCachedSize(wxSize(maxWidth
, availableSpace
.y
));
655 m_invalidRange
= wxRICHTEXT_NONE
;
661 void wxRichTextParagraphLayoutBox::Copy(const wxRichTextParagraphLayoutBox
& obj
)
663 wxRichTextBox::Copy(obj
);
665 m_partialParagraph
= obj
.m_partialParagraph
;
668 /// Get/set the size for the given range.
669 bool wxRichTextParagraphLayoutBox::GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
) const
673 wxRichTextObjectList::compatibility_iterator startPara
= wxRichTextObjectList::compatibility_iterator();
674 wxRichTextObjectList::compatibility_iterator endPara
= wxRichTextObjectList::compatibility_iterator();
676 // First find the first paragraph whose starting position is within the range.
677 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
680 // child is a paragraph
681 wxRichTextObject
* child
= node
->GetData();
682 const wxRichTextRange
& r
= child
->GetRange();
684 if (r
.GetStart() <= range
.GetStart() && r
.GetEnd() >= range
.GetStart())
690 node
= node
->GetNext();
693 // Next find the last paragraph containing part of the range
694 node
= m_children
.GetFirst();
697 // child is a paragraph
698 wxRichTextObject
* child
= node
->GetData();
699 const wxRichTextRange
& r
= child
->GetRange();
701 if (r
.GetStart() <= range
.GetEnd() && r
.GetEnd() >= range
.GetEnd())
707 node
= node
->GetNext();
710 if (!startPara
|| !endPara
)
713 // Now we can add up the sizes
714 for (node
= startPara
; node
; node
= node
->GetNext())
716 // child is a paragraph
717 wxRichTextObject
* child
= node
->GetData();
718 const wxRichTextRange
& childRange
= child
->GetRange();
719 wxRichTextRange rangeToFind
= range
;
720 rangeToFind
.LimitTo(childRange
);
724 int childDescent
= 0;
725 child
->GetRangeSize(rangeToFind
, childSize
, childDescent
, dc
, flags
, position
);
727 descent
= wxMax(childDescent
, descent
);
729 sz
.x
= wxMax(sz
.x
, childSize
.x
);
741 /// Get the paragraph at the given position
742 wxRichTextParagraph
* wxRichTextParagraphLayoutBox::GetParagraphAtPosition(long pos
, bool caretPosition
) const
747 // First find the first paragraph whose starting position is within the range.
748 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
751 // child is a paragraph
752 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
753 wxASSERT (child
!= NULL
);
755 // Return first child in buffer if position is -1
759 if (child
->GetRange().Contains(pos
))
762 node
= node
->GetNext();
767 /// Get the line at the given position
768 wxRichTextLine
* wxRichTextParagraphLayoutBox::GetLineAtPosition(long pos
, bool caretPosition
) const
773 // First find the first paragraph whose starting position is within the range.
774 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
777 // child is a paragraph
778 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
779 wxASSERT (child
!= NULL
);
781 wxRichTextLineList::compatibility_iterator node2
= child
->GetLines().GetFirst();
784 wxRichTextLine
* line
= node2
->GetData();
786 wxRichTextRange range
= line
->GetAbsoluteRange();
788 if (range
.Contains(pos
) ||
790 // If the position is end-of-paragraph, then return the last line of
792 (range
.GetEnd() == child
->GetRange().GetEnd()-1) && (pos
== child
->GetRange().GetEnd()))
795 node2
= node2
->GetNext();
798 node
= node
->GetNext();
801 int lineCount
= GetLineCount();
803 return GetLineForVisibleLineNumber(lineCount
-1);
808 /// Get the line at the given y pixel position, or the last line.
809 wxRichTextLine
* wxRichTextParagraphLayoutBox::GetLineAtYPosition(int y
) const
811 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
814 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
815 wxASSERT (child
!= NULL
);
817 wxRichTextLineList::compatibility_iterator node2
= child
->GetLines().GetFirst();
820 wxRichTextLine
* line
= node2
->GetData();
822 wxRect
rect(line
->GetRect());
824 if (y
<= rect
.GetBottom())
827 node2
= node2
->GetNext();
830 node
= node
->GetNext();
834 int lineCount
= GetLineCount();
836 return GetLineForVisibleLineNumber(lineCount
-1);
841 /// Get the number of visible lines
842 int wxRichTextParagraphLayoutBox::GetLineCount() const
846 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
849 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
850 wxASSERT (child
!= NULL
);
852 count
+= child
->GetLines().GetCount();
853 node
= node
->GetNext();
859 /// Get the paragraph for a given line
860 wxRichTextParagraph
* wxRichTextParagraphLayoutBox::GetParagraphForLine(wxRichTextLine
* line
) const
862 return GetParagraphAtPosition(line
->GetAbsoluteRange().GetStart());
865 /// Get the line size at the given position
866 wxSize
wxRichTextParagraphLayoutBox::GetLineSizeAtPosition(long pos
, bool caretPosition
) const
868 wxRichTextLine
* line
= GetLineAtPosition(pos
, caretPosition
);
871 return line
->GetSize();
878 /// Convenience function to add a paragraph of text
879 wxRichTextRange
wxRichTextParagraphLayoutBox::AddParagraph(const wxString
& text
, wxTextAttrEx
* paraStyle
)
881 #if wxRICHTEXT_USE_DYNAMIC_STYLES
882 // Don't use the base style, just the default style, and the base style will
883 // be combined at display time
884 wxTextAttrEx
style(GetDefaultStyle());
886 wxTextAttrEx
style(GetAttributes());
888 // Apply default style. If the style has no attributes set,
889 // then the attributes will remain the 'basic style' (i.e. the
890 // layout box's style).
891 wxRichTextApplyStyle(style
, GetDefaultStyle());
893 wxRichTextParagraph
* para
= new wxRichTextParagraph(text
, this, & style
);
895 para
->SetAttributes(*paraStyle
);
902 return para
->GetRange();
905 /// Adds multiple paragraphs, based on newlines.
906 wxRichTextRange
wxRichTextParagraphLayoutBox::AddParagraphs(const wxString
& text
, wxTextAttrEx
* paraStyle
)
908 #if wxRICHTEXT_USE_DYNAMIC_STYLES
909 // Don't use the base style, just the default style, and the base style will
910 // be combined at display time
911 wxTextAttrEx
style(GetDefaultStyle());
913 wxTextAttrEx
style(GetAttributes());
915 //wxLogDebug("Initial style = %s", style.GetFont().GetFaceName());
916 //wxLogDebug("Initial size = %d", style.GetFont().GetPointSize());
918 // Apply default style. If the style has no attributes set,
919 // then the attributes will remain the 'basic style' (i.e. the
920 // layout box's style).
921 wxRichTextApplyStyle(style
, GetDefaultStyle());
923 //wxLogDebug("Style after applying default style = %s", style.GetFont().GetFaceName());
924 //wxLogDebug("Size after applying default style = %d", style.GetFont().GetPointSize());
927 wxRichTextParagraph
* firstPara
= NULL
;
928 wxRichTextParagraph
* lastPara
= NULL
;
930 wxRichTextRange
range(-1, -1);
933 size_t len
= text
.length();
935 wxRichTextParagraph
* para
= new wxRichTextParagraph(wxT(""), this, & style
);
937 para
->SetAttributes(*paraStyle
);
947 if (ch
== wxT('\n') || ch
== wxT('\r'))
949 wxRichTextPlainText
* plainText
= (wxRichTextPlainText
*) para
->GetChildren().GetFirst()->GetData();
950 plainText
->SetText(line
);
952 para
= new wxRichTextParagraph(wxT(""), this, & style
);
954 para
->SetAttributes(*paraStyle
);
962 line
= wxEmptyString
;
972 wxRichTextPlainText
* plainText
= (wxRichTextPlainText
*) para
->GetChildren().GetFirst()->GetData();
973 plainText
->SetText(line
);
978 range.SetStart(firstPara->GetRange().GetStart());
980 range.SetStart(lastPara->GetRange().GetStart());
983 range.SetEnd(lastPara->GetRange().GetEnd());
985 range.SetEnd(firstPara->GetRange().GetEnd());
992 return wxRichTextRange(firstPara
->GetRange().GetStart(), lastPara
->GetRange().GetEnd());
995 /// Convenience function to add an image
996 wxRichTextRange
wxRichTextParagraphLayoutBox::AddImage(const wxImage
& image
, wxTextAttrEx
* paraStyle
)
998 #if wxRICHTEXT_USE_DYNAMIC_STYLES
999 // Don't use the base style, just the default style, and the base style will
1000 // be combined at display time
1001 wxTextAttrEx
style(GetDefaultStyle());
1003 wxTextAttrEx
style(GetAttributes());
1005 // Apply default style. If the style has no attributes set,
1006 // then the attributes will remain the 'basic style' (i.e. the
1007 // layout box's style).
1008 wxRichTextApplyStyle(style
, GetDefaultStyle());
1011 wxRichTextParagraph
* para
= new wxRichTextParagraph(this, & style
);
1013 para
->AppendChild(new wxRichTextImage(image
, this));
1016 para
->SetAttributes(*paraStyle
);
1021 return para
->GetRange();
1025 /// Insert fragment into this box at the given position. If partialParagraph is true,
1026 /// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
1028 /// TODO: if fragment is inserted inside styled fragment, must apply that style to
1029 /// to the data (if it has a default style, anyway).
1031 bool wxRichTextParagraphLayoutBox::InsertFragment(long position
, wxRichTextParagraphLayoutBox
& fragment
)
1035 // First, find the first paragraph whose starting position is within the range.
1036 wxRichTextParagraph
* para
= GetParagraphAtPosition(position
);
1039 wxRichTextObjectList::compatibility_iterator node
= m_children
.Find(para
);
1041 // Now split at this position, returning the object to insert the new
1042 // ones in front of.
1043 wxRichTextObject
* nextObject
= para
->SplitAt(position
);
1045 // Special case: partial paragraph, just one paragraph. Might be a small amount of
1046 // text, for example, so let's optimize.
1048 if (fragment
.GetPartialParagraph() && fragment
.GetChildren().GetCount() == 1)
1050 // Add the first para to this para...
1051 wxRichTextObjectList::compatibility_iterator firstParaNode
= fragment
.GetChildren().GetFirst();
1055 // Iterate through the fragment paragraph inserting the content into this paragraph.
1056 wxRichTextParagraph
* firstPara
= wxDynamicCast(firstParaNode
->GetData(), wxRichTextParagraph
);
1057 wxASSERT (firstPara
!= NULL
);
1059 wxRichTextObjectList::compatibility_iterator objectNode
= firstPara
->GetChildren().GetFirst();
1062 wxRichTextObject
* newObj
= objectNode
->GetData()->Clone();
1067 para
->AppendChild(newObj
);
1071 // Insert before nextObject
1072 para
->InsertChild(newObj
, nextObject
);
1075 objectNode
= objectNode
->GetNext();
1082 // Procedure for inserting a fragment consisting of a number of
1085 // 1. Remove and save the content that's after the insertion point, for adding
1086 // back once we've added the fragment.
1087 // 2. Add the content from the first fragment paragraph to the current
1089 // 3. Add remaining fragment paragraphs after the current paragraph.
1090 // 4. Add back the saved content from the first paragraph. If partialParagraph
1091 // is true, add it to the last paragraph added and not a new one.
1093 // 1. Remove and save objects after split point.
1094 wxList savedObjects
;
1096 para
->MoveToList(nextObject
, savedObjects
);
1098 // 2. Add the content from the 1st fragment paragraph.
1099 wxRichTextObjectList::compatibility_iterator firstParaNode
= fragment
.GetChildren().GetFirst();
1103 wxRichTextParagraph
* firstPara
= wxDynamicCast(firstParaNode
->GetData(), wxRichTextParagraph
);
1104 wxASSERT(firstPara
!= NULL
);
1106 wxRichTextObjectList::compatibility_iterator objectNode
= firstPara
->GetChildren().GetFirst();
1109 wxRichTextObject
* newObj
= objectNode
->GetData()->Clone();
1112 para
->AppendChild(newObj
);
1114 objectNode
= objectNode
->GetNext();
1117 // 3. Add remaining fragment paragraphs after the current paragraph.
1118 wxRichTextObjectList::compatibility_iterator nextParagraphNode
= node
->GetNext();
1119 wxRichTextObject
* nextParagraph
= NULL
;
1120 if (nextParagraphNode
)
1121 nextParagraph
= nextParagraphNode
->GetData();
1123 wxRichTextObjectList::compatibility_iterator i
= fragment
.GetChildren().GetFirst()->GetNext();
1124 wxRichTextParagraph
* finalPara
= para
;
1126 // If there was only one paragraph, we need to insert a new one.
1129 finalPara
= new wxRichTextParagraph
;
1131 // TODO: These attributes should come from the subsequent paragraph
1132 // when originally deleted, since the subsequent para takes on
1133 // the previous para's attributes.
1134 finalPara
->SetAttributes(firstPara
->GetAttributes());
1137 InsertChild(finalPara
, nextParagraph
);
1139 AppendChild(finalPara
);
1143 wxRichTextParagraph
* para
= wxDynamicCast(i
->GetData(), wxRichTextParagraph
);
1144 wxASSERT( para
!= NULL
);
1146 finalPara
= (wxRichTextParagraph
*) para
->Clone();
1149 InsertChild(finalPara
, nextParagraph
);
1151 AppendChild(finalPara
);
1156 // 4. Add back the remaining content.
1159 finalPara
->MoveFromList(savedObjects
);
1161 // Ensure there's at least one object
1162 if (finalPara
->GetChildCount() == 0)
1164 wxRichTextPlainText
* text
= new wxRichTextPlainText(wxEmptyString
);
1165 #if !wxRICHTEXT_USE_DYNAMIC_STYLES
1166 text
->SetAttributes(finalPara
->GetAttributes());
1169 finalPara
->AppendChild(text
);
1179 wxRichTextObjectList::compatibility_iterator i
= fragment
.GetChildren().GetFirst();
1182 wxRichTextParagraph
* para
= wxDynamicCast(i
->GetData(), wxRichTextParagraph
);
1183 wxASSERT( para
!= NULL
);
1185 AppendChild(para
->Clone());
1194 /// Make a copy of the fragment corresponding to the given range, putting it in 'fragment'.
1195 /// If there was an incomplete paragraph at the end, partialParagraph is set to true.
1196 bool wxRichTextParagraphLayoutBox::CopyFragment(const wxRichTextRange
& range
, wxRichTextParagraphLayoutBox
& fragment
)
1198 wxRichTextObjectList::compatibility_iterator i
= GetChildren().GetFirst();
1201 wxRichTextParagraph
* para
= wxDynamicCast(i
->GetData(), wxRichTextParagraph
);
1202 wxASSERT( para
!= NULL
);
1204 if (!para
->GetRange().IsOutside(range
))
1206 fragment
.AppendChild(para
->Clone());
1211 // Now top and tail the first and last paragraphs in our new fragment (which might be the same).
1212 if (!fragment
.IsEmpty())
1214 wxRichTextRange
topTailRange(range
);
1216 wxRichTextParagraph
* firstPara
= wxDynamicCast(fragment
.GetChildren().GetFirst()->GetData(), wxRichTextParagraph
);
1217 wxASSERT( firstPara
!= NULL
);
1219 // Chop off the start of the paragraph
1220 if (topTailRange
.GetStart() > firstPara
->GetRange().GetStart())
1222 wxRichTextRange
r(firstPara
->GetRange().GetStart(), topTailRange
.GetStart()-1);
1223 firstPara
->DeleteRange(r
);
1225 // Make sure the numbering is correct
1227 fragment
.CalculateRange(firstPara
->GetRange().GetStart(), end
);
1229 // Now, we've deleted some positions, so adjust the range
1231 topTailRange
.SetEnd(topTailRange
.GetEnd() - r
.GetLength());
1234 wxRichTextParagraph
* lastPara
= wxDynamicCast(fragment
.GetChildren().GetLast()->GetData(), wxRichTextParagraph
);
1235 wxASSERT( lastPara
!= NULL
);
1237 if (topTailRange
.GetEnd() < (lastPara
->GetRange().GetEnd()-1))
1239 wxRichTextRange
r(topTailRange
.GetEnd()+1, lastPara
->GetRange().GetEnd()-1); /* -1 since actual text ends 1 position before end of para marker */
1240 lastPara
->DeleteRange(r
);
1242 // Make sure the numbering is correct
1244 fragment
.CalculateRange(firstPara
->GetRange().GetStart(), end
);
1246 // We only have part of a paragraph at the end
1247 fragment
.SetPartialParagraph(true);
1251 if (topTailRange
.GetEnd() == (lastPara
->GetRange().GetEnd() - 1))
1252 // We have a partial paragraph (don't save last new paragraph marker)
1253 fragment
.SetPartialParagraph(true);
1255 // We have a complete paragraph
1256 fragment
.SetPartialParagraph(false);
1263 /// Given a position, get the number of the visible line (potentially many to a paragraph),
1264 /// starting from zero at the start of the buffer.
1265 long wxRichTextParagraphLayoutBox::GetVisibleLineNumber(long pos
, bool caretPosition
, bool startOfLine
) const
1272 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
1275 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
1276 wxASSERT( child
!= NULL
);
1278 if (child
->GetRange().Contains(pos
))
1280 wxRichTextLineList::compatibility_iterator node2
= child
->GetLines().GetFirst();
1283 wxRichTextLine
* line
= node2
->GetData();
1284 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
1286 if (lineRange
.Contains(pos
))
1288 // If the caret is displayed at the end of the previous wrapped line,
1289 // we want to return the line it's _displayed_ at (not the actual line
1290 // containing the position).
1291 if (lineRange
.GetStart() == pos
&& !startOfLine
&& child
->GetRange().GetStart() != pos
)
1292 return lineCount
- 1;
1299 node2
= node2
->GetNext();
1301 // If we didn't find it in the lines, it must be
1302 // the last position of the paragraph. So return the last line.
1306 lineCount
+= child
->GetLines().GetCount();
1308 node
= node
->GetNext();
1315 /// Given a line number, get the corresponding wxRichTextLine object.
1316 wxRichTextLine
* wxRichTextParagraphLayoutBox::GetLineForVisibleLineNumber(long lineNumber
) const
1320 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
1323 wxRichTextParagraph
* child
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
1324 wxASSERT(child
!= NULL
);
1326 if (lineNumber
< (int) (child
->GetLines().GetCount() + lineCount
))
1328 wxRichTextLineList::compatibility_iterator node2
= child
->GetLines().GetFirst();
1331 wxRichTextLine
* line
= node2
->GetData();
1333 if (lineCount
== lineNumber
)
1338 node2
= node2
->GetNext();
1342 lineCount
+= child
->GetLines().GetCount();
1344 node
= node
->GetNext();
1351 /// Delete range from layout.
1352 bool wxRichTextParagraphLayoutBox::DeleteRange(const wxRichTextRange
& range
)
1354 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
1358 wxRichTextParagraph
* obj
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
1359 wxASSERT (obj
!= NULL
);
1361 wxRichTextObjectList::compatibility_iterator next
= node
->GetNext();
1363 // Delete the range in each paragraph
1365 if (!obj
->GetRange().IsOutside(range
))
1367 // Deletes the content of this object within the given range
1368 obj
->DeleteRange(range
);
1370 // If the whole paragraph is within the range to delete,
1371 // delete the whole thing.
1372 if (range
.GetStart() <= obj
->GetRange().GetStart() && range
.GetEnd() >= obj
->GetRange().GetEnd())
1374 // Delete the whole object
1375 RemoveChild(obj
, true);
1377 // If the range includes the paragraph end, we need to join this
1378 // and the next paragraph.
1379 else if (range
.Contains(obj
->GetRange().GetEnd()))
1381 // We need to move the objects from the next paragraph
1382 // to this paragraph
1386 wxRichTextParagraph
* nextParagraph
= wxDynamicCast(next
->GetData(), wxRichTextParagraph
);
1387 next
= next
->GetNext();
1390 // Delete the stuff we need to delete
1391 nextParagraph
->DeleteRange(range
);
1393 // Move the objects to the previous para
1394 wxRichTextObjectList::compatibility_iterator node1
= nextParagraph
->GetChildren().GetFirst();
1398 wxRichTextObject
* obj1
= node1
->GetData();
1400 // If the object is empty, optimise it out
1401 if (obj1
->IsEmpty())
1407 obj
->AppendChild(obj1
);
1410 wxRichTextObjectList::compatibility_iterator next1
= node1
->GetNext();
1411 nextParagraph
->GetChildren().Erase(node1
);
1416 // Delete the paragraph
1417 RemoveChild(nextParagraph
, true);
1431 /// Get any text in this object for the given range
1432 wxString
wxRichTextParagraphLayoutBox::GetTextForRange(const wxRichTextRange
& range
) const
1436 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
1439 wxRichTextObject
* child
= node
->GetData();
1440 if (!child
->GetRange().IsOutside(range
))
1442 // if (lineCount > 0)
1443 // text += wxT("\n");
1444 wxRichTextRange childRange
= range
;
1445 childRange
.LimitTo(child
->GetRange());
1447 wxString childText
= child
->GetTextForRange(childRange
);
1451 if (childRange
.GetEnd() == child
->GetRange().GetEnd())
1456 node
= node
->GetNext();
1462 /// Get all the text
1463 wxString
wxRichTextParagraphLayoutBox::GetText() const
1465 return GetTextForRange(GetRange());
1468 /// Get the paragraph by number
1469 wxRichTextParagraph
* wxRichTextParagraphLayoutBox::GetParagraphAtLine(long paragraphNumber
) const
1471 if ((size_t) paragraphNumber
>= GetChildCount())
1474 return (wxRichTextParagraph
*) GetChild((size_t) paragraphNumber
);
1477 /// Get the length of the paragraph
1478 int wxRichTextParagraphLayoutBox::GetParagraphLength(long paragraphNumber
) const
1480 wxRichTextParagraph
* para
= GetParagraphAtLine(paragraphNumber
);
1482 return para
->GetRange().GetLength() - 1; // don't include newline
1487 /// Get the text of the paragraph
1488 wxString
wxRichTextParagraphLayoutBox::GetParagraphText(long paragraphNumber
) const
1490 wxRichTextParagraph
* para
= GetParagraphAtLine(paragraphNumber
);
1492 return para
->GetTextForRange(para
->GetRange());
1494 return wxEmptyString
;
1497 /// Convert zero-based line column and paragraph number to a position.
1498 long wxRichTextParagraphLayoutBox::XYToPosition(long x
, long y
) const
1500 wxRichTextParagraph
* para
= GetParagraphAtLine(y
);
1503 return para
->GetRange().GetStart() + x
;
1509 /// Convert zero-based position to line column and paragraph number
1510 bool wxRichTextParagraphLayoutBox::PositionToXY(long pos
, long* x
, long* y
) const
1512 wxRichTextParagraph
* para
= GetParagraphAtPosition(pos
);
1516 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
1519 wxRichTextObject
* child
= node
->GetData();
1523 node
= node
->GetNext();
1527 *x
= pos
- para
->GetRange().GetStart();
1535 /// Get the leaf object in a paragraph at this position.
1536 /// Given a line number, get the corresponding wxRichTextLine object.
1537 wxRichTextObject
* wxRichTextParagraphLayoutBox::GetLeafObjectAtPosition(long position
) const
1539 wxRichTextParagraph
* para
= GetParagraphAtPosition(position
);
1542 wxRichTextObjectList::compatibility_iterator node
= para
->GetChildren().GetFirst();
1546 wxRichTextObject
* child
= node
->GetData();
1547 if (child
->GetRange().Contains(position
))
1550 node
= node
->GetNext();
1552 if (position
== para
->GetRange().GetEnd() && para
->GetChildCount() > 0)
1553 return para
->GetChildren().GetLast()->GetData();
1558 /// Set character or paragraph text attributes: apply character styles only to immediate text nodes
1559 bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange
& range
, const wxRichTextAttr
& style
, int flags
)
1561 bool characterStyle
= false;
1562 bool paragraphStyle
= false;
1564 if (style
.IsCharacterStyle())
1565 characterStyle
= true;
1566 if (style
.IsParagraphStyle())
1567 paragraphStyle
= true;
1569 bool withUndo
= ((flags
& wxRICHTEXT_SETSTYLE_WITH_UNDO
) != 0);
1570 bool applyMinimal
= ((flags
& wxRICHTEXT_SETSTYLE_OPTIMIZE
) != 0);
1571 bool parasOnly
= ((flags
& wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY
) != 0);
1572 bool charactersOnly
= ((flags
& wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY
) != 0);
1574 // Limit the attributes to be set to the content to only character attributes.
1575 wxRichTextAttr
characterAttributes(style
);
1576 characterAttributes
.SetFlags(characterAttributes
.GetFlags() & (wxTEXT_ATTR_CHARACTER
));
1578 // If we are associated with a control, make undoable; otherwise, apply immediately
1581 bool haveControl
= (GetRichTextCtrl() != NULL
);
1583 wxRichTextAction
* action
= NULL
;
1585 if (haveControl
&& withUndo
)
1587 action
= new wxRichTextAction(NULL
, _("Change Style"), wxRICHTEXT_CHANGE_STYLE
, & GetRichTextCtrl()->GetBuffer(), GetRichTextCtrl());
1588 action
->SetRange(range
);
1589 action
->SetPosition(GetRichTextCtrl()->GetCaretPosition());
1592 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
1595 wxRichTextParagraph
* para
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
1596 wxASSERT (para
!= NULL
);
1598 if (para
&& para
->GetChildCount() > 0)
1600 // Stop searching if we're beyond the range of interest
1601 if (para
->GetRange().GetStart() > range
.GetEnd())
1604 if (!para
->GetRange().IsOutside(range
))
1606 // We'll be using a copy of the paragraph to make style changes,
1607 // not updating the buffer directly.
1608 wxRichTextParagraph
* newPara
wxDUMMY_INITIALIZE(NULL
);
1610 if (haveControl
&& withUndo
)
1612 newPara
= new wxRichTextParagraph(*para
);
1613 action
->GetNewParagraphs().AppendChild(newPara
);
1615 // Also store the old ones for Undo
1616 action
->GetOldParagraphs().AppendChild(new wxRichTextParagraph(*para
));
1621 if (paragraphStyle
&& !charactersOnly
)
1625 // Only apply attributes that will make a difference to the combined
1626 // style as seen on the display
1627 wxRichTextAttr
combinedAttr(para
->GetCombinedAttributes());
1628 wxRichTextApplyStyle(newPara
->GetAttributes(), style
, & combinedAttr
);
1631 wxRichTextApplyStyle(newPara
->GetAttributes(), style
);
1634 #if wxRICHTEXT_USE_DYNAMIC_STYLES
1635 // If applying paragraph styles dynamically, don't change the text objects' attributes
1636 // since they will computed as needed. Only apply the character styling if it's _only_
1637 // character styling. This policy is subject to change and might be put under user control.
1639 // Hm. we might well be applying a mix of paragraph and character styles, in which
1640 // case we _do_ want to apply character styles regardless of what para styles are set.
1641 // But if we're applying a paragraph style, which has some character attributes, but
1642 // we only want the paragraphs to hold this character style, then we _don't_ want to
1643 // apply the character style. So we need to be able to choose.
1645 // if (!paragraphStyle && characterStyle && range.GetStart() != newPara->GetRange().GetEnd())
1646 if (!parasOnly
&& characterStyle
&& range
.GetStart() != newPara
->GetRange().GetEnd())
1648 if (characterStyle
&& range
.GetStart() != newPara
->GetRange().GetEnd())
1651 wxRichTextRange
childRange(range
);
1652 childRange
.LimitTo(newPara
->GetRange());
1654 // Find the starting position and if necessary split it so
1655 // we can start applying a different style.
1656 // TODO: check that the style actually changes or is different
1657 // from style outside of range
1658 wxRichTextObject
* firstObject
wxDUMMY_INITIALIZE(NULL
);
1659 wxRichTextObject
* lastObject
wxDUMMY_INITIALIZE(NULL
);
1661 if (childRange
.GetStart() == newPara
->GetRange().GetStart())
1662 firstObject
= newPara
->GetChildren().GetFirst()->GetData();
1664 firstObject
= newPara
->SplitAt(range
.GetStart());
1666 // Increment by 1 because we're apply the style one _after_ the split point
1667 long splitPoint
= childRange
.GetEnd();
1668 if (splitPoint
!= newPara
->GetRange().GetEnd())
1672 if (splitPoint
== newPara
->GetRange().GetEnd() || splitPoint
== (newPara
->GetRange().GetEnd() - 1))
1673 lastObject
= newPara
->GetChildren().GetLast()->GetData();
1675 // lastObject is set as a side-effect of splitting. It's
1676 // returned as the object before the new object.
1677 (void) newPara
->SplitAt(splitPoint
, & lastObject
);
1679 wxASSERT(firstObject
!= NULL
);
1680 wxASSERT(lastObject
!= NULL
);
1682 if (!firstObject
|| !lastObject
)
1685 wxRichTextObjectList::compatibility_iterator firstNode
= newPara
->GetChildren().Find(firstObject
);
1686 wxRichTextObjectList::compatibility_iterator lastNode
= newPara
->GetChildren().Find(lastObject
);
1688 wxASSERT(firstNode
);
1691 wxRichTextObjectList::compatibility_iterator node2
= firstNode
;
1695 wxRichTextObject
* child
= node2
->GetData();
1699 // Only apply attributes that will make a difference to the combined
1700 // style as seen on the display
1701 wxRichTextAttr
combinedAttr(newPara
->GetCombinedAttributes(child
->GetAttributes()));
1702 wxRichTextApplyStyle(child
->GetAttributes(), characterAttributes
, & combinedAttr
);
1705 wxRichTextApplyStyle(child
->GetAttributes(), characterAttributes
);
1707 if (node2
== lastNode
)
1710 node2
= node2
->GetNext();
1716 node
= node
->GetNext();
1719 // Do action, or delay it until end of batch.
1720 if (haveControl
&& withUndo
)
1721 GetRichTextCtrl()->GetBuffer().SubmitAction(action
);
1726 /// Set text attributes
1727 bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange
& range
, const wxTextAttrEx
& style
, int flags
)
1729 wxRichTextAttr richStyle
= style
;
1730 return SetStyle(range
, richStyle
, flags
);
1733 /// Get the text attributes for this position.
1734 bool wxRichTextParagraphLayoutBox::GetStyle(long position
, wxTextAttrEx
& style
)
1736 return DoGetStyle(position
, style
, true);
1739 /// Get the text attributes for this position.
1740 bool wxRichTextParagraphLayoutBox::GetStyle(long position
, wxRichTextAttr
& style
)
1742 wxTextAttrEx
textAttrEx(style
);
1743 if (GetStyle(position
, textAttrEx
))
1752 /// Get the content (uncombined) attributes for this position.
1753 bool wxRichTextParagraphLayoutBox::GetUncombinedStyle(long position
, wxTextAttrEx
& style
)
1755 return DoGetStyle(position
, style
, false);
1758 bool wxRichTextParagraphLayoutBox::GetUncombinedStyle(long position
, wxRichTextAttr
& style
)
1760 wxTextAttrEx
textAttrEx(style
);
1761 if (GetUncombinedStyle(position
, textAttrEx
))
1770 /// Implementation helper for GetStyle. If combineStyles is true, combine base, paragraph and
1771 /// context attributes.
1772 bool wxRichTextParagraphLayoutBox::DoGetStyle(long position
, wxTextAttrEx
& style
, bool combineStyles
)
1774 wxRichTextObject
* obj
wxDUMMY_INITIALIZE(NULL
);
1776 if (style
.IsParagraphStyle())
1778 obj
= GetParagraphAtPosition(position
);
1781 #if wxRICHTEXT_USE_DYNAMIC_STYLES
1784 // Start with the base style
1785 style
= GetAttributes();
1787 // Apply the paragraph style
1788 wxRichTextApplyStyle(style
, obj
->GetAttributes());
1791 style
= obj
->GetAttributes();
1793 style
= obj
->GetAttributes();
1800 obj
= GetLeafObjectAtPosition(position
);
1803 #if wxRICHTEXT_USE_DYNAMIC_STYLES
1806 wxRichTextParagraph
* para
= wxDynamicCast(obj
->GetParent(), wxRichTextParagraph
);
1807 style
= para
? para
->GetCombinedAttributes(obj
->GetAttributes()) : obj
->GetAttributes();
1810 style
= obj
->GetAttributes();
1812 style
= obj
->GetAttributes();
1820 static bool wxHasStyle(long flags
, long style
)
1822 return (flags
& style
) != 0;
1825 /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of
1827 bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttrEx
& currentStyle
, const wxTextAttrEx
& style
, long& multipleStyleAttributes
)
1829 if (style
.HasFont())
1831 if (style
.HasSize() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_FONT_SIZE
))
1833 if (currentStyle
.GetFont().Ok() && currentStyle
.HasSize())
1835 if (currentStyle
.GetFont().GetPointSize() != style
.GetFont().GetPointSize())
1837 // Clash of style - mark as such
1838 multipleStyleAttributes
|= wxTEXT_ATTR_FONT_SIZE
;
1839 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_FONT_SIZE
);
1844 if (!currentStyle
.GetFont().Ok())
1845 wxSetFontPreservingStyles(currentStyle
, *wxNORMAL_FONT
);
1846 wxFont
font(currentStyle
.GetFont());
1847 font
.SetPointSize(style
.GetFont().GetPointSize());
1849 wxSetFontPreservingStyles(currentStyle
, font
);
1850 currentStyle
.SetFlags(currentStyle
.GetFlags() | wxTEXT_ATTR_FONT_SIZE
);
1854 if (style
.HasItalic() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_FONT_ITALIC
))
1856 if (currentStyle
.GetFont().Ok() && currentStyle
.HasItalic())
1858 if (currentStyle
.GetFont().GetStyle() != style
.GetFont().GetStyle())
1860 // Clash of style - mark as such
1861 multipleStyleAttributes
|= wxTEXT_ATTR_FONT_ITALIC
;
1862 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_FONT_ITALIC
);
1867 if (!currentStyle
.GetFont().Ok())
1868 wxSetFontPreservingStyles(currentStyle
, *wxNORMAL_FONT
);
1869 wxFont
font(currentStyle
.GetFont());
1870 font
.SetStyle(style
.GetFont().GetStyle());
1871 wxSetFontPreservingStyles(currentStyle
, font
);
1872 currentStyle
.SetFlags(currentStyle
.GetFlags() | wxTEXT_ATTR_FONT_ITALIC
);
1876 if (style
.HasWeight() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_FONT_WEIGHT
))
1878 if (currentStyle
.GetFont().Ok() && currentStyle
.HasWeight())
1880 if (currentStyle
.GetFont().GetWeight() != style
.GetFont().GetWeight())
1882 // Clash of style - mark as such
1883 multipleStyleAttributes
|= wxTEXT_ATTR_FONT_WEIGHT
;
1884 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_FONT_WEIGHT
);
1889 if (!currentStyle
.GetFont().Ok())
1890 wxSetFontPreservingStyles(currentStyle
, *wxNORMAL_FONT
);
1891 wxFont
font(currentStyle
.GetFont());
1892 font
.SetWeight(style
.GetFont().GetWeight());
1893 wxSetFontPreservingStyles(currentStyle
, font
);
1894 currentStyle
.SetFlags(currentStyle
.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT
);
1898 if (style
.HasFaceName() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_FONT_FACE
))
1900 if (currentStyle
.GetFont().Ok() && currentStyle
.HasFaceName())
1902 wxString
faceName1(currentStyle
.GetFont().GetFaceName());
1903 wxString
faceName2(style
.GetFont().GetFaceName());
1905 if (faceName1
!= faceName2
)
1907 // Clash of style - mark as such
1908 multipleStyleAttributes
|= wxTEXT_ATTR_FONT_FACE
;
1909 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_FONT_FACE
);
1914 if (!currentStyle
.GetFont().Ok())
1915 wxSetFontPreservingStyles(currentStyle
, *wxNORMAL_FONT
);
1916 wxFont
font(currentStyle
.GetFont());
1917 font
.SetFaceName(style
.GetFont().GetFaceName());
1918 wxSetFontPreservingStyles(currentStyle
, font
);
1919 currentStyle
.SetFlags(currentStyle
.GetFlags() | wxTEXT_ATTR_FONT_FACE
);
1923 if (style
.HasUnderlined() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_FONT_UNDERLINE
))
1925 if (currentStyle
.GetFont().Ok() && currentStyle
.HasUnderlined())
1927 if (currentStyle
.GetFont().GetUnderlined() != style
.GetFont().GetUnderlined())
1929 // Clash of style - mark as such
1930 multipleStyleAttributes
|= wxTEXT_ATTR_FONT_UNDERLINE
;
1931 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_FONT_UNDERLINE
);
1936 if (!currentStyle
.GetFont().Ok())
1937 wxSetFontPreservingStyles(currentStyle
, *wxNORMAL_FONT
);
1938 wxFont
font(currentStyle
.GetFont());
1939 font
.SetUnderlined(style
.GetFont().GetUnderlined());
1940 wxSetFontPreservingStyles(currentStyle
, font
);
1941 currentStyle
.SetFlags(currentStyle
.GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE
);
1946 if (style
.HasTextColour() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_TEXT_COLOUR
))
1948 if (currentStyle
.HasTextColour())
1950 if (currentStyle
.GetTextColour() != style
.GetTextColour())
1952 // Clash of style - mark as such
1953 multipleStyleAttributes
|= wxTEXT_ATTR_TEXT_COLOUR
;
1954 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_TEXT_COLOUR
);
1958 currentStyle
.SetTextColour(style
.GetTextColour());
1961 if (style
.HasBackgroundColour() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_BACKGROUND_COLOUR
))
1963 if (currentStyle
.HasBackgroundColour())
1965 if (currentStyle
.GetBackgroundColour() != style
.GetBackgroundColour())
1967 // Clash of style - mark as such
1968 multipleStyleAttributes
|= wxTEXT_ATTR_BACKGROUND_COLOUR
;
1969 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_BACKGROUND_COLOUR
);
1973 currentStyle
.SetBackgroundColour(style
.GetBackgroundColour());
1976 if (style
.HasAlignment() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_ALIGNMENT
))
1978 if (currentStyle
.HasAlignment())
1980 if (currentStyle
.GetAlignment() != style
.GetAlignment())
1982 // Clash of style - mark as such
1983 multipleStyleAttributes
|= wxTEXT_ATTR_ALIGNMENT
;
1984 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_ALIGNMENT
);
1988 currentStyle
.SetAlignment(style
.GetAlignment());
1991 if (style
.HasTabs() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_TABS
))
1993 if (currentStyle
.HasTabs())
1995 if (!wxRichTextTabsEq(currentStyle
.GetTabs(), style
.GetTabs()))
1997 // Clash of style - mark as such
1998 multipleStyleAttributes
|= wxTEXT_ATTR_TABS
;
1999 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_TABS
);
2003 currentStyle
.SetTabs(style
.GetTabs());
2006 if (style
.HasLeftIndent() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_LEFT_INDENT
))
2008 if (currentStyle
.HasLeftIndent())
2010 if (currentStyle
.GetLeftIndent() != style
.GetLeftIndent() || currentStyle
.GetLeftSubIndent() != style
.GetLeftSubIndent())
2012 // Clash of style - mark as such
2013 multipleStyleAttributes
|= wxTEXT_ATTR_LEFT_INDENT
;
2014 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_LEFT_INDENT
);
2018 currentStyle
.SetLeftIndent(style
.GetLeftIndent(), style
.GetLeftSubIndent());
2021 if (style
.HasRightIndent() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_RIGHT_INDENT
))
2023 if (currentStyle
.HasRightIndent())
2025 if (currentStyle
.GetRightIndent() != style
.GetRightIndent())
2027 // Clash of style - mark as such
2028 multipleStyleAttributes
|= wxTEXT_ATTR_RIGHT_INDENT
;
2029 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_RIGHT_INDENT
);
2033 currentStyle
.SetRightIndent(style
.GetRightIndent());
2036 if (style
.HasParagraphSpacingAfter() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_PARA_SPACING_AFTER
))
2038 if (currentStyle
.HasParagraphSpacingAfter())
2040 if (currentStyle
.HasParagraphSpacingAfter() != style
.HasParagraphSpacingAfter())
2042 // Clash of style - mark as such
2043 multipleStyleAttributes
|= wxTEXT_ATTR_PARA_SPACING_AFTER
;
2044 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_PARA_SPACING_AFTER
);
2048 currentStyle
.SetParagraphSpacingAfter(style
.GetParagraphSpacingAfter());
2051 if (style
.HasParagraphSpacingBefore() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_PARA_SPACING_BEFORE
))
2053 if (currentStyle
.HasParagraphSpacingBefore())
2055 if (currentStyle
.HasParagraphSpacingBefore() != style
.HasParagraphSpacingBefore())
2057 // Clash of style - mark as such
2058 multipleStyleAttributes
|= wxTEXT_ATTR_PARA_SPACING_BEFORE
;
2059 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_PARA_SPACING_BEFORE
);
2063 currentStyle
.SetParagraphSpacingBefore(style
.GetParagraphSpacingBefore());
2066 if (style
.HasLineSpacing() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_LINE_SPACING
))
2068 if (currentStyle
.HasLineSpacing())
2070 if (currentStyle
.HasLineSpacing() != style
.HasLineSpacing())
2072 // Clash of style - mark as such
2073 multipleStyleAttributes
|= wxTEXT_ATTR_LINE_SPACING
;
2074 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_LINE_SPACING
);
2078 currentStyle
.SetLineSpacing(style
.GetLineSpacing());
2081 if (style
.HasCharacterStyleName() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_CHARACTER_STYLE_NAME
))
2083 if (currentStyle
.HasCharacterStyleName())
2085 if (currentStyle
.HasCharacterStyleName() != style
.HasCharacterStyleName())
2087 // Clash of style - mark as such
2088 multipleStyleAttributes
|= wxTEXT_ATTR_CHARACTER_STYLE_NAME
;
2089 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_CHARACTER_STYLE_NAME
);
2093 currentStyle
.SetCharacterStyleName(style
.GetCharacterStyleName());
2096 if (style
.HasParagraphStyleName() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
))
2098 if (currentStyle
.HasParagraphStyleName())
2100 if (currentStyle
.HasParagraphStyleName() != style
.HasParagraphStyleName())
2102 // Clash of style - mark as such
2103 multipleStyleAttributes
|= wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
;
2104 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
);
2108 currentStyle
.SetParagraphStyleName(style
.GetParagraphStyleName());
2111 if (style
.HasBulletStyle() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_BULLET_STYLE
))
2113 if (currentStyle
.HasBulletStyle())
2115 if (currentStyle
.HasBulletStyle() != style
.HasBulletStyle())
2117 // Clash of style - mark as such
2118 multipleStyleAttributes
|= wxTEXT_ATTR_BULLET_STYLE
;
2119 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_BULLET_STYLE
);
2123 currentStyle
.SetBulletStyle(style
.GetBulletStyle());
2126 if (style
.HasBulletNumber() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_BULLET_NUMBER
))
2128 if (currentStyle
.HasBulletNumber())
2130 if (currentStyle
.HasBulletNumber() != style
.HasBulletNumber())
2132 // Clash of style - mark as such
2133 multipleStyleAttributes
|= wxTEXT_ATTR_BULLET_NUMBER
;
2134 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_BULLET_NUMBER
);
2138 currentStyle
.SetBulletNumber(style
.GetBulletNumber());
2141 if (style
.HasBulletSymbol() && !wxHasStyle(multipleStyleAttributes
, wxTEXT_ATTR_BULLET_SYMBOL
))
2143 if (currentStyle
.HasBulletSymbol())
2145 if (currentStyle
.HasBulletSymbol() != style
.HasBulletSymbol())
2147 // Clash of style - mark as such
2148 multipleStyleAttributes
|= wxTEXT_ATTR_BULLET_SYMBOL
;
2149 currentStyle
.SetFlags(currentStyle
.GetFlags() & ~wxTEXT_ATTR_BULLET_SYMBOL
);
2154 currentStyle
.SetBulletSymbol(style
.GetBulletSymbol());
2155 currentStyle
.SetBulletFont(style
.GetBulletFont());
2162 /// Get the combined style for a range - if any attribute is different within the range,
2163 /// that attribute is not present within the flags.
2164 /// *** Note that this is not recursive, and so assumes that content inside a paragraph is not itself
2166 bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange
& range
, wxTextAttrEx
& style
)
2168 style
= wxTextAttrEx();
2170 // The attributes that aren't valid because of multiple styles within the range
2171 long multipleStyleAttributes
= 0;
2173 wxRichTextObjectList::compatibility_iterator node
= GetChildren().GetFirst();
2176 wxRichTextParagraph
* para
= (wxRichTextParagraph
*) node
->GetData();
2177 if (!(para
->GetRange().GetStart() > range
.GetEnd() || para
->GetRange().GetEnd() < range
.GetStart()))
2179 if (para
->GetChildren().GetCount() == 0)
2181 wxTextAttrEx paraStyle
= para
->GetCombinedAttributes();
2183 CollectStyle(style
, paraStyle
, multipleStyleAttributes
);
2187 wxRichTextRange
paraRange(para
->GetRange());
2188 paraRange
.LimitTo(range
);
2190 // First collect paragraph attributes only
2191 wxTextAttrEx paraStyle
= para
->GetCombinedAttributes();
2192 paraStyle
.SetFlags(paraStyle
.GetFlags() & wxTEXT_ATTR_PARAGRAPH
);
2193 CollectStyle(style
, paraStyle
, multipleStyleAttributes
);
2195 wxRichTextObjectList::compatibility_iterator childNode
= para
->GetChildren().GetFirst();
2199 wxRichTextObject
* child
= childNode
->GetData();
2200 if (!(child
->GetRange().GetStart() > range
.GetEnd() || child
->GetRange().GetEnd() < range
.GetStart()))
2202 wxTextAttrEx childStyle
= para
->GetCombinedAttributes(child
->GetAttributes());
2204 // Now collect character attributes only
2205 childStyle
.SetFlags(childStyle
.GetFlags() & wxTEXT_ATTR_CHARACTER
);
2207 CollectStyle(style
, childStyle
, multipleStyleAttributes
);
2210 childNode
= childNode
->GetNext();
2214 node
= node
->GetNext();
2219 /// Set default style
2220 bool wxRichTextParagraphLayoutBox::SetDefaultStyle(const wxTextAttrEx
& style
)
2222 // I don't think the default style should be combined with the previous
2224 m_defaultAttributes
= style
;
2227 // keep the old attributes if the new style doesn't specify them unless the
2228 // new style is empty - then reset m_defaultStyle (as there is no other way
2230 if ( style
.IsDefault() )
2231 m_defaultAttributes
= style
;
2233 m_defaultAttributes
= wxTextAttrEx::CombineEx(style
, m_defaultAttributes
, NULL
);
2238 /// Test if this whole range has character attributes of the specified kind. If any
2239 /// of the attributes are different within the range, the test fails. You
2240 /// can use this to implement, for example, bold button updating. style must have
2241 /// flags indicating which attributes are of interest.
2242 bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
2245 int matchingCount
= 0;
2247 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
2250 wxRichTextParagraph
* para
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
2251 wxASSERT (para
!= NULL
);
2255 // Stop searching if we're beyond the range of interest
2256 if (para
->GetRange().GetStart() > range
.GetEnd())
2257 return foundCount
== matchingCount
;
2259 if (!para
->GetRange().IsOutside(range
))
2261 wxRichTextObjectList::compatibility_iterator node2
= para
->GetChildren().GetFirst();
2265 wxRichTextObject
* child
= node2
->GetData();
2266 if (!child
->GetRange().IsOutside(range
) && child
->IsKindOf(CLASSINFO(wxRichTextPlainText
)))
2269 #if wxRICHTEXT_USE_DYNAMIC_STYLES
2270 wxTextAttrEx textAttr
= para
->GetCombinedAttributes(child
->GetAttributes());
2272 const wxTextAttrEx
& textAttr
= child
->GetAttributes();
2274 if (wxTextAttrEqPartial(textAttr
, style
, style
.GetFlags()))
2278 node2
= node2
->GetNext();
2283 node
= node
->GetNext();
2286 return foundCount
== matchingCount
;
2289 bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
2291 wxRichTextAttr richStyle
= style
;
2292 return HasCharacterAttributes(range
, richStyle
);
2295 /// Test if this whole range has paragraph attributes of the specified kind. If any
2296 /// of the attributes are different within the range, the test fails. You
2297 /// can use this to implement, for example, centering button updating. style must have
2298 /// flags indicating which attributes are of interest.
2299 bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange
& range
, const wxRichTextAttr
& style
) const
2302 int matchingCount
= 0;
2304 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
2307 wxRichTextParagraph
* para
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
2308 wxASSERT (para
!= NULL
);
2312 // Stop searching if we're beyond the range of interest
2313 if (para
->GetRange().GetStart() > range
.GetEnd())
2314 return foundCount
== matchingCount
;
2316 if (!para
->GetRange().IsOutside(range
))
2318 #if wxRICHTEXT_USE_DYNAMIC_STYLES
2319 wxTextAttrEx textAttr
= GetAttributes();
2320 // Apply the paragraph style
2321 wxRichTextApplyStyle(textAttr
, para
->GetAttributes());
2324 const wxTextAttrEx
& textAttr
= para
->GetAttributes();
2327 if (wxTextAttrEqPartial(textAttr
, style
, style
.GetFlags()))
2332 node
= node
->GetNext();
2334 return foundCount
== matchingCount
;
2337 bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange
& range
, const wxTextAttrEx
& style
) const
2339 wxRichTextAttr richStyle
= style
;
2340 return HasParagraphAttributes(range
, richStyle
);
2343 void wxRichTextParagraphLayoutBox::Clear()
2348 void wxRichTextParagraphLayoutBox::Reset()
2352 AddParagraph(wxEmptyString
);
2355 /// Invalidate the buffer. With no argument, invalidates whole buffer.
2356 void wxRichTextParagraphLayoutBox::Invalidate(const wxRichTextRange
& invalidRange
)
2360 if (invalidRange
== wxRICHTEXT_ALL
)
2362 m_invalidRange
= wxRICHTEXT_ALL
;
2366 // Already invalidating everything
2367 if (m_invalidRange
== wxRICHTEXT_ALL
)
2370 if ((invalidRange
.GetStart() < m_invalidRange
.GetStart()) || m_invalidRange
.GetStart() == -1)
2371 m_invalidRange
.SetStart(invalidRange
.GetStart());
2372 if (invalidRange
.GetEnd() > m_invalidRange
.GetEnd())
2373 m_invalidRange
.SetEnd(invalidRange
.GetEnd());
2376 /// Get invalid range, rounding to entire paragraphs if argument is true.
2377 wxRichTextRange
wxRichTextParagraphLayoutBox::GetInvalidRange(bool wholeParagraphs
) const
2379 if (m_invalidRange
== wxRICHTEXT_ALL
|| m_invalidRange
== wxRICHTEXT_NONE
)
2380 return m_invalidRange
;
2382 wxRichTextRange range
= m_invalidRange
;
2384 if (wholeParagraphs
)
2386 wxRichTextParagraph
* para1
= GetParagraphAtPosition(range
.GetStart());
2387 wxRichTextParagraph
* para2
= GetParagraphAtPosition(range
.GetEnd());
2389 range
.SetStart(para1
->GetRange().GetStart());
2391 range
.SetEnd(para2
->GetRange().GetEnd());
2396 /// Apply the style sheet to the buffer, for example if the styles have changed.
2397 bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet
* styleSheet
)
2399 wxASSERT(styleSheet
!= NULL
);
2405 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
2408 wxRichTextParagraph
* para
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
2409 wxASSERT (para
!= NULL
);
2413 if (!para
->GetAttributes().GetParagraphStyleName().IsEmpty())
2415 wxRichTextParagraphStyleDefinition
* def
= styleSheet
->FindParagraphStyle(para
->GetAttributes().GetParagraphStyleName());
2418 para
->GetAttributes() = def
->GetStyle();
2424 node
= node
->GetNext();
2426 return foundCount
!= 0;
2430 * wxRichTextParagraph
2431 * This object represents a single paragraph (or in a straight text editor, a line).
2434 IMPLEMENT_DYNAMIC_CLASS(wxRichTextParagraph
, wxRichTextBox
)
2436 wxArrayInt
wxRichTextParagraph::sm_defaultTabs
;
2438 wxRichTextParagraph::wxRichTextParagraph(wxRichTextObject
* parent
, wxTextAttrEx
* style
):
2439 wxRichTextBox(parent
)
2441 if (parent
&& !style
)
2442 SetAttributes(parent
->GetAttributes());
2444 SetAttributes(*style
);
2447 wxRichTextParagraph::wxRichTextParagraph(const wxString
& text
, wxRichTextObject
* parent
, wxTextAttrEx
* style
):
2448 wxRichTextBox(parent
)
2450 if (parent
&& !style
)
2451 SetAttributes(parent
->GetAttributes());
2453 SetAttributes(*style
);
2455 AppendChild(new wxRichTextPlainText(text
, this));
2458 wxRichTextParagraph::~wxRichTextParagraph()
2464 bool wxRichTextParagraph::Draw(wxDC
& dc
, const wxRichTextRange
& WXUNUSED(range
), const wxRichTextRange
& selectionRange
, const wxRect
& WXUNUSED(rect
), int WXUNUSED(descent
), int style
)
2466 #if wxRICHTEXT_USE_DYNAMIC_STYLES
2467 wxTextAttrEx attr
= GetCombinedAttributes();
2469 const wxTextAttrEx
& attr
= GetAttributes();
2472 // Draw the bullet, if any
2473 if (attr
.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE
)
2475 if (attr
.GetLeftSubIndent() != 0)
2477 int spaceBeforePara
= ConvertTenthsMMToPixels(dc
, attr
.GetParagraphSpacingBefore());
2478 int leftIndent
= ConvertTenthsMMToPixels(dc
, attr
.GetLeftIndent());
2480 if (attr
.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_BITMAP
)
2486 wxString bulletText
= GetBulletText();
2487 if (!bulletText
.empty())
2489 // Get the combined font, or if a font is specified for a symbol bullet,
2492 wxTextAttrEx
bulletAttr(GetCombinedAttributes());
2494 if ((attr
.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL
) && !attr
.GetBulletFont().IsEmpty() && bulletAttr
.GetFont().Ok())
2496 font
= (*wxTheFontList
->FindOrCreateFont(bulletAttr
.GetFont().GetPointSize(), bulletAttr
.GetFont().GetFamily(),
2497 bulletAttr
.GetFont().GetStyle(), bulletAttr
.GetFont().GetWeight(), bulletAttr
.GetFont().GetUnderlined(),
2498 attr
.GetBulletFont()));
2500 else if (bulletAttr
.GetFont().Ok())
2501 font
= bulletAttr
.GetFont();
2503 font
= (*wxNORMAL_FONT
);
2507 if (bulletAttr
.GetTextColour().Ok())
2508 dc
.SetTextForeground(bulletAttr
.GetTextColour());
2510 dc
.SetBackgroundMode(wxTRANSPARENT
);
2512 // Get line height from first line, if any
2513 wxRichTextLine
* line
= m_cachedLines
.GetFirst() ? (wxRichTextLine
* ) m_cachedLines
.GetFirst()->GetData() : (wxRichTextLine
*) NULL
;
2516 int lineHeight
wxDUMMY_INITIALIZE(0);
2519 lineHeight
= line
->GetSize().y
;
2520 linePos
= line
->GetPosition() + GetPosition();
2524 lineHeight
= dc
.GetCharHeight();
2525 linePos
= GetPosition();
2526 linePos
.y
+= spaceBeforePara
;
2529 int charHeight
= dc
.GetCharHeight();
2531 int x
= GetPosition().x
+ leftIndent
;
2532 int y
= linePos
.y
+ (lineHeight
- charHeight
);
2534 dc
.DrawText(bulletText
, x
, y
);
2540 // Draw the range for each line, one object at a time.
2542 wxRichTextLineList::compatibility_iterator node
= m_cachedLines
.GetFirst();
2545 wxRichTextLine
* line
= node
->GetData();
2546 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2548 int maxDescent
= line
->GetDescent();
2550 // Lines are specified relative to the paragraph
2552 wxPoint linePosition
= line
->GetPosition() + GetPosition();
2553 wxPoint objectPosition
= linePosition
;
2555 // Loop through objects until we get to the one within range
2556 wxRichTextObjectList::compatibility_iterator node2
= m_children
.GetFirst();
2559 wxRichTextObject
* child
= node2
->GetData();
2560 if (!child
->GetRange().IsOutside(lineRange
))
2562 // Draw this part of the line at the correct position
2563 wxRichTextRange
objectRange(child
->GetRange());
2564 objectRange
.LimitTo(lineRange
);
2568 child
->GetRangeSize(objectRange
, objectSize
, descent
, dc
, wxRICHTEXT_UNFORMATTED
, objectPosition
);
2570 // Use the child object's width, but the whole line's height
2571 wxRect
childRect(objectPosition
, wxSize(objectSize
.x
, line
->GetSize().y
));
2572 child
->Draw(dc
, objectRange
, selectionRange
, childRect
, maxDescent
, style
);
2574 objectPosition
.x
+= objectSize
.x
;
2576 else if (child
->GetRange().GetStart() > lineRange
.GetEnd())
2577 // Can break out of inner loop now since we've passed this line's range
2580 node2
= node2
->GetNext();
2583 node
= node
->GetNext();
2589 /// Lay the item out
2590 bool wxRichTextParagraph::Layout(wxDC
& dc
, const wxRect
& rect
, int style
)
2592 #if wxRICHTEXT_USE_DYNAMIC_STYLES
2593 wxTextAttrEx attr
= GetCombinedAttributes();
2595 const wxTextAttrEx
& attr
= GetAttributes();
2600 // Increase the size of the paragraph due to spacing
2601 int spaceBeforePara
= ConvertTenthsMMToPixels(dc
, attr
.GetParagraphSpacingBefore());
2602 int spaceAfterPara
= ConvertTenthsMMToPixels(dc
, attr
.GetParagraphSpacingAfter());
2603 int leftIndent
= ConvertTenthsMMToPixels(dc
, attr
.GetLeftIndent());
2604 int leftSubIndent
= ConvertTenthsMMToPixels(dc
, attr
.GetLeftSubIndent());
2605 int rightIndent
= ConvertTenthsMMToPixels(dc
, attr
.GetRightIndent());
2607 int lineSpacing
= 0;
2609 // Let's assume line spacing of 10 is normal, 15 is 1.5, 20 is 2, etc.
2610 if (attr
.GetLineSpacing() > 10 && attr
.GetFont().Ok())
2612 dc
.SetFont(attr
.GetFont());
2613 lineSpacing
= (ConvertTenthsMMToPixels(dc
, dc
.GetCharHeight()) * attr
.GetLineSpacing())/10;
2616 // Available space for text on each line differs.
2617 int availableTextSpaceFirstLine
= rect
.GetWidth() - leftIndent
- rightIndent
;
2619 // Bullets start the text at the same position as subsequent lines
2620 if (attr
.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE
)
2621 availableTextSpaceFirstLine
-= leftSubIndent
;
2623 int availableTextSpaceSubsequentLines
= rect
.GetWidth() - leftIndent
- rightIndent
- leftSubIndent
;
2625 // Start position for each line relative to the paragraph
2626 int startPositionFirstLine
= leftIndent
;
2627 int startPositionSubsequentLines
= leftIndent
+ leftSubIndent
;
2629 // If we have a bullet in this paragraph, the start position for the first line's text
2630 // is actually leftIndent + leftSubIndent.
2631 if (attr
.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE
)
2632 startPositionFirstLine
= startPositionSubsequentLines
;
2634 long lastEndPos
= GetRange().GetStart()-1;
2635 long lastCompletedEndPos
= lastEndPos
;
2637 int currentWidth
= 0;
2638 SetPosition(rect
.GetPosition());
2640 wxPoint
currentPosition(0, spaceBeforePara
); // We will calculate lines relative to paragraph
2649 // We may need to go back to a previous child, in which case create the new line,
2650 // find the child corresponding to the start position of the string, and
2653 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
2656 wxRichTextObject
* child
= node
->GetData();
2658 // If this is e.g. a composite text box, it will need to be laid out itself.
2659 // But if just a text fragment or image, for example, this will
2660 // do nothing. NB: won't we need to set the position after layout?
2661 // since for example if position is dependent on vertical line size, we
2662 // can't tell the position until the size is determined. So possibly introduce
2663 // another layout phase.
2665 child
->Layout(dc
, rect
, style
);
2667 // Available width depends on whether we're on the first or subsequent lines
2668 int availableSpaceForText
= (lineCount
== 0 ? availableTextSpaceFirstLine
: availableTextSpaceSubsequentLines
);
2670 currentPosition
.x
= (lineCount
== 0 ? startPositionFirstLine
: startPositionSubsequentLines
);
2672 // We may only be looking at part of a child, if we searched back for wrapping
2673 // and found a suitable point some way into the child. So get the size for the fragment
2677 int childDescent
= 0;
2678 if (lastEndPos
== child
->GetRange().GetStart() - 1)
2680 childSize
= child
->GetCachedSize();
2681 childDescent
= child
->GetDescent();
2684 GetRangeSize(wxRichTextRange(lastEndPos
+1, child
->GetRange().GetEnd()), childSize
, childDescent
, dc
, wxRICHTEXT_UNFORMATTED
,rect
.GetPosition());
2686 if (childSize
.x
+ currentWidth
> availableSpaceForText
)
2688 long wrapPosition
= 0;
2690 // Find a place to wrap. This may walk back to previous children,
2691 // for example if a word spans several objects.
2692 if (!FindWrapPosition(wxRichTextRange(lastCompletedEndPos
+1, child
->GetRange().GetEnd()), dc
, availableSpaceForText
, wrapPosition
))
2694 // If the function failed, just cut it off at the end of this child.
2695 wrapPosition
= child
->GetRange().GetEnd();
2698 // FindWrapPosition can still return a value that will put us in an endless wrapping loop
2699 if (wrapPosition
<= lastCompletedEndPos
)
2700 wrapPosition
= wxMax(lastCompletedEndPos
+1,child
->GetRange().GetEnd());
2702 // wxLogDebug(wxT("Split at %ld"), wrapPosition);
2704 // Let's find the actual size of the current line now
2706 wxRichTextRange
actualRange(lastCompletedEndPos
+1, wrapPosition
);
2707 GetRangeSize(actualRange
, actualSize
, childDescent
, dc
, wxRICHTEXT_UNFORMATTED
);
2708 currentWidth
= actualSize
.x
;
2709 lineHeight
= wxMax(lineHeight
, actualSize
.y
);
2710 maxDescent
= wxMax(childDescent
, maxDescent
);
2713 wxRichTextLine
* line
= AllocateLine(lineCount
);
2715 // Set relative range so we won't have to change line ranges when paragraphs are moved
2716 line
->SetRange(wxRichTextRange(actualRange
.GetStart() - GetRange().GetStart(), actualRange
.GetEnd() - GetRange().GetStart()));
2717 line
->SetPosition(currentPosition
);
2718 line
->SetSize(wxSize(currentWidth
, lineHeight
));
2719 line
->SetDescent(maxDescent
);
2721 // Now move down a line. TODO: add margins, spacing
2722 currentPosition
.y
+= lineHeight
;
2723 currentPosition
.y
+= lineSpacing
;
2726 maxWidth
= wxMax(maxWidth
, currentWidth
);
2730 // TODO: account for zero-length objects, such as fields
2731 wxASSERT(wrapPosition
> lastCompletedEndPos
);
2733 lastEndPos
= wrapPosition
;
2734 lastCompletedEndPos
= lastEndPos
;
2738 // May need to set the node back to a previous one, due to searching back in wrapping
2739 wxRichTextObject
* childAfterWrapPosition
= FindObjectAtPosition(wrapPosition
+1);
2740 if (childAfterWrapPosition
)
2741 node
= m_children
.Find(childAfterWrapPosition
);
2743 node
= node
->GetNext();
2747 // We still fit, so don't add a line, and keep going
2748 currentWidth
+= childSize
.x
;
2749 lineHeight
= wxMax(lineHeight
, childSize
.y
);
2750 maxDescent
= wxMax(childDescent
, maxDescent
);
2752 maxWidth
= wxMax(maxWidth
, currentWidth
);
2753 lastEndPos
= child
->GetRange().GetEnd();
2755 node
= node
->GetNext();
2759 // Add the last line - it's the current pos -> last para pos
2760 // Substract -1 because the last position is always the end-paragraph position.
2761 if (lastCompletedEndPos
<= GetRange().GetEnd()-1)
2763 currentPosition
.x
= (lineCount
== 0 ? startPositionFirstLine
: startPositionSubsequentLines
);
2765 wxRichTextLine
* line
= AllocateLine(lineCount
);
2767 wxRichTextRange
actualRange(lastCompletedEndPos
+1, GetRange().GetEnd()-1);
2769 // Set relative range so we won't have to change line ranges when paragraphs are moved
2770 line
->SetRange(wxRichTextRange(actualRange
.GetStart() - GetRange().GetStart(), actualRange
.GetEnd() - GetRange().GetStart()));
2772 line
->SetPosition(currentPosition
);
2774 if (lineHeight
== 0)
2776 if (attr
.GetFont().Ok())
2777 dc
.SetFont(attr
.GetFont());
2778 lineHeight
= dc
.GetCharHeight();
2780 if (maxDescent
== 0)
2783 dc
.GetTextExtent(wxT("X"), & w
, &h
, & maxDescent
);
2786 line
->SetSize(wxSize(currentWidth
, lineHeight
));
2787 line
->SetDescent(maxDescent
);
2788 currentPosition
.y
+= lineHeight
;
2789 currentPosition
.y
+= lineSpacing
;
2793 // Remove remaining unused line objects, if any
2794 ClearUnusedLines(lineCount
);
2796 // Apply styles to wrapped lines
2797 ApplyParagraphStyle(attr
, rect
);
2799 SetCachedSize(wxSize(maxWidth
, currentPosition
.y
+ spaceBeforePara
+ spaceAfterPara
));
2806 /// Apply paragraph styles, such as centering, to wrapped lines
2807 void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttrEx
& attr
, const wxRect
& rect
)
2809 if (!attr
.HasAlignment())
2812 wxRichTextLineList::compatibility_iterator node
= m_cachedLines
.GetFirst();
2815 wxRichTextLine
* line
= node
->GetData();
2817 wxPoint pos
= line
->GetPosition();
2818 wxSize size
= line
->GetSize();
2820 // centering, right-justification
2821 if (attr
.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE
)
2823 pos
.x
= (rect
.GetWidth() - size
.x
)/2 + pos
.x
;
2824 line
->SetPosition(pos
);
2826 else if (attr
.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_RIGHT
)
2828 pos
.x
= rect
.GetRight() - size
.x
;
2829 line
->SetPosition(pos
);
2832 node
= node
->GetNext();
2836 /// Insert text at the given position
2837 bool wxRichTextParagraph::InsertText(long pos
, const wxString
& text
)
2839 wxRichTextObject
* childToUse
= NULL
;
2840 wxRichTextObjectList::compatibility_iterator nodeToUse
= wxRichTextObjectList::compatibility_iterator();
2842 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
2845 wxRichTextObject
* child
= node
->GetData();
2846 if (child
->GetRange().Contains(pos
) && child
->GetRange().GetLength() > 0)
2853 node
= node
->GetNext();
2858 wxRichTextPlainText
* textObject
= wxDynamicCast(childToUse
, wxRichTextPlainText
);
2861 int posInString
= pos
- textObject
->GetRange().GetStart();
2863 wxString newText
= textObject
->GetText().Mid(0, posInString
) +
2864 text
+ textObject
->GetText().Mid(posInString
);
2865 textObject
->SetText(newText
);
2867 int textLength
= text
.length();
2869 textObject
->SetRange(wxRichTextRange(textObject
->GetRange().GetStart(),
2870 textObject
->GetRange().GetEnd() + textLength
));
2872 // Increment the end range of subsequent fragments in this paragraph.
2873 // We'll set the paragraph range itself at a higher level.
2875 wxRichTextObjectList::compatibility_iterator node
= nodeToUse
->GetNext();
2878 wxRichTextObject
* child
= node
->GetData();
2879 child
->SetRange(wxRichTextRange(textObject
->GetRange().GetStart() + textLength
,
2880 textObject
->GetRange().GetEnd() + textLength
));
2882 node
= node
->GetNext();
2889 // TODO: if not a text object, insert at closest position, e.g. in front of it
2895 // Don't pass parent initially to suppress auto-setting of parent range.
2896 // We'll do that at a higher level.
2897 wxRichTextPlainText
* textObject
= new wxRichTextPlainText(text
, this);
2899 AppendChild(textObject
);
2906 void wxRichTextParagraph::Copy(const wxRichTextParagraph
& obj
)
2908 wxRichTextBox::Copy(obj
);
2911 /// Clear the cached lines
2912 void wxRichTextParagraph::ClearLines()
2914 WX_CLEAR_LIST(wxRichTextLineList
, m_cachedLines
);
2917 /// Get/set the object size for the given range. Returns false if the range
2918 /// is invalid for this object.
2919 bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int flags
, wxPoint position
) const
2921 if (!range
.IsWithin(GetRange()))
2924 if (flags
& wxRICHTEXT_UNFORMATTED
)
2926 // Just use unformatted data, assume no line breaks
2927 // TODO: take into account line breaks
2931 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
2934 wxRichTextObject
* child
= node
->GetData();
2935 if (!child
->GetRange().IsOutside(range
))
2939 wxRichTextRange rangeToUse
= range
;
2940 rangeToUse
.LimitTo(child
->GetRange());
2941 int childDescent
= 0;
2943 if (child
->GetRangeSize(rangeToUse
, childSize
, childDescent
, dc
, flags
, position
))
2945 sz
.y
= wxMax(sz
.y
, childSize
.y
);
2946 sz
.x
+= childSize
.x
;
2947 descent
= wxMax(descent
, childDescent
);
2951 node
= node
->GetNext();
2957 // Use formatted data, with line breaks
2960 // We're going to loop through each line, and then for each line,
2961 // call GetRangeSize for the fragment that comprises that line.
2962 // Only we have to do that multiple times within the line, because
2963 // the line may be broken into pieces. For now ignore line break commands
2964 // (so we can assume that getting the unformatted size for a fragment
2965 // within a line is the actual size)
2967 wxRichTextLineList::compatibility_iterator node
= m_cachedLines
.GetFirst();
2970 wxRichTextLine
* line
= node
->GetData();
2971 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
2972 if (!lineRange
.IsOutside(range
))
2976 wxRichTextObjectList::compatibility_iterator node2
= m_children
.GetFirst();
2979 wxRichTextObject
* child
= node2
->GetData();
2981 if (!child
->GetRange().IsOutside(lineRange
))
2983 wxRichTextRange rangeToUse
= lineRange
;
2984 rangeToUse
.LimitTo(child
->GetRange());
2987 int childDescent
= 0;
2988 if (child
->GetRangeSize(rangeToUse
, childSize
, childDescent
, dc
, flags
, position
))
2990 lineSize
.y
= wxMax(lineSize
.y
, childSize
.y
);
2991 lineSize
.x
+= childSize
.x
;
2993 descent
= wxMax(descent
, childDescent
);
2996 node2
= node2
->GetNext();
2999 // Increase size by a line (TODO: paragraph spacing)
3001 sz
.x
= wxMax(sz
.x
, lineSize
.x
);
3003 node
= node
->GetNext();
3010 /// Finds the absolute position and row height for the given character position
3011 bool wxRichTextParagraph::FindPosition(wxDC
& dc
, long index
, wxPoint
& pt
, int* height
, bool forceLineStart
)
3015 wxRichTextLine
* line
= ((wxRichTextParagraphLayoutBox
*)GetParent())->GetLineAtPosition(0);
3017 *height
= line
->GetSize().y
;
3019 *height
= dc
.GetCharHeight();
3021 // -1 means 'the start of the buffer'.
3024 pt
= pt
+ line
->GetPosition();
3029 // The final position in a paragraph is taken to mean the position
3030 // at the start of the next paragraph.
3031 if (index
== GetRange().GetEnd())
3033 wxRichTextParagraphLayoutBox
* parent
= wxDynamicCast(GetParent(), wxRichTextParagraphLayoutBox
);
3034 wxASSERT( parent
!= NULL
);
3036 // Find the height at the next paragraph, if any
3037 wxRichTextLine
* line
= parent
->GetLineAtPosition(index
+ 1);
3040 *height
= line
->GetSize().y
;
3041 pt
= line
->GetAbsolutePosition();
3045 *height
= dc
.GetCharHeight();
3046 int indent
= ConvertTenthsMMToPixels(dc
, m_attributes
.GetLeftIndent());
3047 pt
= wxPoint(indent
, GetCachedSize().y
);
3053 if (index
< GetRange().GetStart() || index
> GetRange().GetEnd())
3056 wxRichTextLineList::compatibility_iterator node
= m_cachedLines
.GetFirst();
3059 wxRichTextLine
* line
= node
->GetData();
3060 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
3061 if (index
>= lineRange
.GetStart() && index
<= lineRange
.GetEnd())
3063 // If this is the last point in the line, and we're forcing the
3064 // returned value to be the start of the next line, do the required
3066 if (index
== lineRange
.GetEnd() && forceLineStart
)
3068 if (node
->GetNext())
3070 wxRichTextLine
* nextLine
= node
->GetNext()->GetData();
3071 *height
= nextLine
->GetSize().y
;
3072 pt
= nextLine
->GetAbsolutePosition();
3077 pt
.y
= line
->GetPosition().y
+ GetPosition().y
;
3079 wxRichTextRange
r(lineRange
.GetStart(), index
);
3083 // We find the size of the line up to this point,
3084 // then we can add this size to the line start position and
3085 // paragraph start position to find the actual position.
3087 if (GetRangeSize(r
, rangeSize
, descent
, dc
, wxRICHTEXT_UNFORMATTED
, line
->GetPosition()+ GetPosition()))
3089 pt
.x
= line
->GetPosition().x
+ GetPosition().x
+ rangeSize
.x
;
3090 *height
= line
->GetSize().y
;
3097 node
= node
->GetNext();
3103 /// Hit-testing: returns a flag indicating hit test details, plus
3104 /// information about position
3105 int wxRichTextParagraph::HitTest(wxDC
& dc
, const wxPoint
& pt
, long& textPosition
)
3107 wxPoint paraPos
= GetPosition();
3109 wxRichTextLineList::compatibility_iterator node
= m_cachedLines
.GetFirst();
3112 wxRichTextLine
* line
= node
->GetData();
3113 wxPoint linePos
= paraPos
+ line
->GetPosition();
3114 wxSize lineSize
= line
->GetSize();
3115 wxRichTextRange lineRange
= line
->GetAbsoluteRange();
3117 if (pt
.y
>= linePos
.y
&& pt
.y
<= linePos
.y
+ lineSize
.y
)
3119 if (pt
.x
< linePos
.x
)
3121 textPosition
= lineRange
.GetStart();
3122 return wxRICHTEXT_HITTEST_BEFORE
;
3124 else if (pt
.x
>= (linePos
.x
+ lineSize
.x
))
3126 textPosition
= lineRange
.GetEnd();
3127 return wxRICHTEXT_HITTEST_AFTER
;
3132 int lastX
= linePos
.x
;
3133 for (i
= lineRange
.GetStart(); i
<= lineRange
.GetEnd(); i
++)
3138 wxRichTextRange
rangeToUse(lineRange
.GetStart(), i
);
3140 GetRangeSize(rangeToUse
, childSize
, descent
, dc
, wxRICHTEXT_UNFORMATTED
, linePos
);
3142 int nextX
= childSize
.x
+ linePos
.x
;
3144 if (pt
.x
>= lastX
&& pt
.x
<= nextX
)
3148 // So now we know it's between i-1 and i.
3149 // Let's see if we can be more precise about
3150 // which side of the position it's on.
3152 int midPoint
= (nextX
- lastX
)/2 + lastX
;
3153 if (pt
.x
>= midPoint
)
3154 return wxRICHTEXT_HITTEST_AFTER
;
3156 return wxRICHTEXT_HITTEST_BEFORE
;
3166 node
= node
->GetNext();
3169 return wxRICHTEXT_HITTEST_NONE
;
3172 /// Split an object at this position if necessary, and return
3173 /// the previous object, or NULL if inserting at beginning.
3174 wxRichTextObject
* wxRichTextParagraph::SplitAt(long pos
, wxRichTextObject
** previousObject
)
3176 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
3179 wxRichTextObject
* child
= node
->GetData();
3181 if (pos
== child
->GetRange().GetStart())
3185 if (node
->GetPrevious())
3186 *previousObject
= node
->GetPrevious()->GetData();
3188 *previousObject
= NULL
;
3194 if (child
->GetRange().Contains(pos
))
3196 // This should create a new object, transferring part of
3197 // the content to the old object and the rest to the new object.
3198 wxRichTextObject
* newObject
= child
->DoSplit(pos
);
3200 // If we couldn't split this object, just insert in front of it.
3203 // Maybe this is an empty string, try the next one
3208 // Insert the new object after 'child'
3209 if (node
->GetNext())
3210 m_children
.Insert(node
->GetNext(), newObject
);
3212 m_children
.Append(newObject
);
3213 newObject
->SetParent(this);
3216 *previousObject
= child
;
3222 node
= node
->GetNext();
3225 *previousObject
= NULL
;
3229 /// Move content to a list from obj on
3230 void wxRichTextParagraph::MoveToList(wxRichTextObject
* obj
, wxList
& list
)
3232 wxRichTextObjectList::compatibility_iterator node
= m_children
.Find(obj
);
3235 wxRichTextObject
* child
= node
->GetData();
3238 wxRichTextObjectList::compatibility_iterator oldNode
= node
;
3240 node
= node
->GetNext();
3242 m_children
.DeleteNode(oldNode
);
3246 /// Add content back from list
3247 void wxRichTextParagraph::MoveFromList(wxList
& list
)
3249 for (wxList::compatibility_iterator node
= list
.GetFirst(); node
; node
= node
->GetNext())
3251 AppendChild((wxRichTextObject
*) node
->GetData());
3256 void wxRichTextParagraph::CalculateRange(long start
, long& end
)
3258 wxRichTextCompositeObject::CalculateRange(start
, end
);
3260 // Add one for end of paragraph
3263 m_range
.SetRange(start
, end
);
3266 /// Find the object at the given position
3267 wxRichTextObject
* wxRichTextParagraph::FindObjectAtPosition(long position
)
3269 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
3272 wxRichTextObject
* obj
= node
->GetData();
3273 if (obj
->GetRange().Contains(position
))
3276 node
= node
->GetNext();
3281 /// Get the plain text searching from the start or end of the range.
3282 /// The resulting string may be shorter than the range given.
3283 bool wxRichTextParagraph::GetContiguousPlainText(wxString
& text
, const wxRichTextRange
& range
, bool fromStart
)
3285 text
= wxEmptyString
;
3289 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetFirst();
3292 wxRichTextObject
* obj
= node
->GetData();
3293 if (!obj
->GetRange().IsOutside(range
))
3295 wxRichTextPlainText
* textObj
= wxDynamicCast(obj
, wxRichTextPlainText
);
3298 text
+= textObj
->GetTextForRange(range
);
3304 node
= node
->GetNext();
3309 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetLast();
3312 wxRichTextObject
* obj
= node
->GetData();
3313 if (!obj
->GetRange().IsOutside(range
))
3315 wxRichTextPlainText
* textObj
= wxDynamicCast(obj
, wxRichTextPlainText
);
3318 text
= textObj
->GetTextForRange(range
) + text
;
3324 node
= node
->GetPrevious();
3331 /// Find a suitable wrap position.
3332 bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange
& range
, wxDC
& dc
, int availableSpace
, long& wrapPosition
)
3334 // Find the first position where the line exceeds the available space.
3337 long breakPosition
= range
.GetEnd();
3338 for (i
= range
.GetStart(); i
<= range
.GetEnd(); i
++)
3341 GetRangeSize(wxRichTextRange(range
.GetStart(), i
), sz
, descent
, dc
, wxRICHTEXT_UNFORMATTED
);
3343 if (sz
.x
> availableSpace
)
3345 breakPosition
= i
-1;
3350 // Now we know the last position on the line.
3351 // Let's try to find a word break.
3354 if (GetContiguousPlainText(plainText
, wxRichTextRange(range
.GetStart(), breakPosition
), false))
3356 int spacePos
= plainText
.Find(wxT(' '), true);
3357 if (spacePos
!= wxNOT_FOUND
)
3359 int positionsFromEndOfString
= plainText
.length() - spacePos
- 1;
3360 breakPosition
= breakPosition
- positionsFromEndOfString
;
3364 wrapPosition
= breakPosition
;
3369 /// Get the bullet text for this paragraph.
3370 wxString
wxRichTextParagraph::GetBulletText()
3372 if (GetAttributes().GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_NONE
||
3373 (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_BITMAP
))
3374 return wxEmptyString
;
3376 int number
= GetAttributes().GetBulletNumber();
3379 if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ARABIC
)
3381 text
.Printf(wxT("%d"), number
);
3383 else if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_LETTERS_UPPER
)
3385 // TODO: Unicode, and also check if number > 26
3386 text
.Printf(wxT("%c"), (wxChar
) (number
+64));
3388 else if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_LETTERS_LOWER
)
3390 // TODO: Unicode, and also check if number > 26
3391 text
.Printf(wxT("%c"), (wxChar
) (number
+96));
3393 else if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ROMAN_UPPER
)
3395 text
= wxRichTextDecimalToRoman(number
);
3397 else if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ROMAN_LOWER
)
3399 text
= wxRichTextDecimalToRoman(number
);
3402 else if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL
)
3404 text
= GetAttributes().GetBulletSymbol();
3407 if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_PARENTHESES
)
3409 text
= wxT("(") + text
+ wxT(")");
3411 if (GetAttributes().GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_PERIOD
)
3419 /// Allocate or reuse a line object
3420 wxRichTextLine
* wxRichTextParagraph::AllocateLine(int pos
)
3422 if (pos
< (int) m_cachedLines
.GetCount())
3424 wxRichTextLine
* line
= m_cachedLines
.Item(pos
)->GetData();
3430 wxRichTextLine
* line
= new wxRichTextLine(this);
3431 m_cachedLines
.Append(line
);
3436 /// Clear remaining unused line objects, if any
3437 bool wxRichTextParagraph::ClearUnusedLines(int lineCount
)
3439 int cachedLineCount
= m_cachedLines
.GetCount();
3440 if ((int) cachedLineCount
> lineCount
)
3442 for (int i
= 0; i
< (int) (cachedLineCount
- lineCount
); i
++)
3444 wxRichTextLineList::compatibility_iterator node
= m_cachedLines
.GetLast();
3445 wxRichTextLine
* line
= node
->GetData();
3446 m_cachedLines
.Erase(node
);
3453 /// Get combined attributes of the base style, paragraph style and character style. We use this to dynamically
3454 /// retrieve the actual style.
3455 wxTextAttrEx
wxRichTextParagraph::GetCombinedAttributes(const wxTextAttrEx
& contentStyle
) const
3458 wxRichTextBuffer
* buf
= wxDynamicCast(GetParent(), wxRichTextBuffer
);
3461 attr
= buf
->GetBasicStyle();
3462 wxRichTextApplyStyle(attr
, GetAttributes());
3465 attr
= GetAttributes();
3467 wxRichTextApplyStyle(attr
, contentStyle
);
3471 /// Get combined attributes of the base style and paragraph style.
3472 wxTextAttrEx
wxRichTextParagraph::GetCombinedAttributes() const
3475 wxRichTextBuffer
* buf
= wxDynamicCast(GetParent(), wxRichTextBuffer
);
3478 attr
= buf
->GetBasicStyle();
3479 wxRichTextApplyStyle(attr
, GetAttributes());
3482 attr
= GetAttributes();
3487 /// Create default tabstop array
3488 void wxRichTextParagraph::InitDefaultTabs()
3490 // create a default tab list at 10 mm each.
3491 for (int i
= 0; i
< 20; ++i
)
3493 sm_defaultTabs
.Add(i
*100);
3497 /// Clear default tabstop array
3498 void wxRichTextParagraph::ClearDefaultTabs()
3500 sm_defaultTabs
.Clear();
3506 * This object represents a line in a paragraph, and stores
3507 * offsets from the start of the paragraph representing the
3508 * start and end positions of the line.
3511 wxRichTextLine::wxRichTextLine(wxRichTextParagraph
* parent
)
3517 void wxRichTextLine::Init(wxRichTextParagraph
* parent
)
3520 m_range
.SetRange(-1, -1);
3521 m_pos
= wxPoint(0, 0);
3522 m_size
= wxSize(0, 0);
3527 void wxRichTextLine::Copy(const wxRichTextLine
& obj
)
3529 m_range
= obj
.m_range
;
3532 /// Get the absolute object position
3533 wxPoint
wxRichTextLine::GetAbsolutePosition() const
3535 return m_parent
->GetPosition() + m_pos
;
3538 /// Get the absolute range
3539 wxRichTextRange
wxRichTextLine::GetAbsoluteRange() const
3541 wxRichTextRange
range(m_range
.GetStart() + m_parent
->GetRange().GetStart(), 0);
3542 range
.SetEnd(range
.GetStart() + m_range
.GetLength()-1);
3547 * wxRichTextPlainText
3548 * This object represents a single piece of text.
3551 IMPLEMENT_DYNAMIC_CLASS(wxRichTextPlainText
, wxRichTextObject
)
3553 wxRichTextPlainText::wxRichTextPlainText(const wxString
& text
, wxRichTextObject
* parent
, wxTextAttrEx
* style
):
3554 wxRichTextObject(parent
)
3556 if (parent
&& !style
)
3557 SetAttributes(parent
->GetAttributes());
3559 SetAttributes(*style
);
3564 #define USE_KERNING_FIX 1
3567 bool wxRichTextPlainText::Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int descent
, int WXUNUSED(style
))
3569 #if wxRICHTEXT_USE_DYNAMIC_STYLES
3570 wxRichTextParagraph
* para
= wxDynamicCast(GetParent(), wxRichTextParagraph
);
3571 wxASSERT (para
!= NULL
);
3573 wxTextAttrEx
textAttr(para
? para
->GetCombinedAttributes(GetAttributes()) : GetAttributes());
3575 wxTextAttrEx
textAttr(GetAttributes());
3578 int offset
= GetRange().GetStart();
3580 long len
= range
.GetLength();
3581 wxString stringChunk
= m_text
.Mid(range
.GetStart() - offset
, (size_t) len
);
3583 int charHeight
= dc
.GetCharHeight();
3586 int y
= rect
.y
+ (rect
.height
- charHeight
- (descent
- m_descent
));
3588 // Test for the optimized situations where all is selected, or none
3591 if (textAttr
.GetFont().Ok())
3592 dc
.SetFont(textAttr
.GetFont());
3594 // (a) All selected.
3595 if (selectionRange
.GetStart() <= range
.GetStart() && selectionRange
.GetEnd() >= range
.GetEnd())
3597 DrawTabbedString(dc
, textAttr
, rect
, stringChunk
, x
, y
, true);
3599 // (b) None selected.
3600 else if (selectionRange
.GetEnd() < range
.GetStart() || selectionRange
.GetStart() > range
.GetEnd())
3602 // Draw all unselected
3603 DrawTabbedString(dc
, textAttr
, rect
, stringChunk
, x
, y
, false);
3607 // (c) Part selected, part not
3608 // Let's draw unselected chunk, selected chunk, then unselected chunk.
3610 dc
.SetBackgroundMode(wxTRANSPARENT
);
3612 // 1. Initial unselected chunk, if any, up until start of selection.
3613 if (selectionRange
.GetStart() > range
.GetStart() && selectionRange
.GetStart() <= range
.GetEnd())
3615 int r1
= range
.GetStart();
3616 int s1
= selectionRange
.GetStart()-1;
3617 int fragmentLen
= s1
- r1
+ 1;
3618 if (fragmentLen
< 0)
3619 wxLogDebug(wxT("Mid(%d, %d"), (int)(r1
- offset
), (int)fragmentLen
);
3620 wxString stringFragment
= m_text
.Mid(r1
- offset
, fragmentLen
);
3622 DrawTabbedString(dc
, textAttr
, rect
, stringFragment
, x
, y
, false);
3625 if (stringChunk
.Find(wxT("\t")) == wxNOT_FOUND
)
3627 // Compensate for kerning difference
3628 wxString
stringFragment2(m_text
.Mid(r1
- offset
, fragmentLen
+1));
3629 wxString
stringFragment3(m_text
.Mid(r1
- offset
+ fragmentLen
, 1));
3631 wxCoord w1
, h1
, w2
, h2
, w3
, h3
;
3632 dc
.GetTextExtent(stringFragment
, & w1
, & h1
);
3633 dc
.GetTextExtent(stringFragment2
, & w2
, & h2
);
3634 dc
.GetTextExtent(stringFragment3
, & w3
, & h3
);
3636 int kerningDiff
= (w1
+ w3
) - w2
;
3637 x
= x
- kerningDiff
;
3642 // 2. Selected chunk, if any.
3643 if (selectionRange
.GetEnd() >= range
.GetStart())
3645 int s1
= wxMax(selectionRange
.GetStart(), range
.GetStart());
3646 int s2
= wxMin(selectionRange
.GetEnd(), range
.GetEnd());
3648 int fragmentLen
= s2
- s1
+ 1;
3649 if (fragmentLen
< 0)
3650 wxLogDebug(wxT("Mid(%d, %d"), (int)(s1
- offset
), (int)fragmentLen
);
3651 wxString stringFragment
= m_text
.Mid(s1
- offset
, fragmentLen
);
3653 DrawTabbedString(dc
, textAttr
, rect
, stringFragment
, x
, y
, true);
3656 if (stringChunk
.Find(wxT("\t")) == wxNOT_FOUND
)
3658 // Compensate for kerning difference
3659 wxString
stringFragment2(m_text
.Mid(s1
- offset
, fragmentLen
+1));
3660 wxString
stringFragment3(m_text
.Mid(s1
- offset
+ fragmentLen
, 1));
3662 wxCoord w1
, h1
, w2
, h2
, w3
, h3
;
3663 dc
.GetTextExtent(stringFragment
, & w1
, & h1
);
3664 dc
.GetTextExtent(stringFragment2
, & w2
, & h2
);
3665 dc
.GetTextExtent(stringFragment3
, & w3
, & h3
);
3667 int kerningDiff
= (w1
+ w3
) - w2
;
3668 x
= x
- kerningDiff
;
3673 // 3. Remaining unselected chunk, if any
3674 if (selectionRange
.GetEnd() < range
.GetEnd())
3676 int s2
= wxMin(selectionRange
.GetEnd()+1, range
.GetEnd());
3677 int r2
= range
.GetEnd();
3679 int fragmentLen
= r2
- s2
+ 1;
3680 if (fragmentLen
< 0)
3681 wxLogDebug(wxT("Mid(%d, %d"), (int)(s2
- offset
), (int)fragmentLen
);
3682 wxString stringFragment
= m_text
.Mid(s2
- offset
, fragmentLen
);
3684 DrawTabbedString(dc
, textAttr
, rect
, stringFragment
, x
, y
, false);
3691 bool wxRichTextPlainText::DrawTabbedString(wxDC
& dc
, const wxTextAttrEx
& attr
, const wxRect
& rect
,wxString
& str
, wxCoord
& x
, wxCoord
& y
, bool selected
)
3693 bool hasTabs
= (str
.Find(wxT('\t')) != wxNOT_FOUND
);
3695 wxArrayInt tabArray
;
3699 if (attr
.GetTabs().IsEmpty())
3700 tabArray
= wxRichTextParagraph::GetDefaultTabs();
3702 tabArray
= attr
.GetTabs();
3703 tabCount
= tabArray
.GetCount();
3705 for (int i
= 0; i
< tabCount
; ++i
)
3707 int pos
= tabArray
[i
];
3708 pos
= ConvertTenthsMMToPixels(dc
, pos
);
3715 int nextTabPos
= -1;
3721 dc
.SetBrush(*wxBLACK_BRUSH
);
3722 dc
.SetPen(*wxBLACK_PEN
);
3723 dc
.SetTextForeground(*wxWHITE
);
3724 dc
.SetBackgroundMode(wxTRANSPARENT
);
3728 dc
.SetTextForeground(attr
.GetTextColour());
3729 dc
.SetBackgroundMode(wxTRANSPARENT
);
3734 // the string has a tab
3735 // break up the string at the Tab
3736 wxString stringChunk
= str
.BeforeFirst(wxT('\t'));
3737 str
= str
.AfterFirst(wxT('\t'));
3738 dc
.GetTextExtent(stringChunk
, & w
, & h
);
3740 bool not_found
= true;
3741 for (int i
= 0; i
< tabCount
&& not_found
; ++i
)
3743 nextTabPos
= tabArray
.Item(i
);
3744 if (nextTabPos
> tabPos
)
3750 wxRect
selRect(x
, rect
.y
, w
, rect
.GetHeight());
3751 dc
.DrawRectangle(selRect
);
3753 dc
.DrawText(stringChunk
, x
, y
);
3757 hasTabs
= (str
.Find(wxT('\t')) != wxNOT_FOUND
);
3762 dc
.GetTextExtent(str
, & w
, & h
);
3765 wxRect
selRect(x
, rect
.y
, w
, rect
.GetHeight());
3766 dc
.DrawRectangle(selRect
);
3768 dc
.DrawText(str
, x
, y
);
3775 /// Lay the item out
3776 bool wxRichTextPlainText::Layout(wxDC
& dc
, const wxRect
& WXUNUSED(rect
), int WXUNUSED(style
))
3778 #if wxRICHTEXT_USE_DYNAMIC_STYLES
3779 wxRichTextParagraph
* para
= wxDynamicCast(GetParent(), wxRichTextParagraph
);
3780 wxASSERT (para
!= NULL
);
3782 wxTextAttrEx
textAttr(para
? para
->GetCombinedAttributes(GetAttributes()) : GetAttributes());
3784 wxTextAttrEx
textAttr(GetAttributes());
3787 if (textAttr
.GetFont().Ok())
3788 dc
.SetFont(textAttr
.GetFont());
3791 dc
.GetTextExtent(m_text
, & w
, & h
, & m_descent
);
3792 m_size
= wxSize(w
, dc
.GetCharHeight());
3798 void wxRichTextPlainText::Copy(const wxRichTextPlainText
& obj
)
3800 wxRichTextObject::Copy(obj
);
3802 m_text
= obj
.m_text
;
3805 /// Get/set the object size for the given range. Returns false if the range
3806 /// is invalid for this object.
3807 bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& descent
, wxDC
& dc
, int WXUNUSED(flags
), wxPoint position
) const
3809 if (!range
.IsWithin(GetRange()))
3812 #if wxRICHTEXT_USE_DYNAMIC_STYLES
3813 wxRichTextParagraph
* para
= wxDynamicCast(GetParent(), wxRichTextParagraph
);
3814 wxASSERT (para
!= NULL
);
3816 wxTextAttrEx
textAttr(para
? para
->GetCombinedAttributes(GetAttributes()) : GetAttributes());
3818 wxTextAttrEx
textAttr(GetAttributes());
3821 // Always assume unformatted text, since at this level we have no knowledge
3822 // of line breaks - and we don't need it, since we'll calculate size within
3823 // formatted text by doing it in chunks according to the line ranges
3825 if (textAttr
.GetFont().Ok())
3826 dc
.SetFont(textAttr
.GetFont());
3828 int startPos
= range
.GetStart() - GetRange().GetStart();
3829 long len
= range
.GetLength();
3830 wxString stringChunk
= m_text
.Mid(startPos
, (size_t) len
);
3833 if (stringChunk
.Find(wxT('\t')) != wxNOT_FOUND
)
3835 // the string has a tab
3836 wxArrayInt tabArray
;
3837 if (textAttr
.GetTabs().IsEmpty())
3838 tabArray
= wxRichTextParagraph::GetDefaultTabs();
3840 tabArray
= textAttr
.GetTabs();
3842 int tabCount
= tabArray
.GetCount();
3844 for (int i
= 0; i
< tabCount
; ++i
)
3846 int pos
= tabArray
[i
];
3847 pos
= ((wxRichTextPlainText
*) this)->ConvertTenthsMMToPixels(dc
, pos
);
3851 int nextTabPos
= -1;
3853 while (stringChunk
.Find(wxT('\t')) >= 0)
3855 // the string has a tab
3856 // break up the string at the Tab
3857 wxString stringFragment
= stringChunk
.BeforeFirst(wxT('\t'));
3858 stringChunk
= stringChunk
.AfterFirst(wxT('\t'));
3859 dc
.GetTextExtent(stringFragment
, & w
, & h
);
3861 int absoluteWidth
= width
+ position
.x
;
3862 bool notFound
= true;
3863 for (int i
= 0; i
< tabCount
&& notFound
; ++i
)
3865 nextTabPos
= tabArray
.Item(i
);
3866 if (nextTabPos
> absoluteWidth
)
3869 width
= nextTabPos
- position
.x
;
3874 dc
.GetTextExtent(stringChunk
, & w
, & h
, & descent
);
3876 size
= wxSize(width
, dc
.GetCharHeight());
3881 /// Do a split, returning an object containing the second part, and setting
3882 /// the first part in 'this'.
3883 wxRichTextObject
* wxRichTextPlainText::DoSplit(long pos
)
3885 int index
= pos
- GetRange().GetStart();
3886 if (index
< 0 || index
>= (int) m_text
.length())
3889 wxString firstPart
= m_text
.Mid(0, index
);
3890 wxString secondPart
= m_text
.Mid(index
);
3894 wxRichTextPlainText
* newObject
= new wxRichTextPlainText(secondPart
);
3895 newObject
->SetAttributes(GetAttributes());
3897 newObject
->SetRange(wxRichTextRange(pos
, GetRange().GetEnd()));
3898 GetRange().SetEnd(pos
-1);
3904 void wxRichTextPlainText::CalculateRange(long start
, long& end
)
3906 end
= start
+ m_text
.length() - 1;
3907 m_range
.SetRange(start
, end
);
3911 bool wxRichTextPlainText::DeleteRange(const wxRichTextRange
& range
)
3913 wxRichTextRange r
= range
;
3915 r
.LimitTo(GetRange());
3917 if (r
.GetStart() == GetRange().GetStart() && r
.GetEnd() == GetRange().GetEnd())
3923 long startIndex
= r
.GetStart() - GetRange().GetStart();
3924 long len
= r
.GetLength();
3926 m_text
= m_text
.Mid(0, startIndex
) + m_text
.Mid(startIndex
+len
);
3930 /// Get text for the given range.
3931 wxString
wxRichTextPlainText::GetTextForRange(const wxRichTextRange
& range
) const
3933 wxRichTextRange r
= range
;
3935 r
.LimitTo(GetRange());
3937 long startIndex
= r
.GetStart() - GetRange().GetStart();
3938 long len
= r
.GetLength();
3940 return m_text
.Mid(startIndex
, len
);
3943 /// Returns true if this object can merge itself with the given one.
3944 bool wxRichTextPlainText::CanMerge(wxRichTextObject
* object
) const
3946 return object
->GetClassInfo() == CLASSINFO(wxRichTextPlainText
) &&
3947 (m_text
.empty() || wxTextAttrEq(GetAttributes(), object
->GetAttributes()));
3950 /// Returns true if this object merged itself with the given one.
3951 /// The calling code will then delete the given object.
3952 bool wxRichTextPlainText::Merge(wxRichTextObject
* object
)
3954 wxRichTextPlainText
* textObject
= wxDynamicCast(object
, wxRichTextPlainText
);
3955 wxASSERT( textObject
!= NULL
);
3959 m_text
+= textObject
->GetText();
3966 /// Dump to output stream for debugging
3967 void wxRichTextPlainText::Dump(wxTextOutputStream
& stream
)
3969 wxRichTextObject::Dump(stream
);
3970 stream
<< m_text
<< wxT("\n");
3975 * This is a kind of box, used to represent the whole buffer
3978 IMPLEMENT_DYNAMIC_CLASS(wxRichTextBuffer
, wxRichTextParagraphLayoutBox
)
3980 wxList
wxRichTextBuffer::sm_handlers
;
3983 void wxRichTextBuffer::Init()
3985 m_commandProcessor
= new wxCommandProcessor
;
3986 m_styleSheet
= NULL
;
3988 m_batchedCommandDepth
= 0;
3989 m_batchedCommand
= NULL
;
3994 wxRichTextBuffer::~wxRichTextBuffer()
3996 delete m_commandProcessor
;
3997 delete m_batchedCommand
;
4002 void wxRichTextBuffer::Clear()
4005 GetCommandProcessor()->ClearCommands();
4007 Invalidate(wxRICHTEXT_ALL
);
4010 void wxRichTextBuffer::Reset()
4013 AddParagraph(wxEmptyString
);
4014 GetCommandProcessor()->ClearCommands();
4016 Invalidate(wxRICHTEXT_ALL
);
4019 void wxRichTextBuffer::Copy(const wxRichTextBuffer
& obj
)
4021 wxRichTextParagraphLayoutBox::Copy(obj
);
4023 m_styleSheet
= obj
.m_styleSheet
;
4024 m_modified
= obj
.m_modified
;
4025 m_batchedCommandDepth
= obj
.m_batchedCommandDepth
;
4026 m_batchedCommand
= obj
.m_batchedCommand
;
4027 m_suppressUndo
= obj
.m_suppressUndo
;
4030 /// Submit command to insert paragraphs
4031 bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos
, const wxRichTextParagraphLayoutBox
& paragraphs
, wxRichTextCtrl
* ctrl
, int flags
)
4033 wxRichTextAction
* action
= new wxRichTextAction(NULL
, _("Insert Text"), wxRICHTEXT_INSERT
, this, ctrl
, false);
4035 wxTextAttrEx
* p
= NULL
;
4036 wxTextAttrEx paraAttr
;
4037 if (flags
& wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
)
4039 paraAttr
= GetStyleForNewParagraph(pos
);
4040 if (!paraAttr
.IsDefault())
4044 #if wxRICHTEXT_USE_DYNAMIC_STYLES
4045 wxTextAttrEx
attr(GetDefaultStyle());
4047 wxTextAttrEx
attr(GetBasicStyle());
4048 wxRichTextApplyStyle(attr
, GetDefaultStyle());
4051 action
->GetNewParagraphs() = paragraphs
;
4055 wxRichTextObjectList::compatibility_iterator node
= m_children
.GetLast();
4058 wxRichTextParagraph
* obj
= (wxRichTextParagraph
*) node
->GetData();
4059 obj
->SetAttributes(*p
);
4060 node
= node
->GetPrevious();
4064 action
->SetPosition(pos
);
4066 // Set the range we'll need to delete in Undo
4067 action
->SetRange(wxRichTextRange(pos
, pos
+ paragraphs
.GetRange().GetEnd() - 1));
4069 SubmitAction(action
);
4074 /// Submit command to insert the given text
4075 bool wxRichTextBuffer::InsertTextWithUndo(long pos
, const wxString
& text
, wxRichTextCtrl
* ctrl
, int flags
)
4077 wxRichTextAction
* action
= new wxRichTextAction(NULL
, _("Insert Text"), wxRICHTEXT_INSERT
, this, ctrl
, false);
4079 wxTextAttrEx
* p
= NULL
;
4080 wxTextAttrEx paraAttr
;
4081 if (flags
& wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
)
4083 paraAttr
= GetStyleForNewParagraph(pos
);
4084 if (!paraAttr
.IsDefault())
4088 #if wxRICHTEXT_USE_DYNAMIC_STYLES
4089 wxTextAttrEx
attr(GetDefaultStyle());
4091 wxTextAttrEx
attr(GetBasicStyle());
4092 wxRichTextApplyStyle(attr
, GetDefaultStyle());
4095 action
->GetNewParagraphs().AddParagraphs(text
, p
);
4097 int length
= action
->GetNewParagraphs().GetRange().GetLength();
4099 if (text
.length() > 0 && text
.Last() != wxT('\n'))
4101 // Don't count the newline when undoing
4103 action
->GetNewParagraphs().SetPartialParagraph(true);
4106 action
->SetPosition(pos
);
4108 // Set the range we'll need to delete in Undo
4109 action
->SetRange(wxRichTextRange(pos
, pos
+ length
- 1));
4111 SubmitAction(action
);
4116 /// Submit command to insert the given text
4117 bool wxRichTextBuffer::InsertNewlineWithUndo(long pos
, wxRichTextCtrl
* ctrl
, int flags
)
4119 wxRichTextAction
* action
= new wxRichTextAction(NULL
, _("Insert Text"), wxRICHTEXT_INSERT
, this, ctrl
, false);
4121 wxTextAttrEx
* p
= NULL
;
4122 wxTextAttrEx paraAttr
;
4123 if (flags
& wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
)
4125 paraAttr
= GetStyleForNewParagraph(pos
);
4126 if (!paraAttr
.IsDefault())
4130 #if wxRICHTEXT_USE_DYNAMIC_STYLES
4131 wxTextAttrEx
attr(GetDefaultStyle());
4133 wxTextAttrEx
attr(GetBasicStyle());
4134 wxRichTextApplyStyle(attr
, GetDefaultStyle());
4137 wxRichTextParagraph
* newPara
= new wxRichTextParagraph(wxEmptyString
, this, & attr
);
4138 action
->GetNewParagraphs().AppendChild(newPara
);
4139 action
->GetNewParagraphs().UpdateRanges();
4140 action
->GetNewParagraphs().SetPartialParagraph(false);
4141 action
->SetPosition(pos
);
4144 newPara
->SetAttributes(*p
);
4146 // Set the range we'll need to delete in Undo
4147 action
->SetRange(wxRichTextRange(pos
, pos
));
4149 SubmitAction(action
);
4154 /// Submit command to insert the given image
4155 bool wxRichTextBuffer::InsertImageWithUndo(long pos
, const wxRichTextImageBlock
& imageBlock
, wxRichTextCtrl
* ctrl
, int flags
)
4157 wxRichTextAction
* action
= new wxRichTextAction(NULL
, _("Insert Image"), wxRICHTEXT_INSERT
, this, ctrl
, false);
4159 wxTextAttrEx
* p
= NULL
;
4160 wxTextAttrEx paraAttr
;
4161 if (flags
& wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
)
4163 paraAttr
= GetStyleForNewParagraph(pos
);
4164 if (!paraAttr
.IsDefault())
4168 #if wxRICHTEXT_USE_DYNAMIC_STYLES
4169 wxTextAttrEx
attr(GetDefaultStyle());
4171 wxTextAttrEx
attr(GetBasicStyle());
4172 wxRichTextApplyStyle(attr
, GetDefaultStyle());
4175 wxRichTextParagraph
* newPara
= new wxRichTextParagraph(this, & attr
);
4177 newPara
->SetAttributes(*p
);
4179 wxRichTextImage
* imageObject
= new wxRichTextImage(imageBlock
, newPara
);
4180 newPara
->AppendChild(imageObject
);
4181 action
->GetNewParagraphs().AppendChild(newPara
);
4182 action
->GetNewParagraphs().UpdateRanges();
4184 action
->GetNewParagraphs().SetPartialParagraph(true);
4186 action
->SetPosition(pos
);
4188 // Set the range we'll need to delete in Undo
4189 action
->SetRange(wxRichTextRange(pos
, pos
));
4191 SubmitAction(action
);
4196 /// Get the style that is appropriate for a new paragraph at this position.
4197 /// If the previous paragraph has a paragraph style name, look up the next-paragraph
4199 wxRichTextAttr
wxRichTextBuffer::GetStyleForNewParagraph(long pos
, bool caretPosition
) const
4201 wxRichTextParagraph
* para
= GetParagraphAtPosition(pos
, caretPosition
);
4204 if (!para
->GetAttributes().GetParagraphStyleName().IsEmpty() && GetStyleSheet())
4206 wxRichTextParagraphStyleDefinition
* paraDef
= GetStyleSheet()->FindParagraphStyle(para
->GetAttributes().GetParagraphStyleName());
4207 if (paraDef
&& !paraDef
->GetNextStyle().IsEmpty())
4209 wxRichTextParagraphStyleDefinition
* nextParaDef
= GetStyleSheet()->FindParagraphStyle(paraDef
->GetNextStyle());
4211 return nextParaDef
->GetStyle();
4214 wxRichTextAttr
attr(para
->GetAttributes());
4215 int flags
= attr
.GetFlags();
4217 // Eliminate character styles
4218 flags
&= ( (~ wxTEXT_ATTR_FONT
) |
4219 (~ wxTEXT_ATTR_TEXT_COLOUR
) |
4220 (~ wxTEXT_ATTR_BACKGROUND_COLOUR
) );
4221 attr
.SetFlags(flags
);
4226 return wxRichTextAttr();
4229 /// Submit command to delete this range
4230 bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange
& range
, long initialCaretPosition
, long WXUNUSED(newCaretPositon
), wxRichTextCtrl
* ctrl
)
4232 wxRichTextAction
* action
= new wxRichTextAction(NULL
, _("Delete"), wxRICHTEXT_DELETE
, this, ctrl
);
4234 action
->SetPosition(initialCaretPosition
);
4236 // Set the range to delete
4237 action
->SetRange(range
);
4239 // Copy the fragment that we'll need to restore in Undo
4240 CopyFragment(range
, action
->GetOldParagraphs());
4242 // Special case: if there is only one (non-partial) paragraph,
4243 // we must save the *next* paragraph's style, because that
4244 // is the style we must apply when inserting the content back
4245 // when undoing the delete. (This is because we're merging the
4246 // paragraph with the previous paragraph and throwing away
4247 // the style, and we need to restore it.)
4248 if (!action
->GetOldParagraphs().GetPartialParagraph() && action
->GetOldParagraphs().GetChildCount() == 1)
4250 wxRichTextParagraph
* lastPara
= GetParagraphAtPosition(range
.GetStart());
4253 wxRichTextParagraph
* nextPara
= GetParagraphAtPosition(range
.GetEnd()+1);
4256 wxRichTextParagraph
* para
= (wxRichTextParagraph
*) action
->GetOldParagraphs().GetChild(0);
4257 para
->SetAttributes(nextPara
->GetAttributes());
4262 SubmitAction(action
);
4267 /// Collapse undo/redo commands
4268 bool wxRichTextBuffer::BeginBatchUndo(const wxString
& cmdName
)
4270 if (m_batchedCommandDepth
== 0)
4272 wxASSERT(m_batchedCommand
== NULL
);
4273 if (m_batchedCommand
)
4275 GetCommandProcessor()->Submit(m_batchedCommand
);
4277 m_batchedCommand
= new wxRichTextCommand(cmdName
);
4280 m_batchedCommandDepth
++;
4285 /// Collapse undo/redo commands
4286 bool wxRichTextBuffer::EndBatchUndo()
4288 m_batchedCommandDepth
--;
4290 wxASSERT(m_batchedCommandDepth
>= 0);
4291 wxASSERT(m_batchedCommand
!= NULL
);
4293 if (m_batchedCommandDepth
== 0)
4295 GetCommandProcessor()->Submit(m_batchedCommand
);
4296 m_batchedCommand
= NULL
;
4302 /// Submit immediately, or delay according to whether collapsing is on
4303 bool wxRichTextBuffer::SubmitAction(wxRichTextAction
* action
)
4305 if (BatchingUndo() && m_batchedCommand
&& !SuppressingUndo())
4306 m_batchedCommand
->AddAction(action
);
4309 wxRichTextCommand
* cmd
= new wxRichTextCommand(action
->GetName());
4310 cmd
->AddAction(action
);
4312 // Only store it if we're not suppressing undo.
4313 return GetCommandProcessor()->Submit(cmd
, !SuppressingUndo());
4319 /// Begin suppressing undo/redo commands.
4320 bool wxRichTextBuffer::BeginSuppressUndo()
4327 /// End suppressing undo/redo commands.
4328 bool wxRichTextBuffer::EndSuppressUndo()
4335 /// Begin using a style
4336 bool wxRichTextBuffer::BeginStyle(const wxTextAttrEx
& style
)
4338 wxTextAttrEx
newStyle(GetDefaultStyle());
4340 // Save the old default style
4341 m_attributeStack
.Append((wxObject
*) new wxTextAttrEx(GetDefaultStyle()));
4343 wxRichTextApplyStyle(newStyle
, style
);
4344 newStyle
.SetFlags(style
.GetFlags()|newStyle
.GetFlags());
4346 SetDefaultStyle(newStyle
);
4348 // wxLogDebug("Default style size = %d", GetDefaultStyle().GetFont().GetPointSize());
4354 bool wxRichTextBuffer::EndStyle()
4356 if (!m_attributeStack
.GetFirst())
4358 wxLogDebug(_("Too many EndStyle calls!"));
4362 wxList::compatibility_iterator node
= m_attributeStack
.GetLast();
4363 wxTextAttrEx
* attr
= (wxTextAttrEx
*)node
->GetData();
4364 m_attributeStack
.Erase(node
);
4366 SetDefaultStyle(*attr
);
4373 bool wxRichTextBuffer::EndAllStyles()
4375 while (m_attributeStack
.GetCount() != 0)
4380 /// Clear the style stack
4381 void wxRichTextBuffer::ClearStyleStack()
4383 for (wxList::compatibility_iterator node
= m_attributeStack
.GetFirst(); node
; node
= node
->GetNext())
4384 delete (wxTextAttrEx
*) node
->GetData();
4385 m_attributeStack
.Clear();
4388 /// Begin using bold
4389 bool wxRichTextBuffer::BeginBold()
4391 wxFont
font(GetBasicStyle().GetFont());
4392 font
.SetWeight(wxBOLD
);
4395 attr
.SetFont(font
,wxTEXT_ATTR_FONT_WEIGHT
);
4397 return BeginStyle(attr
);
4400 /// Begin using italic
4401 bool wxRichTextBuffer::BeginItalic()
4403 wxFont
font(GetBasicStyle().GetFont());
4404 font
.SetStyle(wxITALIC
);
4407 attr
.SetFont(font
, wxTEXT_ATTR_FONT_ITALIC
);
4409 return BeginStyle(attr
);
4412 /// Begin using underline
4413 bool wxRichTextBuffer::BeginUnderline()
4415 wxFont
font(GetBasicStyle().GetFont());
4416 font
.SetUnderlined(true);
4419 attr
.SetFont(font
, wxTEXT_ATTR_FONT_UNDERLINE
);
4421 return BeginStyle(attr
);
4424 /// Begin using point size
4425 bool wxRichTextBuffer::BeginFontSize(int pointSize
)
4427 wxFont
font(GetBasicStyle().GetFont());
4428 font
.SetPointSize(pointSize
);
4431 attr
.SetFont(font
, wxTEXT_ATTR_FONT_SIZE
);
4433 return BeginStyle(attr
);
4436 /// Begin using this font
4437 bool wxRichTextBuffer::BeginFont(const wxFont
& font
)
4440 attr
.SetFlags(wxTEXT_ATTR_FONT
);
4443 return BeginStyle(attr
);
4446 /// Begin using this colour
4447 bool wxRichTextBuffer::BeginTextColour(const wxColour
& colour
)
4450 attr
.SetFlags(wxTEXT_ATTR_TEXT_COLOUR
);
4451 attr
.SetTextColour(colour
);
4453 return BeginStyle(attr
);
4456 /// Begin using alignment
4457 bool wxRichTextBuffer::BeginAlignment(wxTextAttrAlignment alignment
)
4460 attr
.SetFlags(wxTEXT_ATTR_ALIGNMENT
);
4461 attr
.SetAlignment(alignment
);
4463 return BeginStyle(attr
);
4466 /// Begin left indent
4467 bool wxRichTextBuffer::BeginLeftIndent(int leftIndent
, int leftSubIndent
)
4470 attr
.SetFlags(wxTEXT_ATTR_LEFT_INDENT
);
4471 attr
.SetLeftIndent(leftIndent
, leftSubIndent
);
4473 return BeginStyle(attr
);
4476 /// Begin right indent
4477 bool wxRichTextBuffer::BeginRightIndent(int rightIndent
)
4480 attr
.SetFlags(wxTEXT_ATTR_RIGHT_INDENT
);
4481 attr
.SetRightIndent(rightIndent
);
4483 return BeginStyle(attr
);
4486 /// Begin paragraph spacing
4487 bool wxRichTextBuffer::BeginParagraphSpacing(int before
, int after
)
4491 flags
|= wxTEXT_ATTR_PARA_SPACING_BEFORE
;
4493 flags
|= wxTEXT_ATTR_PARA_SPACING_AFTER
;
4496 attr
.SetFlags(flags
);
4497 attr
.SetParagraphSpacingBefore(before
);
4498 attr
.SetParagraphSpacingAfter(after
);
4500 return BeginStyle(attr
);
4503 /// Begin line spacing
4504 bool wxRichTextBuffer::BeginLineSpacing(int lineSpacing
)
4507 attr
.SetFlags(wxTEXT_ATTR_LINE_SPACING
);
4508 attr
.SetLineSpacing(lineSpacing
);
4510 return BeginStyle(attr
);
4513 /// Begin numbered bullet
4514 bool wxRichTextBuffer::BeginNumberedBullet(int bulletNumber
, int leftIndent
, int leftSubIndent
, int bulletStyle
)
4517 attr
.SetFlags(wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_NUMBER
|wxTEXT_ATTR_LEFT_INDENT
);
4518 attr
.SetBulletStyle(bulletStyle
);
4519 attr
.SetBulletNumber(bulletNumber
);
4520 attr
.SetLeftIndent(leftIndent
, leftSubIndent
);
4522 return BeginStyle(attr
);
4525 /// Begin symbol bullet
4526 bool wxRichTextBuffer::BeginSymbolBullet(wxChar symbol
, int leftIndent
, int leftSubIndent
, int bulletStyle
)
4529 attr
.SetFlags(wxTEXT_ATTR_BULLET_STYLE
|wxTEXT_ATTR_BULLET_SYMBOL
|wxTEXT_ATTR_LEFT_INDENT
);
4530 attr
.SetBulletStyle(bulletStyle
);
4531 attr
.SetLeftIndent(leftIndent
, leftSubIndent
);
4532 attr
.SetBulletSymbol(symbol
);
4534 return BeginStyle(attr
);
4537 /// Begin named character style
4538 bool wxRichTextBuffer::BeginCharacterStyle(const wxString
& characterStyle
)
4540 if (GetStyleSheet())
4542 wxRichTextCharacterStyleDefinition
* def
= GetStyleSheet()->FindCharacterStyle(characterStyle
);
4546 def
->GetStyle().CopyTo(attr
);
4547 return BeginStyle(attr
);
4553 /// Begin named paragraph style
4554 bool wxRichTextBuffer::BeginParagraphStyle(const wxString
& paragraphStyle
)
4556 if (GetStyleSheet())
4558 wxRichTextParagraphStyleDefinition
* def
= GetStyleSheet()->FindParagraphStyle(paragraphStyle
);
4562 def
->GetStyle().CopyTo(attr
);
4563 return BeginStyle(attr
);
4569 /// Adds a handler to the end
4570 void wxRichTextBuffer::AddHandler(wxRichTextFileHandler
*handler
)
4572 sm_handlers
.Append(handler
);
4575 /// Inserts a handler at the front
4576 void wxRichTextBuffer::InsertHandler(wxRichTextFileHandler
*handler
)
4578 sm_handlers
.Insert( handler
);
4581 /// Removes a handler
4582 bool wxRichTextBuffer::RemoveHandler(const wxString
& name
)
4584 wxRichTextFileHandler
*handler
= FindHandler(name
);
4587 sm_handlers
.DeleteObject(handler
);
4595 /// Finds a handler by filename or, if supplied, type
4596 wxRichTextFileHandler
*wxRichTextBuffer::FindHandlerFilenameOrType(const wxString
& filename
, int imageType
)
4598 if (imageType
!= wxRICHTEXT_TYPE_ANY
)
4599 return FindHandler(imageType
);
4600 else if (!filename
.IsEmpty())
4602 wxString path
, file
, ext
;
4603 wxSplitPath(filename
, & path
, & file
, & ext
);
4604 return FindHandler(ext
, imageType
);
4611 /// Finds a handler by name
4612 wxRichTextFileHandler
* wxRichTextBuffer::FindHandler(const wxString
& name
)
4614 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
4617 wxRichTextFileHandler
*handler
= (wxRichTextFileHandler
*)node
->GetData();
4618 if (handler
->GetName().Lower() == name
.Lower()) return handler
;
4620 node
= node
->GetNext();
4625 /// Finds a handler by extension and type
4626 wxRichTextFileHandler
* wxRichTextBuffer::FindHandler(const wxString
& extension
, int type
)
4628 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
4631 wxRichTextFileHandler
*handler
= (wxRichTextFileHandler
*)node
->GetData();
4632 if ( handler
->GetExtension().Lower() == extension
.Lower() &&
4633 (type
== wxRICHTEXT_TYPE_ANY
|| handler
->GetType() == type
) )
4635 node
= node
->GetNext();
4640 /// Finds a handler by type
4641 wxRichTextFileHandler
* wxRichTextBuffer::FindHandler(int type
)
4643 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
4646 wxRichTextFileHandler
*handler
= (wxRichTextFileHandler
*)node
->GetData();
4647 if (handler
->GetType() == type
) return handler
;
4648 node
= node
->GetNext();
4653 void wxRichTextBuffer::InitStandardHandlers()
4655 if (!FindHandler(wxRICHTEXT_TYPE_TEXT
))
4656 AddHandler(new wxRichTextPlainTextHandler
);
4659 void wxRichTextBuffer::CleanUpHandlers()
4661 wxList::compatibility_iterator node
= sm_handlers
.GetFirst();
4664 wxRichTextFileHandler
* handler
= (wxRichTextFileHandler
*)node
->GetData();
4665 wxList::compatibility_iterator next
= node
->GetNext();
4670 sm_handlers
.Clear();
4673 wxString
wxRichTextBuffer::GetExtWildcard(bool combine
, bool save
, wxArrayInt
* types
)
4680 wxList::compatibility_iterator node
= GetHandlers().GetFirst();
4684 wxRichTextFileHandler
* handler
= (wxRichTextFileHandler
*) node
->GetData();
4685 if (handler
->IsVisible() && ((save
&& handler
->CanSave()) || !save
&& handler
->CanLoad()))
4690 wildcard
+= wxT(";");
4691 wildcard
+= wxT("*.") + handler
->GetExtension();
4696 wildcard
+= wxT("|");
4697 wildcard
+= handler
->GetName();
4698 wildcard
+= wxT(" ");
4699 wildcard
+= _("files");
4700 wildcard
+= wxT(" (*.");
4701 wildcard
+= handler
->GetExtension();
4702 wildcard
+= wxT(")|*.");
4703 wildcard
+= handler
->GetExtension();
4705 types
->Add(handler
->GetType());
4710 node
= node
->GetNext();
4714 wildcard
= wxT("(") + wildcard
+ wxT(")|") + wildcard
;
4719 bool wxRichTextBuffer::LoadFile(const wxString
& filename
, int type
)
4721 wxRichTextFileHandler
* handler
= FindHandlerFilenameOrType(filename
, type
);
4724 SetDefaultStyle(wxTextAttrEx());
4726 bool success
= handler
->LoadFile(this, filename
);
4727 Invalidate(wxRICHTEXT_ALL
);
4735 bool wxRichTextBuffer::SaveFile(const wxString
& filename
, int type
)
4737 wxRichTextFileHandler
* handler
= FindHandlerFilenameOrType(filename
, type
);
4739 return handler
->SaveFile(this, filename
);
4744 /// Load from a stream
4745 bool wxRichTextBuffer::LoadFile(wxInputStream
& stream
, int type
)
4747 wxRichTextFileHandler
* handler
= FindHandler(type
);
4750 SetDefaultStyle(wxTextAttrEx());
4751 bool success
= handler
->LoadFile(this, stream
);
4752 Invalidate(wxRICHTEXT_ALL
);
4759 /// Save to a stream
4760 bool wxRichTextBuffer::SaveFile(wxOutputStream
& stream
, int type
)
4762 wxRichTextFileHandler
* handler
= FindHandler(type
);
4764 return handler
->SaveFile(this, stream
);
4769 /// Copy the range to the clipboard
4770 bool wxRichTextBuffer::CopyToClipboard(const wxRichTextRange
& range
)
4772 bool success
= false;
4773 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
4775 if (!wxTheClipboard
->IsOpened() && wxTheClipboard
->Open())
4777 wxTheClipboard
->Clear();
4779 // Add composite object
4781 wxDataObjectComposite
* compositeObject
= new wxDataObjectComposite();
4784 wxString text
= GetTextForRange(range
);
4787 text
= wxTextFile::Translate(text
, wxTextFileType_Dos
);
4790 compositeObject
->Add(new wxTextDataObject(text
), false /* not preferred */);
4793 // Add rich text buffer data object. This needs the XML handler to be present.
4795 if (FindHandler(wxRICHTEXT_TYPE_XML
))
4797 wxRichTextBuffer
* richTextBuf
= new wxRichTextBuffer
;
4798 CopyFragment(range
, *richTextBuf
);
4800 compositeObject
->Add(new wxRichTextBufferDataObject(richTextBuf
), true /* preferred */);
4803 if (wxTheClipboard
->SetData(compositeObject
))
4806 wxTheClipboard
->Close();
4815 /// Paste the clipboard content to the buffer
4816 bool wxRichTextBuffer::PasteFromClipboard(long position
)
4818 bool success
= false;
4819 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
4820 if (CanPasteFromClipboard())
4822 if (wxTheClipboard
->Open())
4824 if (wxTheClipboard
->IsSupported(wxDataFormat(wxRichTextBufferDataObject::GetRichTextBufferFormatId())))
4826 wxRichTextBufferDataObject data
;
4827 wxTheClipboard
->GetData(data
);
4828 wxRichTextBuffer
* richTextBuffer
= data
.GetRichTextBuffer();
4831 InsertParagraphsWithUndo(position
+1, *richTextBuffer
, GetRichTextCtrl(), wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE
);
4832 delete richTextBuffer
;
4835 else if (wxTheClipboard
->IsSupported(wxDF_TEXT
) || wxTheClipboard
->IsSupported(wxDF_UNICODETEXT
))
4837 wxTextDataObject data
;
4838 wxTheClipboard
->GetData(data
);
4839 wxString
text(data
.GetText());
4840 text
.Replace(_T("\r\n"), _T("\n"));
4842 InsertTextWithUndo(position
+1, text
, GetRichTextCtrl());
4846 else if (wxTheClipboard
->IsSupported(wxDF_BITMAP
))
4848 wxBitmapDataObject data
;
4849 wxTheClipboard
->GetData(data
);
4850 wxBitmap
bitmap(data
.GetBitmap());
4851 wxImage
image(bitmap
.ConvertToImage());
4853 wxRichTextAction
* action
= new wxRichTextAction(NULL
, _("Insert Image"), wxRICHTEXT_INSERT
, this, GetRichTextCtrl(), false);
4855 action
->GetNewParagraphs().AddImage(image
);
4857 if (action
->GetNewParagraphs().GetChildCount() == 1)
4858 action
->GetNewParagraphs().SetPartialParagraph(true);
4860 action
->SetPosition(position
);
4862 // Set the range we'll need to delete in Undo
4863 action
->SetRange(wxRichTextRange(position
, position
));
4865 SubmitAction(action
);
4869 wxTheClipboard
->Close();
4873 wxUnusedVar(position
);
4878 /// Can we paste from the clipboard?
4879 bool wxRichTextBuffer::CanPasteFromClipboard() const
4881 bool canPaste
= false;
4882 #if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
4883 if (!wxTheClipboard
->IsOpened() && wxTheClipboard
->Open())
4885 if (wxTheClipboard
->IsSupported(wxDF_TEXT
) || wxTheClipboard
->IsSupported(wxDF_UNICODETEXT
) ||
4886 wxTheClipboard
->IsSupported(wxDataFormat(wxRichTextBufferDataObject::GetRichTextBufferFormatId())) ||
4887 wxTheClipboard
->IsSupported(wxDF_BITMAP
))
4891 wxTheClipboard
->Close();
4897 /// Dumps contents of buffer for debugging purposes
4898 void wxRichTextBuffer::Dump()
4902 wxStringOutputStream
stream(& text
);
4903 wxTextOutputStream
textStream(stream
);
4912 * Module to initialise and clean up handlers
4915 class wxRichTextModule
: public wxModule
4917 DECLARE_DYNAMIC_CLASS(wxRichTextModule
)
4919 wxRichTextModule() {}
4922 wxRichTextBuffer::InitStandardHandlers();
4923 wxRichTextParagraph::InitDefaultTabs();
4928 wxRichTextBuffer::CleanUpHandlers();
4929 wxRichTextDecimalToRoman(-1);
4930 wxRichTextParagraph::ClearDefaultTabs();
4934 IMPLEMENT_DYNAMIC_CLASS(wxRichTextModule
, wxModule
)
4938 * Commands for undo/redo
4942 wxRichTextCommand::wxRichTextCommand(const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
4943 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
): wxCommand(true, name
)
4945 /* wxRichTextAction* action = */ new wxRichTextAction(this, name
, id
, buffer
, ctrl
, ignoreFirstTime
);
4948 wxRichTextCommand::wxRichTextCommand(const wxString
& name
): wxCommand(true, name
)
4952 wxRichTextCommand::~wxRichTextCommand()
4957 void wxRichTextCommand::AddAction(wxRichTextAction
* action
)
4959 if (!m_actions
.Member(action
))
4960 m_actions
.Append(action
);
4963 bool wxRichTextCommand::Do()
4965 for (wxList::compatibility_iterator node
= m_actions
.GetFirst(); node
; node
= node
->GetNext())
4967 wxRichTextAction
* action
= (wxRichTextAction
*) node
->GetData();
4974 bool wxRichTextCommand::Undo()
4976 for (wxList::compatibility_iterator node
= m_actions
.GetLast(); node
; node
= node
->GetPrevious())
4978 wxRichTextAction
* action
= (wxRichTextAction
*) node
->GetData();
4985 void wxRichTextCommand::ClearActions()
4987 WX_CLEAR_LIST(wxList
, m_actions
);
4995 wxRichTextAction::wxRichTextAction(wxRichTextCommand
* cmd
, const wxString
& name
, wxRichTextCommandId id
, wxRichTextBuffer
* buffer
,
4996 wxRichTextCtrl
* ctrl
, bool ignoreFirstTime
)
4999 m_ignoreThis
= ignoreFirstTime
;
5004 m_newParagraphs
.SetDefaultStyle(buffer
->GetDefaultStyle());
5005 m_newParagraphs
.SetBasicStyle(buffer
->GetBasicStyle());
5007 cmd
->AddAction(this);
5010 wxRichTextAction::~wxRichTextAction()
5014 bool wxRichTextAction::Do()
5016 m_buffer
->Modify(true);
5020 case wxRICHTEXT_INSERT
:
5022 m_buffer
->InsertFragment(GetPosition(), m_newParagraphs
);
5023 m_buffer
->UpdateRanges();
5024 m_buffer
->Invalidate(GetRange());
5026 long newCaretPosition
= GetPosition() + m_newParagraphs
.GetRange().GetLength();
5028 // Character position to caret position
5029 newCaretPosition
--;
5031 // Don't take into account the last newline
5032 if (m_newParagraphs
.GetPartialParagraph())
5033 newCaretPosition
--;
5035 newCaretPosition
= wxMin(newCaretPosition
, (m_buffer
->GetRange().GetEnd()-1));
5037 UpdateAppearance(newCaretPosition
, true /* send update event */);
5041 case wxRICHTEXT_DELETE
:
5043 m_buffer
->DeleteRange(GetRange());
5044 m_buffer
->UpdateRanges();
5045 m_buffer
->Invalidate(wxRichTextRange(GetRange().GetStart(), GetRange().GetStart()));
5047 UpdateAppearance(GetRange().GetStart()-1, true /* send update event */);
5051 case wxRICHTEXT_CHANGE_STYLE
:
5053 ApplyParagraphs(GetNewParagraphs());
5054 m_buffer
->Invalidate(GetRange());
5056 UpdateAppearance(GetPosition());
5067 bool wxRichTextAction::Undo()
5069 m_buffer
->Modify(true);
5073 case wxRICHTEXT_INSERT
:
5075 m_buffer
->DeleteRange(GetRange());
5076 m_buffer
->UpdateRanges();
5077 m_buffer
->Invalidate(wxRichTextRange(GetRange().GetStart(), GetRange().GetStart()));
5079 long newCaretPosition
= GetPosition() - 1;
5080 // if (m_newParagraphs.GetPartialParagraph())
5081 // newCaretPosition --;
5083 UpdateAppearance(newCaretPosition
, true /* send update event */);
5087 case wxRICHTEXT_DELETE
:
5089 m_buffer
->InsertFragment(GetRange().GetStart(), m_oldParagraphs
);
5090 m_buffer
->UpdateRanges();
5091 m_buffer
->Invalidate(GetRange());
5093 UpdateAppearance(GetPosition(), true /* send update event */);
5097 case wxRICHTEXT_CHANGE_STYLE
:
5099 ApplyParagraphs(GetOldParagraphs());
5100 m_buffer
->Invalidate(GetRange());
5102 UpdateAppearance(GetPosition());
5113 /// Update the control appearance
5114 void wxRichTextAction::UpdateAppearance(long caretPosition
, bool sendUpdateEvent
)
5118 m_ctrl
->SetCaretPosition(caretPosition
);
5119 if (!m_ctrl
->IsFrozen())
5121 m_ctrl
->LayoutContent();
5122 m_ctrl
->PositionCaret();
5123 m_ctrl
->Refresh(false);
5125 if (sendUpdateEvent
)
5126 m_ctrl
->SendTextUpdatedEvent();
5131 /// Replace the buffer paragraphs with the new ones.
5132 void wxRichTextAction::ApplyParagraphs(const wxRichTextParagraphLayoutBox
& fragment
)
5134 wxRichTextObjectList::compatibility_iterator node
= fragment
.GetChildren().GetFirst();
5137 wxRichTextParagraph
* para
= wxDynamicCast(node
->GetData(), wxRichTextParagraph
);
5138 wxASSERT (para
!= NULL
);
5140 // We'll replace the existing paragraph by finding the paragraph at this position,
5141 // delete its node data, and setting a copy as the new node data.
5142 // TODO: make more efficient by simply swapping old and new paragraph objects.
5144 wxRichTextParagraph
* existingPara
= m_buffer
->GetParagraphAtPosition(para
->GetRange().GetStart());
5147 wxRichTextObjectList::compatibility_iterator bufferParaNode
= m_buffer
->GetChildren().Find(existingPara
);
5150 wxRichTextParagraph
* newPara
= new wxRichTextParagraph(*para
);
5151 newPara
->SetParent(m_buffer
);
5153 bufferParaNode
->SetData(newPara
);
5155 delete existingPara
;
5159 node
= node
->GetNext();
5166 * This stores beginning and end positions for a range of data.
5169 /// Limit this range to be within 'range'
5170 bool wxRichTextRange::LimitTo(const wxRichTextRange
& range
)
5172 if (m_start
< range
.m_start
)
5173 m_start
= range
.m_start
;
5175 if (m_end
> range
.m_end
)
5176 m_end
= range
.m_end
;
5182 * wxRichTextImage implementation
5183 * This object represents an image.
5186 IMPLEMENT_DYNAMIC_CLASS(wxRichTextImage
, wxRichTextObject
)
5188 wxRichTextImage::wxRichTextImage(const wxImage
& image
, wxRichTextObject
* parent
):
5189 wxRichTextObject(parent
)
5194 wxRichTextImage::wxRichTextImage(const wxRichTextImageBlock
& imageBlock
, wxRichTextObject
* parent
):
5195 wxRichTextObject(parent
)
5197 m_imageBlock
= imageBlock
;
5198 m_imageBlock
.Load(m_image
);
5201 /// Load wxImage from the block
5202 bool wxRichTextImage::LoadFromBlock()
5204 m_imageBlock
.Load(m_image
);
5205 return m_imageBlock
.Ok();
5208 /// Make block from the wxImage
5209 bool wxRichTextImage::MakeBlock()
5211 if (m_imageBlock
.GetImageType() == wxBITMAP_TYPE_ANY
|| m_imageBlock
.GetImageType() == -1)
5212 m_imageBlock
.SetImageType(wxBITMAP_TYPE_PNG
);
5214 m_imageBlock
.MakeImageBlock(m_image
, m_imageBlock
.GetImageType());
5215 return m_imageBlock
.Ok();
5220 bool wxRichTextImage::Draw(wxDC
& dc
, const wxRichTextRange
& range
, const wxRichTextRange
& selectionRange
, const wxRect
& rect
, int WXUNUSED(descent
), int WXUNUSED(style
))
5222 if (!m_image
.Ok() && m_imageBlock
.Ok())
5228 if (m_image
.Ok() && !m_bitmap
.Ok())
5229 m_bitmap
= wxBitmap(m_image
);
5231 int y
= rect
.y
+ (rect
.height
- m_image
.GetHeight());
5234 dc
.DrawBitmap(m_bitmap
, rect
.x
, y
, true);
5236 if (selectionRange
.Contains(range
.GetStart()))
5238 dc
.SetBrush(*wxBLACK_BRUSH
);
5239 dc
.SetPen(*wxBLACK_PEN
);
5240 dc
.SetLogicalFunction(wxINVERT
);
5241 dc
.DrawRectangle(rect
);
5242 dc
.SetLogicalFunction(wxCOPY
);
5248 /// Lay the item out
5249 bool wxRichTextImage::Layout(wxDC
& WXUNUSED(dc
), const wxRect
& rect
, int WXUNUSED(style
))
5256 SetCachedSize(wxSize(m_image
.GetWidth(), m_image
.GetHeight()));
5257 SetPosition(rect
.GetPosition());
5263 /// Get/set the object size for the given range. Returns false if the range
5264 /// is invalid for this object.
5265 bool wxRichTextImage::GetRangeSize(const wxRichTextRange
& range
, wxSize
& size
, int& WXUNUSED(descent
), wxDC
& WXUNUSED(dc
), int WXUNUSED(flags
), wxPoint
WXUNUSED(position
)) const
5267 if (!range
.IsWithin(GetRange()))
5273 size
.x
= m_image
.GetWidth();
5274 size
.y
= m_image
.GetHeight();
5280 void wxRichTextImage::Copy(const wxRichTextImage
& obj
)
5282 wxRichTextObject::Copy(obj
);
5284 m_image
= obj
.m_image
;
5285 m_imageBlock
= obj
.m_imageBlock
;
5293 /// Compare two attribute objects
5294 bool wxTextAttrEq(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
)
5297 attr1
.GetTextColour() == attr2
.GetTextColour() &&
5298 attr1
.GetBackgroundColour() == attr2
.GetBackgroundColour() &&
5299 attr1
.GetFont() == attr2
.GetFont() &&
5300 attr1
.GetAlignment() == attr2
.GetAlignment() &&
5301 attr1
.GetLeftIndent() == attr2
.GetLeftIndent() &&
5302 attr1
.GetRightIndent() == attr2
.GetRightIndent() &&
5303 attr1
.GetLeftSubIndent() == attr2
.GetLeftSubIndent() &&
5304 wxRichTextTabsEq(attr1
.GetTabs(), attr2
.GetTabs()) &&
5305 attr1
.GetLineSpacing() == attr2
.GetLineSpacing() &&
5306 attr1
.GetParagraphSpacingAfter() == attr2
.GetParagraphSpacingAfter() &&
5307 attr1
.GetParagraphSpacingBefore() == attr2
.GetParagraphSpacingBefore() &&
5308 attr1
.GetBulletStyle() == attr2
.GetBulletStyle() &&
5309 attr1
.GetBulletNumber() == attr2
.GetBulletNumber() &&
5310 attr1
.GetBulletSymbol() == attr2
.GetBulletSymbol() &&
5311 attr1
.GetBulletFont() == attr2
.GetBulletFont() &&
5312 attr1
.GetCharacterStyleName() == attr2
.GetCharacterStyleName() &&
5313 attr1
.GetParagraphStyleName() == attr2
.GetParagraphStyleName());
5316 bool wxTextAttrEq(const wxTextAttrEx
& attr1
, const wxRichTextAttr
& attr2
)
5319 attr1
.GetTextColour() == attr2
.GetTextColour() &&
5320 attr1
.GetBackgroundColour() == attr2
.GetBackgroundColour() &&
5321 attr1
.GetFont().GetPointSize() == attr2
.GetFontSize() &&
5322 attr1
.GetFont().GetStyle() == attr2
.GetFontStyle() &&
5323 attr1
.GetFont().GetWeight() == attr2
.GetFontWeight() &&
5324 attr1
.GetFont().GetFaceName() == attr2
.GetFontFaceName() &&
5325 attr1
.GetFont().GetUnderlined() == attr2
.GetFontUnderlined() &&
5326 attr1
.GetAlignment() == attr2
.GetAlignment() &&
5327 attr1
.GetLeftIndent() == attr2
.GetLeftIndent() &&
5328 attr1
.GetRightIndent() == attr2
.GetRightIndent() &&
5329 attr1
.GetLeftSubIndent() == attr2
.GetLeftSubIndent() &&
5330 wxRichTextTabsEq(attr1
.GetTabs(), attr2
.GetTabs()) &&
5331 attr1
.GetLineSpacing() == attr2
.GetLineSpacing() &&
5332 attr1
.GetParagraphSpacingAfter() == attr2
.GetParagraphSpacingAfter() &&
5333 attr1
.GetParagraphSpacingBefore() == attr2
.GetParagraphSpacingBefore() &&
5334 attr1
.GetBulletStyle() == attr2
.GetBulletStyle() &&
5335 attr1
.GetBulletNumber() == attr2
.GetBulletNumber() &&
5336 attr1
.GetBulletSymbol() == attr2
.GetBulletSymbol() &&
5337 attr1
.GetBulletFont() == attr2
.GetBulletFont() &&
5338 attr1
.GetCharacterStyleName() == attr2
.GetCharacterStyleName() &&
5339 attr1
.GetParagraphStyleName() == attr2
.GetParagraphStyleName());
5342 /// Compare two attribute objects, but take into account the flags
5343 /// specifying attributes of interest.
5344 bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxTextAttrEx
& attr2
, int flags
)
5346 if ((flags
& wxTEXT_ATTR_TEXT_COLOUR
) && attr1
.GetTextColour() != attr2
.GetTextColour())
5349 if ((flags
& wxTEXT_ATTR_BACKGROUND_COLOUR
) && attr1
.GetBackgroundColour() != attr2
.GetBackgroundColour())
5352 if ((flags
& wxTEXT_ATTR_FONT_FACE
) && attr1
.GetFont().Ok() && attr2
.GetFont().Ok() &&
5353 attr1
.GetFont().GetFaceName() != attr2
.GetFont().GetFaceName())
5356 if ((flags
& wxTEXT_ATTR_FONT_SIZE
) && attr1
.GetFont().Ok() && attr2
.GetFont().Ok() &&
5357 attr1
.GetFont().GetPointSize() != attr2
.GetFont().GetPointSize())
5360 if ((flags
& wxTEXT_ATTR_FONT_WEIGHT
) && attr1
.GetFont().Ok() && attr2
.GetFont().Ok() &&
5361 attr1
.GetFont().GetWeight() != attr2
.GetFont().GetWeight())
5364 if ((flags
& wxTEXT_ATTR_FONT_ITALIC
) && attr1
.GetFont().Ok() && attr2
.GetFont().Ok() &&
5365 attr1
.GetFont().GetStyle() != attr2
.GetFont().GetStyle())
5368 if ((flags
& wxTEXT_ATTR_FONT_UNDERLINE
) && attr1
.GetFont().Ok() && attr2
.GetFont().Ok() &&
5369 attr1
.GetFont().GetUnderlined() != attr2
.GetFont().GetUnderlined())
5372 if ((flags
& wxTEXT_ATTR_ALIGNMENT
) && attr1
.GetAlignment() != attr2
.GetAlignment())
5375 if ((flags
& wxTEXT_ATTR_LEFT_INDENT
) &&
5376 ((attr1
.GetLeftIndent() != attr2
.GetLeftIndent()) || (attr1
.GetLeftSubIndent() != attr2
.GetLeftSubIndent())))
5379 if ((flags
& wxTEXT_ATTR_RIGHT_INDENT
) &&
5380 (attr1
.GetRightIndent() != attr2
.GetRightIndent()))
5383 if ((flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) &&
5384 (attr1
.GetParagraphSpacingAfter() != attr2
.GetParagraphSpacingAfter()))
5387 if ((flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) &&
5388 (attr1
.GetParagraphSpacingBefore() != attr2
.GetParagraphSpacingBefore()))
5391 if ((flags
& wxTEXT_ATTR_LINE_SPACING
) &&
5392 (attr1
.GetLineSpacing() != attr2
.GetLineSpacing()))
5395 if ((flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) &&
5396 (attr1
.GetCharacterStyleName() != attr2
.GetCharacterStyleName()))
5399 if ((flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) &&
5400 (attr1
.GetParagraphStyleName() != attr2
.GetParagraphStyleName()))
5403 if ((flags
& wxTEXT_ATTR_BULLET_STYLE
) &&
5404 (attr1
.GetBulletStyle() != attr2
.GetBulletStyle()))
5407 if ((flags
& wxTEXT_ATTR_BULLET_NUMBER
) &&
5408 (attr1
.GetBulletNumber() != attr2
.GetBulletNumber()))
5411 if ((flags
& wxTEXT_ATTR_BULLET_SYMBOL
) &&
5412 (attr1
.GetBulletSymbol() != attr2
.GetBulletSymbol()))
5415 if ((flags
& wxTEXT_ATTR_BULLET_SYMBOL
) &&
5416 (attr1
.GetBulletFont() != attr2
.GetBulletFont()))
5419 if ((flags
& wxTEXT_ATTR_TABS
) &&
5420 !wxRichTextTabsEq(attr1
.GetTabs(), attr2
.GetTabs()))
5426 bool wxTextAttrEqPartial(const wxTextAttrEx
& attr1
, const wxRichTextAttr
& attr2
, int flags
)
5428 if ((flags
& wxTEXT_ATTR_TEXT_COLOUR
) && attr1
.GetTextColour() != attr2
.GetTextColour())
5431 if ((flags
& wxTEXT_ATTR_BACKGROUND_COLOUR
) && attr1
.GetBackgroundColour() != attr2
.GetBackgroundColour())
5434 if ((flags
& (wxTEXT_ATTR_FONT
)) && !attr1
.GetFont().Ok())
5437 if ((flags
& wxTEXT_ATTR_FONT_FACE
) && attr1
.GetFont().Ok() &&
5438 attr1
.GetFont().GetFaceName() != attr2
.GetFontFaceName())
5441 if ((flags
& wxTEXT_ATTR_FONT_SIZE
) && attr1
.GetFont().Ok() &&
5442 attr1
.GetFont().GetPointSize() != attr2
.GetFontSize())
5445 if ((flags
& wxTEXT_ATTR_FONT_WEIGHT
) && attr1
.GetFont().Ok() &&
5446 attr1
.GetFont().GetWeight() != attr2
.GetFontWeight())
5449 if ((flags
& wxTEXT_ATTR_FONT_ITALIC
) && attr1
.GetFont().Ok() &&
5450 attr1
.GetFont().GetStyle() != attr2
.GetFontStyle())
5453 if ((flags
& wxTEXT_ATTR_FONT_UNDERLINE
) && attr1
.GetFont().Ok() &&
5454 attr1
.GetFont().GetUnderlined() != attr2
.GetFontUnderlined())
5457 if ((flags
& wxTEXT_ATTR_ALIGNMENT
) && attr1
.GetAlignment() != attr2
.GetAlignment())
5460 if ((flags
& wxTEXT_ATTR_LEFT_INDENT
) &&
5461 ((attr1
.GetLeftIndent() != attr2
.GetLeftIndent()) || (attr1
.GetLeftSubIndent() != attr2
.GetLeftSubIndent())))
5464 if ((flags
& wxTEXT_ATTR_RIGHT_INDENT
) &&
5465 (attr1
.GetRightIndent() != attr2
.GetRightIndent()))
5468 if ((flags
& wxTEXT_ATTR_PARA_SPACING_AFTER
) &&
5469 (attr1
.GetParagraphSpacingAfter() != attr2
.GetParagraphSpacingAfter()))
5472 if ((flags
& wxTEXT_ATTR_PARA_SPACING_BEFORE
) &&
5473 (attr1
.GetParagraphSpacingBefore() != attr2
.GetParagraphSpacingBefore()))
5476 if ((flags
& wxTEXT_ATTR_LINE_SPACING
) &&
5477 (attr1
.GetLineSpacing() != attr2
.GetLineSpacing()))
5480 if ((flags
& wxTEXT_ATTR_CHARACTER_STYLE_NAME
) &&
5481 (attr1
.GetCharacterStyleName() != attr2
.GetCharacterStyleName()))
5484 if ((flags
& wxTEXT_ATTR_PARAGRAPH_STYLE_NAME
) &&
5485 (attr1
.GetParagraphStyleName() != attr2
.GetParagraphStyleName()))
5488 if ((flags
& wxTEXT_ATTR_BULLET_STYLE
) &&
5489 (attr1
.GetBulletStyle() != attr2
.GetBulletStyle()))
5492 if ((flags
& wxTEXT_ATTR_BULLET_NUMBER
) &&
5493 (attr1
.GetBulletNumber() != attr2
.GetBulletNumber()))
5496 if ((flags
& wxTEXT_ATTR_BULLET_SYMBOL
) &&
5497 (attr1
.GetBulletSymbol() != attr2
.GetBulletSymbol()))
5500 if ((flags
& wxTEXT_ATTR_BULLET_SYMBOL
) &&
5501 (attr1
.GetBulletFont() != attr2
.GetBulletFont()))
5504 if ((flags
& wxTEXT_ATTR_TABS
) &&
5505 !wxRichTextTabsEq(attr1
.GetTabs(), attr2
.GetTabs()))
5512 bool wxRichTextTabsEq(const wxArrayInt
& tabs1
, const wxArrayInt
& tabs2
)
5514 if (tabs1
.GetCount() != tabs2
.GetCount())
5518 for (i
= 0; i
< tabs1
.GetCount(); i
++)
5520 if (tabs1
[i
] != tabs2
[i
])
5527 /// Apply one style to another
5528 bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxTextAttrEx
& style
)
5531 if (style
.GetFont().Ok() && ((style
.GetFlags() & (wxTEXT_ATTR_FONT
)) == (wxTEXT_ATTR_FONT
)))
5532 destStyle
.SetFont(style
.GetFont());
5533 else if (style
.GetFont().Ok())
5535 wxFont font
= destStyle
.GetFont();
5537 if (style
.GetFlags() & wxTEXT_ATTR_FONT_FACE
)
5539 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_FACE
);
5540 font
.SetFaceName(style
.GetFont().GetFaceName());
5543 if (style
.GetFlags() & wxTEXT_ATTR_FONT_SIZE
)
5545 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_SIZE
);
5546 font
.SetPointSize(style
.GetFont().GetPointSize());
5549 if (style
.GetFlags() & wxTEXT_ATTR_FONT_ITALIC
)
5551 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_ITALIC
);
5552 font
.SetStyle(style
.GetFont().GetStyle());
5555 if (style
.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT
)
5557 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT
);
5558 font
.SetWeight(style
.GetFont().GetWeight());
5561 if (style
.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE
)
5563 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE
);
5564 font
.SetUnderlined(style
.GetFont().GetUnderlined());
5567 if (font
!= destStyle
.GetFont())
5569 int oldFlags
= destStyle
.GetFlags();
5571 destStyle
.SetFont(font
);
5573 destStyle
.SetFlags(oldFlags
);
5577 if ( style
.GetTextColour().Ok() && style
.HasTextColour())
5578 destStyle
.SetTextColour(style
.GetTextColour());
5580 if ( style
.GetBackgroundColour().Ok() && style
.HasBackgroundColour())
5581 destStyle
.SetBackgroundColour(style
.GetBackgroundColour());
5583 if (style
.HasAlignment())
5584 destStyle
.SetAlignment(style
.GetAlignment());
5586 if (style
.HasTabs())
5587 destStyle
.SetTabs(style
.GetTabs());
5589 if (style
.HasLeftIndent())
5590 destStyle
.SetLeftIndent(style
.GetLeftIndent(), style
.GetLeftSubIndent());
5592 if (style
.HasRightIndent())
5593 destStyle
.SetRightIndent(style
.GetRightIndent());
5595 if (style
.HasParagraphSpacingAfter())
5596 destStyle
.SetParagraphSpacingAfter(style
.GetParagraphSpacingAfter());
5598 if (style
.HasParagraphSpacingBefore())
5599 destStyle
.SetParagraphSpacingBefore(style
.GetParagraphSpacingBefore());
5601 if (style
.HasLineSpacing())
5602 destStyle
.SetLineSpacing(style
.GetLineSpacing());
5604 if (style
.HasCharacterStyleName())
5605 destStyle
.SetCharacterStyleName(style
.GetCharacterStyleName());
5607 if (style
.HasParagraphStyleName())
5608 destStyle
.SetParagraphStyleName(style
.GetParagraphStyleName());
5610 if (style
.HasBulletStyle())
5612 destStyle
.SetBulletStyle(style
.GetBulletStyle());
5613 destStyle
.SetBulletSymbol(style
.GetBulletSymbol());
5614 destStyle
.SetBulletFont(style
.GetBulletFont());
5617 if (style
.HasBulletNumber())
5618 destStyle
.SetBulletNumber(style
.GetBulletNumber());
5623 bool wxRichTextApplyStyle(wxRichTextAttr
& destStyle
, const wxTextAttrEx
& style
)
5625 wxTextAttrEx destStyle2
;
5626 destStyle
.CopyTo(destStyle2
);
5627 wxRichTextApplyStyle(destStyle2
, style
);
5628 destStyle
= destStyle2
;
5632 bool wxRichTextApplyStyle(wxTextAttrEx
& destStyle
, const wxRichTextAttr
& style
, wxRichTextAttr
* compareWith
)
5634 // Whole font. Avoiding setting individual attributes if possible, since
5635 // it recreates the font each time.
5636 if (((style
.GetFlags() & (wxTEXT_ATTR_FONT
)) == (wxTEXT_ATTR_FONT
)) && !compareWith
)
5638 destStyle
.SetFont(wxFont(style
.GetFontSize(), destStyle
.GetFont().Ok() ? destStyle
.GetFont().GetFamily() : wxDEFAULT
,
5639 style
.GetFontStyle(), style
.GetFontWeight(), style
.GetFontUnderlined(), style
.GetFontFaceName()));
5641 else if (style
.GetFlags() & (wxTEXT_ATTR_FONT
))
5643 wxFont font
= destStyle
.GetFont();
5645 if (style
.GetFlags() & wxTEXT_ATTR_FONT_FACE
)
5647 if (compareWith
&& compareWith
->HasFaceName() && compareWith
->GetFontFaceName() == style
.GetFontFaceName())
5649 // The same as currently displayed, so don't set
5653 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_FACE
);
5654 font
.SetFaceName(style
.GetFontFaceName());
5658 if (style
.GetFlags() & wxTEXT_ATTR_FONT_SIZE
)
5660 if (compareWith
&& compareWith
->HasSize() && compareWith
->GetFontSize() == style
.GetFontSize())
5662 // The same as currently displayed, so don't set
5666 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_SIZE
);
5667 font
.SetPointSize(style
.GetFontSize());
5671 if (style
.GetFlags() & wxTEXT_ATTR_FONT_ITALIC
)
5673 if (compareWith
&& compareWith
->HasItalic() && compareWith
->GetFontStyle() == style
.GetFontStyle())
5675 // The same as currently displayed, so don't set
5679 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_ITALIC
);
5680 font
.SetStyle(style
.GetFontStyle());
5684 if (style
.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT
)
5686 if (compareWith
&& compareWith
->HasWeight() && compareWith
->GetFontWeight() == style
.GetFontWeight())
5688 // The same as currently displayed, so don't set
5692 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_WEIGHT
);
5693 font
.SetWeight(style
.GetFontWeight());
5697 if (style
.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE
)
5699 if (compareWith
&& compareWith
->HasUnderlined() && compareWith
->GetFontUnderlined() == style
.GetFontUnderlined())
5701 // The same as currently displayed, so don't set
5705 destStyle
.SetFlags(destStyle
.GetFlags() | wxTEXT_ATTR_FONT_UNDERLINE
);
5706 font
.SetUnderlined(style
.GetFontUnderlined());
5710 if (font
!= destStyle
.GetFont())
5712 int oldFlags
= destStyle
.GetFlags();
5714 destStyle
.SetFont(font
);
5716 destStyle
.SetFlags(oldFlags
);
5720 if (style
.GetTextColour().Ok() && style
.HasTextColour())
5722 if (!(compareWith
&& compareWith
->HasTextColour() && compareWith
->GetTextColour() == style
.GetTextColour()))
5723 destStyle
.SetTextColour(style
.GetTextColour());
5726 if (style
.GetBackgroundColour().Ok() && style
.HasBackgroundColour())
5728 if (!(compareWith
&& compareWith
->HasBackgroundColour() && compareWith
->GetBackgroundColour() == style
.GetBackgroundColour()))
5729 destStyle
.SetBackgroundColour(style
.GetBackgroundColour());
5732 if (style
.HasAlignment())
5734 if (!(compareWith
&& compareWith
->HasAlignment() && compareWith
->GetAlignment() == style
.GetAlignment()))
5735 destStyle
.SetAlignment(style
.GetAlignment());
5738 if (style
.HasTabs())
5740 if (!(compareWith
&& compareWith
->HasTabs() && wxRichTextTabsEq(compareWith
->GetTabs(), style
.GetTabs())))
5741 destStyle
.SetTabs(style
.GetTabs());
5744 if (style
.HasLeftIndent())
5746 if (!(compareWith
&& compareWith
->HasLeftIndent() && compareWith
->GetLeftIndent() == style
.GetLeftIndent()
5747 && compareWith
->GetLeftSubIndent() == style
.GetLeftSubIndent()))
5748 destStyle
.SetLeftIndent(style
.GetLeftIndent(), style
.GetLeftSubIndent());
5751 if (style
.HasRightIndent())
5753 if (!(compareWith
&& compareWith
->HasRightIndent() && compareWith
->GetRightIndent() == style
.GetRightIndent()))
5754 destStyle
.SetRightIndent(style
.GetRightIndent());
5757 if (style
.HasParagraphSpacingAfter())
5759 if (!(compareWith
&& compareWith
->HasParagraphSpacingAfter() && compareWith
->GetParagraphSpacingAfter() == style
.GetParagraphSpacingAfter()))
5760 destStyle
.SetParagraphSpacingAfter(style
.GetParagraphSpacingAfter());
5763 if (style
.HasParagraphSpacingBefore())
5765 if (!(compareWith
&& compareWith
->HasParagraphSpacingBefore() && compareWith
->GetParagraphSpacingBefore() == style
.GetParagraphSpacingBefore()))
5766 destStyle
.SetParagraphSpacingBefore(style
.GetParagraphSpacingBefore());
5769 if (style
.HasLineSpacing())
5771 if (!(compareWith
&& compareWith
->HasLineSpacing() && compareWith
->GetLineSpacing() == style
.GetLineSpacing()))
5772 destStyle
.SetLineSpacing(style
.GetLineSpacing());
5775 if (style
.HasCharacterStyleName())
5777 if (!(compareWith
&& compareWith
->HasCharacterStyleName() && compareWith
->GetCharacterStyleName() == style
.GetCharacterStyleName()))
5778 destStyle
.SetCharacterStyleName(style
.GetCharacterStyleName());
5781 if (style
.HasParagraphStyleName())
5783 if (!(compareWith
&& compareWith
->HasParagraphStyleName() && compareWith
->GetParagraphStyleName() == style
.GetParagraphStyleName()))
5784 destStyle
.SetParagraphStyleName(style
.GetParagraphStyleName());
5787 if (style
.HasBulletStyle())
5789 if (!(compareWith
&& compareWith
->HasBulletStyle() && compareWith
->GetBulletStyle() == style
.GetBulletStyle()))
5790 destStyle
.SetBulletStyle(style
.GetBulletStyle());
5793 if (style
.HasBulletSymbol())
5795 if (!(compareWith
&& compareWith
->HasBulletSymbol() && compareWith
->GetBulletSymbol() == style
.GetBulletSymbol()))
5797 destStyle
.SetBulletSymbol(style
.GetBulletSymbol());
5798 destStyle
.SetBulletFont(style
.GetBulletFont());
5802 if (style
.HasBulletNumber())
5804 if (!(compareWith
&& compareWith
->HasBulletNumber() && compareWith
->GetBulletNumber() == style
.GetBulletNumber()))
5805 destStyle
.SetBulletNumber(style
.GetBulletNumber());
5811 void wxSetFontPreservingStyles(wxTextAttr
& attr
, const wxFont
& font
)
5813 long flags
= attr
.GetFlags();
5815 attr
.SetFlags(flags
);
5818 /// Convert a decimal to Roman numerals
5819 wxString
wxRichTextDecimalToRoman(long n
)
5821 static wxArrayInt decimalNumbers
;
5822 static wxArrayString romanNumbers
;
5827 decimalNumbers
.Clear();
5828 romanNumbers
.Clear();
5829 return wxEmptyString
;
5832 if (decimalNumbers
.GetCount() == 0)
5834 #define wxRichTextAddDecRom(n, r) decimalNumbers.Add(n); romanNumbers.Add(r);
5836 wxRichTextAddDecRom(1000, wxT("M"));
5837 wxRichTextAddDecRom(900, wxT("CM"));
5838 wxRichTextAddDecRom(500, wxT("D"));
5839 wxRichTextAddDecRom(400, wxT("CD"));
5840 wxRichTextAddDecRom(100, wxT("C"));
5841 wxRichTextAddDecRom(90, wxT("XC"));
5842 wxRichTextAddDecRom(50, wxT("L"));
5843 wxRichTextAddDecRom(40, wxT("XL"));
5844 wxRichTextAddDecRom(10, wxT("X"));
5845 wxRichTextAddDecRom(9, wxT("IX"));
5846 wxRichTextAddDecRom(5, wxT("V"));
5847 wxRichTextAddDecRom(4, wxT("IV"));
5848 wxRichTextAddDecRom(1, wxT("I"));
5854 while (n
> 0 && i
< 13)
5856 if (n
>= decimalNumbers
[i
])
5858 n
-= decimalNumbers
[i
];
5859 roman
+= romanNumbers
[i
];
5866 if (roman
.IsEmpty())
5873 * wxRichTextAttr stores attributes without a wxFont object, so is a much more
5874 * efficient way to query styles.
5878 wxRichTextAttr::wxRichTextAttr(const wxColour
& colText
,
5879 const wxColour
& colBack
,
5880 wxTextAttrAlignment alignment
): m_textAlignment(alignment
), m_colText(colText
), m_colBack(colBack
)
5884 if (m_colText
.Ok()) m_flags
|= wxTEXT_ATTR_TEXT_COLOUR
;
5885 if (m_colBack
.Ok()) m_flags
|= wxTEXT_ATTR_BACKGROUND_COLOUR
;
5886 if (alignment
!= wxTEXT_ALIGNMENT_DEFAULT
)
5887 m_flags
|= wxTEXT_ATTR_ALIGNMENT
;
5890 wxRichTextAttr::wxRichTextAttr(const wxTextAttrEx
& attr
)
5898 void wxRichTextAttr::Init()
5900 m_textAlignment
= wxTEXT_ALIGNMENT_DEFAULT
;
5903 m_leftSubIndent
= 0;
5907 m_fontStyle
= wxNORMAL
;
5908 m_fontWeight
= wxNORMAL
;
5909 m_fontUnderlined
= false;
5911 m_paragraphSpacingAfter
= 0;
5912 m_paragraphSpacingBefore
= 0;
5914 m_bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_NONE
;
5916 m_bulletSymbol
= wxT('*');
5920 void wxRichTextAttr::operator= (const wxRichTextAttr
& attr
)
5922 m_colText
= attr
.m_colText
;
5923 m_colBack
= attr
.m_colBack
;
5924 m_textAlignment
= attr
.m_textAlignment
;
5925 m_leftIndent
= attr
.m_leftIndent
;
5926 m_leftSubIndent
= attr
.m_leftSubIndent
;
5927 m_rightIndent
= attr
.m_rightIndent
;
5928 m_tabs
= attr
.m_tabs
;
5929 m_flags
= attr
.m_flags
;
5931 m_fontSize
= attr
.m_fontSize
;
5932 m_fontStyle
= attr
.m_fontStyle
;
5933 m_fontWeight
= attr
.m_fontWeight
;
5934 m_fontUnderlined
= attr
.m_fontUnderlined
;
5935 m_fontFaceName
= attr
.m_fontFaceName
;
5937 m_paragraphSpacingAfter
= attr
.m_paragraphSpacingAfter
;
5938 m_paragraphSpacingBefore
= attr
.m_paragraphSpacingBefore
;
5939 m_lineSpacing
= attr
.m_lineSpacing
;
5940 m_characterStyleName
= attr
.m_characterStyleName
;
5941 m_paragraphStyleName
= attr
.m_paragraphStyleName
;
5942 m_bulletStyle
= attr
.m_bulletStyle
;
5943 m_bulletNumber
= attr
.m_bulletNumber
;
5944 m_bulletSymbol
= attr
.m_bulletSymbol
;
5945 m_bulletFont
= attr
.m_bulletFont
;
5949 void wxRichTextAttr::operator= (const wxTextAttrEx
& attr
)
5951 m_colText
= attr
.GetTextColour();
5952 m_colBack
= attr
.GetBackgroundColour();
5953 m_textAlignment
= attr
.GetAlignment();
5954 m_leftIndent
= attr
.GetLeftIndent();
5955 m_leftSubIndent
= attr
.GetLeftSubIndent();
5956 m_rightIndent
= attr
.GetRightIndent();
5957 m_tabs
= attr
.GetTabs();
5958 m_flags
= attr
.GetFlags();
5960 m_paragraphSpacingAfter
= attr
.GetParagraphSpacingAfter();
5961 m_paragraphSpacingBefore
= attr
.GetParagraphSpacingBefore();
5962 m_lineSpacing
= attr
.GetLineSpacing();
5963 m_characterStyleName
= attr
.GetCharacterStyleName();
5964 m_paragraphStyleName
= attr
.GetParagraphStyleName();
5965 m_bulletStyle
= attr
.GetBulletStyle();
5966 m_bulletNumber
= attr
.GetBulletNumber();
5967 m_bulletSymbol
= attr
.GetBulletSymbol();
5968 m_bulletFont
= attr
.GetBulletFont();
5970 if (attr
.GetFont().Ok())
5971 GetFontAttributes(attr
.GetFont());
5974 // Making a wxTextAttrEx object.
5975 wxRichTextAttr::operator wxTextAttrEx () const
5983 bool wxRichTextAttr::operator== (const wxRichTextAttr
& attr
) const
5985 return GetFlags() == attr
.GetFlags() &&
5987 GetTextColour() == attr
.GetTextColour() &&
5988 GetBackgroundColour() == attr
.GetBackgroundColour() &&
5990 GetAlignment() == attr
.GetAlignment() &&
5991 GetLeftIndent() == attr
.GetLeftIndent() &&
5992 GetLeftSubIndent() == attr
.GetLeftSubIndent() &&
5993 GetRightIndent() == attr
.GetRightIndent() &&
5994 wxRichTextTabsEq(GetTabs(), attr
.GetTabs()) &&
5996 GetParagraphSpacingAfter() == attr
.GetParagraphSpacingAfter() &&
5997 GetParagraphSpacingBefore() == attr
.GetParagraphSpacingBefore() &&
5998 GetLineSpacing() == attr
.GetLineSpacing() &&
5999 GetCharacterStyleName() == attr
.GetCharacterStyleName() &&
6000 GetParagraphStyleName() == attr
.GetParagraphStyleName() &&
6002 GetBulletStyle() == attr
.GetBulletStyle() &&
6003 GetBulletSymbol() == attr
.GetBulletSymbol() &&
6004 GetBulletNumber() == attr
.GetBulletNumber() &&
6005 GetBulletFont() == attr
.GetBulletFont() &&
6007 m_fontSize
== attr
.m_fontSize
&&
6008 m_fontStyle
== attr
.m_fontStyle
&&
6009 m_fontWeight
== attr
.m_fontWeight
&&
6010 m_fontUnderlined
== attr
.m_fontUnderlined
&&
6011 m_fontFaceName
== attr
.m_fontFaceName
;
6014 // Copy to a wxTextAttr
6015 void wxRichTextAttr::CopyTo(wxTextAttrEx
& attr
) const
6017 attr
.SetTextColour(GetTextColour());
6018 attr
.SetBackgroundColour(GetBackgroundColour());
6019 attr
.SetAlignment(GetAlignment());
6020 attr
.SetTabs(GetTabs());
6021 attr
.SetLeftIndent(GetLeftIndent(), GetLeftSubIndent());
6022 attr
.SetRightIndent(GetRightIndent());
6023 attr
.SetFont(CreateFont());
6025 attr
.SetParagraphSpacingAfter(m_paragraphSpacingAfter
);
6026 attr
.SetParagraphSpacingBefore(m_paragraphSpacingBefore
);
6027 attr
.SetLineSpacing(m_lineSpacing
);
6028 attr
.SetBulletStyle(m_bulletStyle
);
6029 attr
.SetBulletNumber(m_bulletNumber
);
6030 attr
.SetBulletSymbol(m_bulletSymbol
);
6031 attr
.SetBulletFont(m_bulletFont
);
6032 attr
.SetCharacterStyleName(m_characterStyleName
);
6033 attr
.SetParagraphStyleName(m_paragraphStyleName
);
6035 attr
.SetFlags(GetFlags()); // Important: set after SetFont and others, since they set flags
6038 // Create font from font attributes.
6039 wxFont
wxRichTextAttr::CreateFont() const
6041 wxFont
font(m_fontSize
, wxDEFAULT
, m_fontStyle
, m_fontWeight
, m_fontUnderlined
, m_fontFaceName
);
6043 font
.SetNoAntiAliasing(true);
6048 // Get attributes from font.
6049 bool wxRichTextAttr::GetFontAttributes(const wxFont
& font
)
6054 m_fontSize
= font
.GetPointSize();
6055 m_fontStyle
= font
.GetStyle();
6056 m_fontWeight
= font
.GetWeight();
6057 m_fontUnderlined
= font
.GetUnderlined();
6058 m_fontFaceName
= font
.GetFaceName();
6063 wxRichTextAttr
wxRichTextAttr::Combine(const wxRichTextAttr
& attr
,
6064 const wxRichTextAttr
& attrDef
,
6065 const wxTextCtrlBase
*text
)
6067 wxColour colFg
= attr
.GetTextColour();
6070 colFg
= attrDef
.GetTextColour();
6072 if ( text
&& !colFg
.Ok() )
6073 colFg
= text
->GetForegroundColour();
6076 wxColour colBg
= attr
.GetBackgroundColour();
6079 colBg
= attrDef
.GetBackgroundColour();
6081 if ( text
&& !colBg
.Ok() )
6082 colBg
= text
->GetBackgroundColour();
6085 wxRichTextAttr
newAttr(colFg
, colBg
);
6087 if (attr
.HasWeight())
6088 newAttr
.SetFontWeight(attr
.GetFontWeight());
6091 newAttr
.SetFontSize(attr
.GetFontSize());
6093 if (attr
.HasItalic())
6094 newAttr
.SetFontStyle(attr
.GetFontStyle());
6096 if (attr
.HasUnderlined())
6097 newAttr
.SetFontUnderlined(attr
.GetFontUnderlined());
6099 if (attr
.HasFaceName())
6100 newAttr
.SetFontFaceName(attr
.GetFontFaceName());
6102 if (attr
.HasAlignment())
6103 newAttr
.SetAlignment(attr
.GetAlignment());
6104 else if (attrDef
.HasAlignment())
6105 newAttr
.SetAlignment(attrDef
.GetAlignment());
6108 newAttr
.SetTabs(attr
.GetTabs());
6109 else if (attrDef
.HasTabs())
6110 newAttr
.SetTabs(attrDef
.GetTabs());
6112 if (attr
.HasLeftIndent())
6113 newAttr
.SetLeftIndent(attr
.GetLeftIndent(), attr
.GetLeftSubIndent());
6114 else if (attrDef
.HasLeftIndent())
6115 newAttr
.SetLeftIndent(attrDef
.GetLeftIndent(), attr
.GetLeftSubIndent());
6117 if (attr
.HasRightIndent())
6118 newAttr
.SetRightIndent(attr
.GetRightIndent());
6119 else if (attrDef
.HasRightIndent())
6120 newAttr
.SetRightIndent(attrDef
.GetRightIndent());
6124 if (attr
.HasParagraphSpacingAfter())
6125 newAttr
.SetParagraphSpacingAfter(attr
.GetParagraphSpacingAfter());
6127 if (attr
.HasParagraphSpacingBefore())
6128 newAttr
.SetParagraphSpacingBefore(attr
.GetParagraphSpacingBefore());
6130 if (attr
.HasLineSpacing())
6131 newAttr
.SetLineSpacing(attr
.GetLineSpacing());
6133 if (attr
.HasCharacterStyleName())
6134 newAttr
.SetCharacterStyleName(attr
.GetCharacterStyleName());
6136 if (attr
.HasParagraphStyleName())
6137 newAttr
.SetParagraphStyleName(attr
.GetParagraphStyleName());
6139 if (attr
.HasBulletStyle())
6140 newAttr
.SetBulletStyle(attr
.GetBulletStyle());
6142 if (attr
.HasBulletNumber())
6143 newAttr
.SetBulletNumber(attr
.GetBulletNumber());
6145 if (attr
.HasBulletSymbol())
6147 newAttr
.SetBulletSymbol(attr
.GetBulletSymbol());
6148 newAttr
.SetBulletFont(attr
.GetBulletFont());
6155 * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes.
6158 wxTextAttrEx::wxTextAttrEx(const wxTextAttrEx
& attr
): wxTextAttr(attr
)
6160 m_paragraphSpacingAfter
= attr
.m_paragraphSpacingAfter
;
6161 m_paragraphSpacingBefore
= attr
.m_paragraphSpacingBefore
;
6162 m_lineSpacing
= attr
.m_lineSpacing
;
6163 m_paragraphStyleName
= attr
.m_paragraphStyleName
;
6164 m_characterStyleName
= attr
.m_characterStyleName
;
6165 m_bulletStyle
= attr
.m_bulletStyle
;
6166 m_bulletNumber
= attr
.m_bulletNumber
;
6167 m_bulletSymbol
= attr
.m_bulletSymbol
;
6168 m_bulletFont
= attr
.m_bulletFont
;
6171 // Initialise this object.
6172 void wxTextAttrEx::Init()
6174 m_paragraphSpacingAfter
= 0;
6175 m_paragraphSpacingBefore
= 0;
6177 m_bulletStyle
= wxTEXT_ATTR_BULLET_STYLE_NONE
;
6180 m_bulletSymbol
= wxT('*');
6183 // Assignment from a wxTextAttrEx object
6184 void wxTextAttrEx::operator= (const wxTextAttrEx
& attr
)
6186 wxTextAttr::operator= (attr
);
6188 m_paragraphSpacingAfter
= attr
.m_paragraphSpacingAfter
;
6189 m_paragraphSpacingBefore
= attr
.m_paragraphSpacingBefore
;
6190 m_lineSpacing
= attr
.m_lineSpacing
;
6191 m_characterStyleName
= attr
.m_characterStyleName
;
6192 m_paragraphStyleName
= attr
.m_paragraphStyleName
;
6193 m_bulletStyle
= attr
.m_bulletStyle
;
6194 m_bulletNumber
= attr
.m_bulletNumber
;
6195 m_bulletSymbol
= attr
.m_bulletSymbol
;
6196 m_bulletFont
= attr
.m_bulletFont
;
6199 // Assignment from a wxTextAttr object.
6200 void wxTextAttrEx::operator= (const wxTextAttr
& attr
)
6202 wxTextAttr::operator= (attr
);
6205 wxTextAttrEx
wxTextAttrEx::CombineEx(const wxTextAttrEx
& attr
,
6206 const wxTextAttrEx
& attrDef
,
6207 const wxTextCtrlBase
*text
)
6209 wxTextAttrEx newAttr
;
6211 // If attr specifies the complete font, just use that font, overriding all
6212 // default font attributes.
6213 if ((attr
.GetFlags() & wxTEXT_ATTR_FONT
) == wxTEXT_ATTR_FONT
)
6214 newAttr
.SetFont(attr
.GetFont());
6217 // First find the basic, default font
6221 if (attrDef
.HasFont())
6223 flags
= (attrDef
.GetFlags() & wxTEXT_ATTR_FONT
);
6224 font
= attrDef
.GetFont();
6229 font
= text
->GetFont();
6231 // We leave flags at 0 because no font attributes have been specified yet
6234 font
= *wxNORMAL_FONT
;
6236 // Otherwise, if there are font attributes in attr, apply them
6237 if (attr
.GetFlags() & wxTEXT_ATTR_FONT
)
6241 flags
|= wxTEXT_ATTR_FONT_SIZE
;
6242 font
.SetPointSize(attr
.GetFont().GetPointSize());
6244 if (attr
.HasItalic())
6246 flags
|= wxTEXT_ATTR_FONT_ITALIC
;;
6247 font
.SetStyle(attr
.GetFont().GetStyle());
6249 if (attr
.HasWeight())
6251 flags
|= wxTEXT_ATTR_FONT_WEIGHT
;
6252 font
.SetWeight(attr
.GetFont().GetWeight());
6254 if (attr
.HasFaceName())
6256 flags
|= wxTEXT_ATTR_FONT_FACE
;
6257 font
.SetFaceName(attr
.GetFont().GetFaceName());
6259 if (attr
.HasUnderlined())
6261 flags
|= wxTEXT_ATTR_FONT_UNDERLINE
;
6262 font
.SetUnderlined(attr
.GetFont().GetUnderlined());
6264 newAttr
.SetFont(font
);
6265 newAttr
.SetFlags(newAttr
.GetFlags()|flags
);
6269 // TODO: should really check we are specifying these in the flags,
6270 // before setting them, as per above; or we will set them willy-nilly.
6271 // However, we should also check whether this is the intention
6272 // as per wxTextAttr::Combine, i.e. always to have valid colours
6274 wxColour colFg
= attr
.GetTextColour();
6277 colFg
= attrDef
.GetTextColour();
6279 if ( text
&& !colFg
.Ok() )
6280 colFg
= text
->GetForegroundColour();
6283 wxColour colBg
= attr
.GetBackgroundColour();
6286 colBg
= attrDef
.GetBackgroundColour();
6288 if ( text
&& !colBg
.Ok() )
6289 colBg
= text
->GetBackgroundColour();
6292 newAttr
.SetTextColour(colFg
);
6293 newAttr
.SetBackgroundColour(colBg
);
6295 if (attr
.HasAlignment())
6296 newAttr
.SetAlignment(attr
.GetAlignment());
6297 else if (attrDef
.HasAlignment())
6298 newAttr
.SetAlignment(attrDef
.GetAlignment());
6301 newAttr
.SetTabs(attr
.GetTabs());
6302 else if (attrDef
.HasTabs())
6303 newAttr
.SetTabs(attrDef
.GetTabs());
6305 if (attr
.HasLeftIndent())
6306 newAttr
.SetLeftIndent(attr
.GetLeftIndent(), attr
.GetLeftSubIndent());
6307 else if (attrDef
.HasLeftIndent())
6308 newAttr
.SetLeftIndent(attrDef
.GetLeftIndent(), attr
.GetLeftSubIndent());
6310 if (attr
.HasRightIndent())
6311 newAttr
.SetRightIndent(attr
.GetRightIndent());
6312 else if (attrDef
.HasRightIndent())
6313 newAttr
.SetRightIndent(attrDef
.GetRightIndent());
6317 if (attr
.HasParagraphSpacingAfter())
6318 newAttr
.SetParagraphSpacingAfter(attr
.GetParagraphSpacingAfter());
6320 if (attr
.HasParagraphSpacingBefore())
6321 newAttr
.SetParagraphSpacingBefore(attr
.GetParagraphSpacingBefore());
6323 if (attr
.HasLineSpacing())
6324 newAttr
.SetLineSpacing(attr
.GetLineSpacing());
6326 if (attr
.HasCharacterStyleName())
6327 newAttr
.SetCharacterStyleName(attr
.GetCharacterStyleName());
6329 if (attr
.HasParagraphStyleName())
6330 newAttr
.SetParagraphStyleName(attr
.GetParagraphStyleName());
6332 if (attr
.HasBulletStyle())
6333 newAttr
.SetBulletStyle(attr
.GetBulletStyle());
6335 if (attr
.HasBulletNumber())
6336 newAttr
.SetBulletNumber(attr
.GetBulletNumber());
6338 if (attr
.HasBulletSymbol())
6340 newAttr
.SetBulletSymbol(attr
.GetBulletSymbol());
6341 newAttr
.SetBulletFont(attr
.GetBulletFont());
6349 * wxRichTextFileHandler
6350 * Base class for file handlers
6353 IMPLEMENT_CLASS(wxRichTextFileHandler
, wxObject
)
6356 bool wxRichTextFileHandler::LoadFile(wxRichTextBuffer
*buffer
, const wxString
& filename
)
6358 wxFFileInputStream
stream(filename
);
6360 return LoadFile(buffer
, stream
);
6365 bool wxRichTextFileHandler::SaveFile(wxRichTextBuffer
*buffer
, const wxString
& filename
)
6367 wxFFileOutputStream
stream(filename
);
6369 return SaveFile(buffer
, stream
);
6373 #endif // wxUSE_STREAMS
6375 /// Can we handle this filename (if using files)? By default, checks the extension.
6376 bool wxRichTextFileHandler::CanHandle(const wxString
& filename
) const
6378 wxString path
, file
, ext
;
6379 wxSplitPath(filename
, & path
, & file
, & ext
);
6381 return (ext
.Lower() == GetExtension());
6385 * wxRichTextTextHandler
6386 * Plain text handler
6389 IMPLEMENT_CLASS(wxRichTextPlainTextHandler
, wxRichTextFileHandler
)
6392 bool wxRichTextPlainTextHandler::DoLoadFile(wxRichTextBuffer
*buffer
, wxInputStream
& stream
)
6400 while (!stream
.Eof())
6402 int ch
= stream
.GetC();
6406 if (ch
== 10 && lastCh
!= 13)
6409 if (ch
> 0 && ch
!= 10)
6417 buffer
->AddParagraphs(str
);
6418 buffer
->UpdateRanges();
6424 bool wxRichTextPlainTextHandler::DoSaveFile(wxRichTextBuffer
*buffer
, wxOutputStream
& stream
)
6429 wxString text
= buffer
->GetText();
6430 wxCharBuffer buf
= text
.ToAscii();
6432 stream
.Write((const char*) buf
, text
.length());
6435 #endif // wxUSE_STREAMS
6438 * Stores information about an image, in binary in-memory form
6441 wxRichTextImageBlock::wxRichTextImageBlock()
6446 wxRichTextImageBlock::wxRichTextImageBlock(const wxRichTextImageBlock
& block
):wxObject()
6452 wxRichTextImageBlock::~wxRichTextImageBlock()
6461 void wxRichTextImageBlock::Init()
6468 void wxRichTextImageBlock::Clear()
6477 // Load the original image into a memory block.
6478 // If the image is not a JPEG, we must convert it into a JPEG
6479 // to conserve space.
6480 // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
6481 // load the image a 2nd time.
6483 bool wxRichTextImageBlock::MakeImageBlock(const wxString
& filename
, int imageType
, wxImage
& image
, bool convertToJPEG
)
6485 m_imageType
= imageType
;
6487 wxString
filenameToRead(filename
);
6488 bool removeFile
= false;
6490 if (imageType
== -1)
6491 return false; // Could not determine image type
6493 if ((imageType
!= wxBITMAP_TYPE_JPEG
) && convertToJPEG
)
6496 bool success
= wxGetTempFileName(_("image"), tempFile
) ;
6500 wxUnusedVar(success
);
6502 image
.SaveFile(tempFile
, wxBITMAP_TYPE_JPEG
);
6503 filenameToRead
= tempFile
;
6506 m_imageType
= wxBITMAP_TYPE_JPEG
;
6509 if (!file
.Open(filenameToRead
))
6512 m_dataSize
= (size_t) file
.Length();
6517 m_data
= ReadBlock(filenameToRead
, m_dataSize
);
6520 wxRemoveFile(filenameToRead
);
6522 return (m_data
!= NULL
);
6525 // Make an image block from the wxImage in the given
6527 bool wxRichTextImageBlock::MakeImageBlock(wxImage
& image
, int imageType
, int quality
)
6529 m_imageType
= imageType
;
6530 image
.SetOption(wxT("quality"), quality
);
6532 if (imageType
== -1)
6533 return false; // Could not determine image type
6536 bool success
= wxGetTempFileName(_("image"), tempFile
) ;
6539 wxUnusedVar(success
);
6541 if (!image
.SaveFile(tempFile
, m_imageType
))
6543 if (wxFileExists(tempFile
))
6544 wxRemoveFile(tempFile
);
6549 if (!file
.Open(tempFile
))
6552 m_dataSize
= (size_t) file
.Length();
6557 m_data
= ReadBlock(tempFile
, m_dataSize
);
6559 wxRemoveFile(tempFile
);
6561 return (m_data
!= NULL
);
6566 bool wxRichTextImageBlock::Write(const wxString
& filename
)
6568 return WriteBlock(filename
, m_data
, m_dataSize
);
6571 void wxRichTextImageBlock::Copy(const wxRichTextImageBlock
& block
)
6573 m_imageType
= block
.m_imageType
;
6579 m_dataSize
= block
.m_dataSize
;
6580 if (m_dataSize
== 0)
6583 m_data
= new unsigned char[m_dataSize
];
6585 for (i
= 0; i
< m_dataSize
; i
++)
6586 m_data
[i
] = block
.m_data
[i
];
6590 void wxRichTextImageBlock::operator=(const wxRichTextImageBlock
& block
)
6595 // Load a wxImage from the block
6596 bool wxRichTextImageBlock::Load(wxImage
& image
)
6601 // Read in the image.
6603 wxMemoryInputStream
mstream(m_data
, m_dataSize
);
6604 bool success
= image
.LoadFile(mstream
, GetImageType());
6607 bool success
= wxGetTempFileName(_("image"), tempFile
) ;
6610 if (!WriteBlock(tempFile
, m_data
, m_dataSize
))
6614 success
= image
.LoadFile(tempFile
, GetImageType());
6615 wxRemoveFile(tempFile
);
6621 // Write data in hex to a stream
6622 bool wxRichTextImageBlock::WriteHex(wxOutputStream
& stream
)
6626 for (i
= 0; i
< (int) m_dataSize
; i
++)
6628 hex
= wxDecToHex(m_data
[i
]);
6629 wxCharBuffer buf
= hex
.ToAscii();
6631 stream
.Write((const char*) buf
, hex
.length());
6637 // Read data in hex from a stream
6638 bool wxRichTextImageBlock::ReadHex(wxInputStream
& stream
, int length
, int imageType
)
6640 int dataSize
= length
/2;
6645 wxString
str(wxT(" "));
6646 m_data
= new unsigned char[dataSize
];
6648 for (i
= 0; i
< dataSize
; i
++)
6650 str
[0] = stream
.GetC();
6651 str
[1] = stream
.GetC();
6653 m_data
[i
] = (unsigned char)wxHexToDec(str
);
6656 m_dataSize
= dataSize
;
6657 m_imageType
= imageType
;
6662 // Allocate and read from stream as a block of memory
6663 unsigned char* wxRichTextImageBlock::ReadBlock(wxInputStream
& stream
, size_t size
)
6665 unsigned char* block
= new unsigned char[size
];
6669 stream
.Read(block
, size
);
6674 unsigned char* wxRichTextImageBlock::ReadBlock(const wxString
& filename
, size_t size
)
6676 wxFileInputStream
stream(filename
);
6680 return ReadBlock(stream
, size
);
6683 // Write memory block to stream
6684 bool wxRichTextImageBlock::WriteBlock(wxOutputStream
& stream
, unsigned char* block
, size_t size
)
6686 stream
.Write((void*) block
, size
);
6687 return stream
.IsOk();
6691 // Write memory block to file
6692 bool wxRichTextImageBlock::WriteBlock(const wxString
& filename
, unsigned char* block
, size_t size
)
6694 wxFileOutputStream
outStream(filename
);
6695 if (!outStream
.Ok())
6698 return WriteBlock(outStream
, block
, size
);
6704 * The data object for a wxRichTextBuffer
6707 const wxChar
*wxRichTextBufferDataObject::ms_richTextBufferFormatId
= wxT("wxShape");
6709 wxRichTextBufferDataObject::wxRichTextBufferDataObject(wxRichTextBuffer
* richTextBuffer
)
6711 m_richTextBuffer
= richTextBuffer
;
6713 // this string should uniquely identify our format, but is otherwise
6715 m_formatRichTextBuffer
.SetId(GetRichTextBufferFormatId());
6717 SetFormat(m_formatRichTextBuffer
);
6720 wxRichTextBufferDataObject::~wxRichTextBufferDataObject()
6722 delete m_richTextBuffer
;
6725 // after a call to this function, the richTextBuffer is owned by the caller and it
6726 // is responsible for deleting it!
6727 wxRichTextBuffer
* wxRichTextBufferDataObject::GetRichTextBuffer()
6729 wxRichTextBuffer
* richTextBuffer
= m_richTextBuffer
;
6730 m_richTextBuffer
= NULL
;
6732 return richTextBuffer
;
6735 wxDataFormat
wxRichTextBufferDataObject::GetPreferredFormat(Direction
WXUNUSED(dir
)) const
6737 return m_formatRichTextBuffer
;
6740 size_t wxRichTextBufferDataObject::GetDataSize() const
6742 if (!m_richTextBuffer
)
6748 wxStringOutputStream
stream(& bufXML
);
6749 if (!m_richTextBuffer
->SaveFile(stream
, wxRICHTEXT_TYPE_XML
))
6751 wxLogError(wxT("Could not write the buffer to an XML stream.\nYou may have forgotten to add the XML file handler."));
6757 wxCharBuffer buffer
= bufXML
.mb_str(wxConvUTF8
);
6758 return strlen(buffer
) + 1;
6760 return bufXML
.Length()+1;
6764 bool wxRichTextBufferDataObject::GetDataHere(void *pBuf
) const
6766 if (!pBuf
|| !m_richTextBuffer
)
6772 wxStringOutputStream
stream(& bufXML
);
6773 if (!m_richTextBuffer
->SaveFile(stream
, wxRICHTEXT_TYPE_XML
))
6775 wxLogError(wxT("Could not write the buffer to an XML stream.\nYou may have forgotten to add the XML file handler."));
6781 wxCharBuffer buffer
= bufXML
.mb_str(wxConvUTF8
);
6782 size_t len
= strlen(buffer
);
6783 memcpy((char*) pBuf
, (const char*) buffer
, len
);
6784 ((char*) pBuf
)[len
] = 0;
6786 size_t len
= bufXML
.Length();
6787 memcpy((char*) pBuf
, (const char*) bufXML
.c_str(), len
);
6788 ((char*) pBuf
)[len
] = 0;
6794 bool wxRichTextBufferDataObject::SetData(size_t WXUNUSED(len
), const void *buf
)
6796 delete m_richTextBuffer
;
6797 m_richTextBuffer
= NULL
;
6799 wxString
bufXML((const char*) buf
, wxConvUTF8
);
6801 m_richTextBuffer
= new wxRichTextBuffer
;
6803 wxStringInputStream
stream(bufXML
);
6804 if (!m_richTextBuffer
->LoadFile(stream
, wxRICHTEXT_TYPE_XML
))
6806 wxLogError(wxT("Could not read the buffer from an XML stream.\nYou may have forgotten to add the XML file handler."));
6808 delete m_richTextBuffer
;
6809 m_richTextBuffer
= NULL
;