+ DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, false);
+
+#if USE_KERNING_FIX
+ if (stringChunk.Find(wxT("\t")) == wxNOT_FOUND)
+ {
+ // Compensate for kerning difference
+ wxString stringFragment2(str.Mid(r1 - offset, fragmentLen+1));
+ wxString stringFragment3(str.Mid(r1 - offset + fragmentLen, 1));
+
+ wxCoord w1, h1, w2, h2, w3, h3;
+ dc.GetTextExtent(stringFragment, & w1, & h1);
+ dc.GetTextExtent(stringFragment2, & w2, & h2);
+ dc.GetTextExtent(stringFragment3, & w3, & h3);
+
+ int kerningDiff = (w1 + w3) - w2;
+ x = x - kerningDiff;
+ }
+#endif
+ }
+
+ // 2. Selected chunk, if any.
+ if (selectionRange.GetEnd() >= range.GetStart())
+ {
+ int s1 = wxMax(selectionRange.GetStart(), range.GetStart());
+ int s2 = wxMin(selectionRange.GetEnd(), range.GetEnd());
+
+ int fragmentLen = s2 - s1 + 1;
+ if (fragmentLen < 0)
+ {
+ wxLogDebug(wxT("Mid(%d, %d"), (int)(s1 - offset), (int)fragmentLen);
+ }
+ wxString stringFragment = str.Mid(s1 - offset, fragmentLen);
+
+ DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, true);
+
+#if USE_KERNING_FIX
+ if (stringChunk.Find(wxT("\t")) == wxNOT_FOUND)
+ {
+ // Compensate for kerning difference
+ wxString stringFragment2(str.Mid(s1 - offset, fragmentLen+1));
+ wxString stringFragment3(str.Mid(s1 - offset + fragmentLen, 1));
+
+ wxCoord w1, h1, w2, h2, w3, h3;
+ dc.GetTextExtent(stringFragment, & w1, & h1);
+ dc.GetTextExtent(stringFragment2, & w2, & h2);
+ dc.GetTextExtent(stringFragment3, & w3, & h3);
+
+ int kerningDiff = (w1 + w3) - w2;
+ x = x - kerningDiff;
+ }
+#endif
+ }
+
+ // 3. Remaining unselected chunk, if any
+ if (selectionRange.GetEnd() < range.GetEnd())
+ {
+ int s2 = wxMin(selectionRange.GetEnd()+1, range.GetEnd());
+ int r2 = range.GetEnd();
+
+ int fragmentLen = r2 - s2 + 1;
+ if (fragmentLen < 0)
+ {
+ wxLogDebug(wxT("Mid(%d, %d"), (int)(s2 - offset), (int)fragmentLen);
+ }
+ wxString stringFragment = str.Mid(s2 - offset, fragmentLen);
+
+ DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, false);
+ }
+ }
+
+ return true;
+}
+
+bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect,wxString& str, wxCoord& x, wxCoord& y, bool selected)
+{
+ bool hasTabs = (str.Find(wxT('\t')) != wxNOT_FOUND);
+
+ wxArrayInt tabArray;
+ int tabCount;
+ if (hasTabs)
+ {
+ if (attr.GetTabs().IsEmpty())
+ tabArray = wxRichTextParagraph::GetDefaultTabs();
+ else
+ tabArray = attr.GetTabs();
+ tabCount = tabArray.GetCount();
+
+ for (int i = 0; i < tabCount; ++i)
+ {
+ int pos = tabArray[i];
+ pos = ConvertTenthsMMToPixels(dc, pos);
+ tabArray[i] = pos;
+ }
+ }
+ else
+ tabCount = 0;
+
+ int nextTabPos = -1;
+ int tabPos = -1;
+ wxCoord w, h;
+
+ if (selected)
+ {
+ wxColour highlightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
+ wxColour highlightTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
+
+ wxCheckSetBrush(dc, wxBrush(highlightColour));
+ wxCheckSetPen(dc, wxPen(highlightColour));
+ dc.SetTextForeground(highlightTextColour);
+ dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+ }
+ else
+ {
+ dc.SetTextForeground(attr.GetTextColour());
+
+ if (attr.HasFlag(wxTEXT_ATTR_BACKGROUND_COLOUR) && attr.GetBackgroundColour().IsOk())
+ {
+ dc.SetBackgroundMode(wxBRUSHSTYLE_SOLID);
+ dc.SetTextBackground(attr.GetBackgroundColour());
+ }
+ else
+ dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+ }
+
+ wxCoord x_orig = GetParent()->GetPosition().x;
+ while (hasTabs)
+ {
+ // the string has a tab
+ // break up the string at the Tab
+ wxString stringChunk = str.BeforeFirst(wxT('\t'));
+ str = str.AfterFirst(wxT('\t'));
+ dc.GetTextExtent(stringChunk, & w, & h);
+ tabPos = x + w;
+ bool not_found = true;
+ for (int i = 0; i < tabCount && not_found; ++i)
+ {
+ nextTabPos = tabArray.Item(i) + x_orig;
+
+ // Find the next tab position.
+ // Even if we're at the end of the tab array, we must still draw the chunk.
+
+ if (nextTabPos > tabPos || (i == (tabCount - 1)))
+ {
+ if (nextTabPos <= tabPos)
+ {
+ int defaultTabWidth = ConvertTenthsMMToPixels(dc, WIDTH_FOR_DEFAULT_TABS);
+ nextTabPos = tabPos + defaultTabWidth;
+ }
+
+ not_found = false;
+ if (selected)
+ {
+ w = nextTabPos - x;
+ wxRect selRect(x, rect.y, w, rect.GetHeight());
+ dc.DrawRectangle(selRect);
+ }
+ dc.DrawText(stringChunk, x, y);
+
+ if (attr.HasTextEffects() && (attr.GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH))
+ {
+ wxPen oldPen = dc.GetPen();
+ wxCheckSetPen(dc, wxPen(attr.GetTextColour(), 1));
+ dc.DrawLine(x, (int) (y+(h/2)+0.5), x+w, (int) (y+(h/2)+0.5));
+ wxCheckSetPen(dc, oldPen);
+ }
+
+ x = nextTabPos;
+ }
+ }
+ hasTabs = (str.Find(wxT('\t')) != wxNOT_FOUND);
+ }
+
+ if (!str.IsEmpty())
+ {
+ dc.GetTextExtent(str, & w, & h);
+ if (selected)
+ {
+ wxRect selRect(x, rect.y, w, rect.GetHeight());
+ dc.DrawRectangle(selRect);
+ }
+ dc.DrawText(str, x, y);
+
+ if (attr.HasTextEffects() && (attr.GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH))
+ {
+ wxPen oldPen = dc.GetPen();
+ wxCheckSetPen(dc, wxPen(attr.GetTextColour(), 1));
+ dc.DrawLine(x, (int) (y+(h/2)+0.5), x+w, (int) (y+(h/2)+0.5));
+ wxCheckSetPen(dc, oldPen);
+ }
+
+ x += w;
+ }
+
+ return true;
+}
+
+/// Lay the item out
+bool wxRichTextPlainText::Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& WXUNUSED(rect), const wxRect& WXUNUSED(parentRect), int WXUNUSED(style))
+{
+ // Only lay out if we haven't already cached the size
+ if (m_size.x == -1)
+ GetRangeSize(GetRange(), m_size, m_descent, dc, context, 0, wxPoint(0, 0));
+ m_maxSize = m_size;
+ // Eventually we want to have a reasonable estimate of minimum size.
+ m_minSize = wxSize(0, 0);
+ return true;
+}
+
+/// Copy
+void wxRichTextPlainText::Copy(const wxRichTextPlainText& obj)
+{
+ wxRichTextObject::Copy(obj);
+
+ m_text = obj.m_text;
+}
+
+/// Get/set the object size for the given range. Returns false if the range
+/// is invalid for this object.
+bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int WXUNUSED(flags), const wxPoint& position, const wxSize& WXUNUSED(parentSize), wxArrayInt* partialExtents) const
+{
+ if (!range.IsWithin(GetRange()))
+ return false;
+
+ wxRichTextParagraph* para = wxDynamicCast(GetParent(), wxRichTextParagraph);
+ wxASSERT (para != NULL);
+
+ int relativeX = position.x - GetParent()->GetPosition().x;
+
+ wxRichTextAttr textAttr(para ? para->GetCombinedAttributes(GetAttributes()) : GetAttributes());
+ context.ApplyVirtualAttributes(textAttr, (wxRichTextObject*) this);
+
+ // Always assume unformatted text, since at this level we have no knowledge
+ // of line breaks - and we don't need it, since we'll calculate size within
+ // formatted text by doing it in chunks according to the line ranges
+
+ bool bScript(false);
+ wxFont font(GetBuffer()->GetFontTable().FindFont(textAttr));
+ if (font.IsOk())
+ {
+ if ( textAttr.HasTextEffects() && ( (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT)
+ || (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) )
+ {
+ wxFont textFont = font;
+ if (textFont.IsUsingSizeInPixels())
+ {
+ double size = static_cast<double>(textFont.GetPixelSize().y) / wxSCRIPT_MUL_FACTOR;
+ textFont.SetPixelSize(wxSize(0, static_cast<int>(size)));
+ }
+ else
+ {
+ double size = static_cast<double>(textFont.GetPointSize()) / wxSCRIPT_MUL_FACTOR;
+ textFont.SetPointSize(static_cast<int>(size));
+ }
+ wxCheckSetFont(dc, textFont);
+ bScript = true;
+ }
+ else if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SMALL_CAPITALS))
+ {
+ wxFont textFont = font;
+ textFont.SetPointSize((int) (textFont.GetPointSize()*0.75));
+ wxCheckSetFont(dc, textFont);
+ bScript = true;
+ }
+ else
+ {
+ wxCheckSetFont(dc, font);
+ }
+ }
+
+ bool haveDescent = false;
+ int startPos = range.GetStart() - GetRange().GetStart();
+ long len = range.GetLength();
+
+ wxString str(m_text);
+ if (context.HasVirtualText(this))
+ {
+ if (!context.GetVirtualText(this, str) || str.Length() != m_text.Length())
+ str = m_text;
+ }
+
+ wxString toReplace = wxRichTextLineBreakChar;
+ str.Replace(toReplace, wxT(" "));
+
+ wxString stringChunk = str.Mid(startPos, (size_t) len);
+
+ if (textAttr.HasTextEffects() && (textAttr.GetTextEffects() & (wxTEXT_ATTR_EFFECT_CAPITALS|wxTEXT_ATTR_EFFECT_SMALL_CAPITALS)))
+ stringChunk.MakeUpper();
+
+ wxCoord w, h;
+ int width = 0;
+ if (stringChunk.Find(wxT('\t')) != wxNOT_FOUND)
+ {
+ // the string has a tab
+ wxArrayInt tabArray;
+ if (textAttr.GetTabs().IsEmpty())
+ tabArray = wxRichTextParagraph::GetDefaultTabs();
+ else
+ tabArray = textAttr.GetTabs();
+
+ int tabCount = tabArray.GetCount();
+
+ for (int i = 0; i < tabCount; ++i)
+ {
+ int pos = tabArray[i];
+ pos = ((wxRichTextPlainText*) this)->ConvertTenthsMMToPixels(dc, pos);
+ tabArray[i] = pos;
+ }
+
+ int nextTabPos = -1;
+
+ while (stringChunk.Find(wxT('\t')) >= 0)
+ {
+ int absoluteWidth = 0;
+
+ // the string has a tab
+ // break up the string at the Tab
+ wxString stringFragment = stringChunk.BeforeFirst(wxT('\t'));
+ stringChunk = stringChunk.AfterFirst(wxT('\t'));
+
+ if (partialExtents)
+ {
+ int oldWidth;
+ if (partialExtents->GetCount() > 0)
+ oldWidth = (*partialExtents)[partialExtents->GetCount()-1];
+ else
+ oldWidth = 0;
+
+ // Add these partial extents
+ wxArrayInt p;
+ dc.GetPartialTextExtents(stringFragment, p);
+ size_t j;
+ for (j = 0; j < p.GetCount(); j++)
+ partialExtents->Add(oldWidth + p[j]);
+
+ if (partialExtents->GetCount() > 0)
+ absoluteWidth = (*partialExtents)[(*partialExtents).GetCount()-1] + relativeX;
+ else
+ absoluteWidth = relativeX;
+ }
+ else
+ {
+ dc.GetTextExtent(stringFragment, & w, & h);
+ width += w;
+ absoluteWidth = width + relativeX;
+ haveDescent = true;
+ }
+
+ bool notFound = true;
+ for (int i = 0; i < tabCount && notFound; ++i)
+ {
+ nextTabPos = tabArray.Item(i);
+
+ // Find the next tab position.
+ // Even if we're at the end of the tab array, we must still process the chunk.
+
+ if (nextTabPos > absoluteWidth || (i == (tabCount - 1)))
+ {
+ if (nextTabPos <= absoluteWidth)
+ {
+ int defaultTabWidth = ((wxRichTextPlainText*) this)->ConvertTenthsMMToPixels(dc, WIDTH_FOR_DEFAULT_TABS);
+ nextTabPos = absoluteWidth + defaultTabWidth;
+ }
+
+ notFound = false;
+ width = nextTabPos - relativeX;
+
+ if (partialExtents)
+ partialExtents->Add(width);
+ }
+ }
+ }
+ }
+
+ if (!stringChunk.IsEmpty())
+ {
+ if (partialExtents)
+ {
+ int oldWidth;
+ if (partialExtents->GetCount() > 0)
+ oldWidth = (*partialExtents)[partialExtents->GetCount()-1];
+ else
+ oldWidth = 0;
+
+ // Add these partial extents
+ wxArrayInt p;
+ dc.GetPartialTextExtents(stringChunk, p);
+ size_t j;
+ for (j = 0; j < p.GetCount(); j++)
+ partialExtents->Add(oldWidth + p[j]);
+ }
+ else
+ {
+ dc.GetTextExtent(stringChunk, & w, & h, & descent);
+ width += w;
+ haveDescent = true;
+ }
+ }
+
+ if (partialExtents)
+ {
+ int charHeight = dc.GetCharHeight();
+ if ((*partialExtents).GetCount() > 0)
+ w = (*partialExtents)[partialExtents->GetCount()-1];
+ else
+ w = 0;
+ size = wxSize(w, charHeight);
+ }
+ else
+ {
+ size = wxSize(width, dc.GetCharHeight());
+ }
+
+ if (!haveDescent)
+ dc.GetTextExtent(wxT("X"), & w, & h, & descent);
+
+ if ( bScript )
+ dc.SetFont(font);
+
+ return true;
+}
+
+/// Do a split, returning an object containing the second part, and setting
+/// the first part in 'this'.
+wxRichTextObject* wxRichTextPlainText::DoSplit(long pos)
+{
+ long index = pos - GetRange().GetStart();
+
+ if (index < 0 || index >= (int) m_text.length())
+ return NULL;
+
+ wxString firstPart = m_text.Mid(0, index);
+ wxString secondPart = m_text.Mid(index);
+
+ m_text = firstPart;
+
+ wxRichTextPlainText* newObject = new wxRichTextPlainText(secondPart);
+ newObject->SetAttributes(GetAttributes());
+ newObject->SetProperties(GetProperties());
+
+ newObject->SetRange(wxRichTextRange(pos, GetRange().GetEnd()));
+ GetRange().SetEnd(pos-1);
+
+ return newObject;
+}
+
+/// Calculate range
+void wxRichTextPlainText::CalculateRange(long start, long& end)
+{
+ end = start + m_text.length() - 1;
+ m_range.SetRange(start, end);
+}
+
+/// Delete range
+bool wxRichTextPlainText::DeleteRange(const wxRichTextRange& range)
+{
+ wxRichTextRange r = range;
+
+ r.LimitTo(GetRange());
+
+ if (r.GetStart() == GetRange().GetStart() && r.GetEnd() == GetRange().GetEnd())
+ {
+ m_text.Empty();
+ return true;
+ }
+
+ long startIndex = r.GetStart() - GetRange().GetStart();
+ long len = r.GetLength();
+
+ m_text = m_text.Mid(0, startIndex) + m_text.Mid(startIndex+len);
+ return true;
+}
+
+/// Get text for the given range.
+wxString wxRichTextPlainText::GetTextForRange(const wxRichTextRange& range) const
+{
+ wxRichTextRange r = range;
+
+ r.LimitTo(GetRange());
+
+ long startIndex = r.GetStart() - GetRange().GetStart();
+ long len = r.GetLength();
+
+ return m_text.Mid(startIndex, len);
+}
+
+/// Returns true if this object can merge itself with the given one.
+bool wxRichTextPlainText::CanMerge(wxRichTextObject* object, wxRichTextDrawingContext& context) const
+{
+ // JACS 2013-01-27
+ if (!context.GetVirtualAttributesEnabled())
+ {
+ return object->GetClassInfo() == wxCLASSINFO(wxRichTextPlainText) &&
+ (m_text.empty() || (wxTextAttrEq(GetAttributes(), object->GetAttributes()) && m_properties == object->GetProperties()));
+ }
+ else
+ {
+ wxRichTextPlainText* otherObj = wxDynamicCast(object, wxRichTextPlainText);
+ if (!otherObj || m_text.empty())
+ return false;
+
+ if (!wxTextAttrEq(GetAttributes(), object->GetAttributes()) || !(m_properties == object->GetProperties()))
+ return false;
+
+ // Check if differing virtual attributes makes it impossible to merge
+ // these strings.
+
+ bool hasVirtualAttr1 = context.HasVirtualAttributes((wxRichTextObject*) this);
+ bool hasVirtualAttr2 = context.HasVirtualAttributes((wxRichTextObject*) object);
+ if (!hasVirtualAttr1 && !hasVirtualAttr2)
+ return true;
+ else if (hasVirtualAttr1 != hasVirtualAttr2)
+ return false;
+ else
+ {
+ wxRichTextAttr virtualAttr1 = context.GetVirtualAttributes((wxRichTextObject*) this);
+ wxRichTextAttr virtualAttr2 = context.GetVirtualAttributes((wxRichTextObject*) object);
+ return virtualAttr1 == virtualAttr2;
+ }
+ }
+}
+
+/// Returns true if this object merged itself with the given one.
+/// The calling code will then delete the given object.
+bool wxRichTextPlainText::Merge(wxRichTextObject* object, wxRichTextDrawingContext& WXUNUSED(context))
+{
+ wxRichTextPlainText* textObject = wxDynamicCast(object, wxRichTextPlainText);
+ wxASSERT( textObject != NULL );
+
+ if (textObject)
+ {
+ m_text += textObject->GetText();
+ wxRichTextApplyStyle(m_attributes, textObject->GetAttributes());
+ return true;
+ }
+ else
+ return false;
+}
+
+bool wxRichTextPlainText::CanSplit(wxRichTextDrawingContext& context) const
+{
+ // If this object has any virtual attributes at all, whether for the whole object
+ // or individual ones, we should try splitting it by calling Split.
+ // Must be more than one character in order to be able to split.
+ return m_text.Length() > 1 && context.HasVirtualAttributes((wxRichTextObject*) this);
+}
+
+wxRichTextObject* wxRichTextPlainText::Split(wxRichTextDrawingContext& context)
+{
+ int count = context.GetVirtualSubobjectAttributesCount(this);
+ if (count > 0 && GetParent())
+ {
+ wxRichTextCompositeObject* parent = wxDynamicCast(GetParent(), wxRichTextCompositeObject);
+ wxRichTextObjectList::compatibility_iterator node = parent->GetChildren().Find(this);
+ if (node)
+ {
+ const wxRichTextAttr emptyAttr;
+ wxRichTextObjectList::compatibility_iterator next = node->GetNext();
+
+ wxArrayInt positions;
+ wxRichTextAttrArray attributes;
+ if (context.GetVirtualSubobjectAttributes(this, positions, attributes) && positions.GetCount() > 0)
+ {
+ wxASSERT(positions.GetCount() == attributes.GetCount());
+
+ // We will gather up runs of text with the same virtual attributes
+
+ int len = m_text.Length();
+ int i = 0;
+
+ // runStart and runEnd represent the accumulated run with a consistent attribute
+ // that hasn't yet been appended
+ int runStart = -1;
+ int runEnd = -1;
+ wxRichTextAttr currentAttr;
+ wxString text = m_text;
+ wxRichTextPlainText* lastPlainText = this;
+
+ for (i = 0; i < (int) positions.GetCount(); i++)
+ {
+ int pos = positions[i];
+ wxASSERT(pos >= 0 && pos < len);
+ if (pos >= 0 && pos < len)
+ {
+ const wxRichTextAttr& attr = attributes[i];
+
+ if (pos == 0)
+ {
+ runStart = 0;
+ currentAttr = attr;
+ }
+ // Check if there was a gap from the last known attribute and this.
+ // In that case, we need to do something with the span of non-attributed text.
+ else if ((pos-1) > runEnd)
+ {
+ if (runEnd == -1)
+ {
+ // We hadn't processed anything previously, so the previous run is from the text start
+ // to just before this position. The current attribute remains empty.
+ runStart = 0;
+ runEnd = pos-1;
+ }
+ else
+ {
+ // If the previous attribute matches the gap's attribute (i.e., no attributes)
+ // then just extend the run.
+ if (currentAttr.IsDefault())
+ {
+ runEnd = pos-1;
+ }
+ else
+ {
+ // We need to add an object, or reuse the existing one.
+ if (runStart == 0)
+ {
+ lastPlainText = this;
+ SetText(text.Mid(runStart, runEnd - runStart + 1));
+ }
+ else
+ {
+ wxRichTextPlainText* obj = new wxRichTextPlainText;
+ lastPlainText = obj;
+ obj->SetAttributes(GetAttributes());
+ obj->SetProperties(GetProperties());
+ obj->SetParent(parent);
+
+ obj->SetText(text.Mid(runStart, runEnd - runStart + 1));
+ if (next)
+ parent->GetChildren().Insert(next, obj);
+ else
+ parent->GetChildren().Append(obj);
+ }
+
+ runStart = runEnd+1;
+ runEnd = pos-1;
+
+ currentAttr = emptyAttr;
+ }
+ }
+ }
+
+ wxASSERT(runEnd == pos-1);
+
+ // Now we only have to deal with the previous run
+ if (currentAttr == attr)
+ {
+ // If we still have the same attributes, then we
+ // simply increase the run size.
+ runEnd = pos;
+ }
+ else
+ {
+ if (runEnd >= 0)
+ {
+ // We need to add an object, or reuse the existing one.
+ if (runStart == 0)
+ {
+ lastPlainText = this;
+ SetText(text.Mid(runStart, runEnd - runStart + 1));
+ }
+ else
+ {
+ wxRichTextPlainText* obj = new wxRichTextPlainText;
+ lastPlainText = obj;
+ obj->SetAttributes(GetAttributes());
+ obj->SetProperties(GetProperties());
+ obj->SetParent(parent);
+
+ obj->SetText(text.Mid(runStart, runEnd - runStart + 1));
+ if (next)
+ parent->GetChildren().Insert(next, obj);
+ else
+ parent->GetChildren().Append(obj);
+ }
+ }
+
+ runStart = pos;
+ runEnd = pos;
+
+ currentAttr = attr;
+ }
+ }
+ }
+
+ // We may still have a run to add, and possibly a no-attribute text fragment after that.
+ // If the whole string was already a single attribute (the run covers the whole string), don't split.
+ if ((runStart != -1) && !(runStart == 0 && runEnd == (len-1)))
+ {
+ // If the current attribute is empty, merge the run with the next fragment
+ // which by definition (because it's not specified) has empty attributes.
+ if (currentAttr.IsDefault())
+ runEnd = (len-1);
+
+ if (runEnd < (len-1))
+ {
+ // We need to add an object, or reuse the existing one.
+ if (runStart == 0)
+ {
+ lastPlainText = this;
+ SetText(text.Mid(runStart, runEnd - runStart + 1));
+ }
+ else
+ {
+ wxRichTextPlainText* obj = new wxRichTextPlainText;
+ lastPlainText = obj;
+ obj->SetAttributes(GetAttributes());
+ obj->SetProperties(GetProperties());
+ obj->SetParent(parent);
+
+ obj->SetText(text.Mid(runStart, runEnd - runStart + 1));
+ if (next)
+ parent->GetChildren().Insert(next, obj);
+ else
+ parent->GetChildren().Append(obj);
+ }
+
+ runStart = runEnd+1;
+ runEnd = (len-1);
+ }
+
+ // Now the last, non-attributed fragment at the end, if any
+ if ((runStart < len) && !(runStart == 0 && runEnd == (len-1)))
+ {
+ wxASSERT(runStart != 0);
+
+ wxRichTextPlainText* obj = new wxRichTextPlainText;
+ obj->SetAttributes(GetAttributes());
+ obj->SetProperties(GetProperties());
+ obj->SetParent(parent);
+
+ obj->SetText(text.Mid(runStart, runEnd - runStart + 1));
+ if (next)
+ parent->GetChildren().Insert(next, obj);
+ else
+ parent->GetChildren().Append(obj);
+
+ lastPlainText = obj;
+ }
+ }
+
+ return lastPlainText;
+ }
+ }
+ }
+ return this;
+}
+
+/// Dump to output stream for debugging
+void wxRichTextPlainText::Dump(wxTextOutputStream& stream)
+{
+ wxRichTextObject::Dump(stream);
+ stream << m_text << wxT("\n");
+}
+
+/// Get the first position from pos that has a line break character.
+long wxRichTextPlainText::GetFirstLineBreakPosition(long pos)
+{
+ int i;
+ int len = m_text.length();
+ int startPos = pos - m_range.GetStart();
+ for (i = startPos; i < len; i++)
+ {
+ wxChar ch = m_text[i];
+ if (ch == wxRichTextLineBreakChar)
+ {
+ return i + m_range.GetStart();
+ }
+ }
+ return -1;
+}
+
+/*!
+ * wxRichTextBuffer
+ * This is a kind of box, used to represent the whole buffer
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxRichTextBuffer, wxRichTextParagraphLayoutBox)
+
+wxList wxRichTextBuffer::sm_handlers;
+wxList wxRichTextBuffer::sm_drawingHandlers;
+wxRichTextFieldTypeHashMap wxRichTextBuffer::sm_fieldTypes;
+wxRichTextRenderer* wxRichTextBuffer::sm_renderer = NULL;
+int wxRichTextBuffer::sm_bulletRightMargin = 20;
+float wxRichTextBuffer::sm_bulletProportion = (float) 0.3;
+bool wxRichTextBuffer::sm_floatingLayoutMode = true;
+
+/// Initialisation
+void wxRichTextBuffer::Init()
+{
+ m_commandProcessor = new wxCommandProcessor;
+ m_styleSheet = NULL;
+ m_modified = false;
+ m_batchedCommandDepth = 0;
+ m_batchedCommand = NULL;
+ m_suppressUndo = 0;
+ m_handlerFlags = 0;
+ m_scale = 1.0;
+ m_dimensionScale = 1.0;
+ m_fontScale = 1.0;
+ SetMargins(4);
+}
+
+/// Initialisation
+wxRichTextBuffer::~wxRichTextBuffer()
+{
+ delete m_commandProcessor;
+ delete m_batchedCommand;
+
+ ClearStyleStack();
+ ClearEventHandlers();
+}
+
+void wxRichTextBuffer::ResetAndClearCommands()
+{
+ Reset();
+
+ GetCommandProcessor()->ClearCommands();
+
+ Modify(false);
+ Invalidate(wxRICHTEXT_ALL);
+}
+
+void wxRichTextBuffer::Copy(const wxRichTextBuffer& obj)
+{
+ wxRichTextParagraphLayoutBox::Copy(obj);
+
+ m_styleSheet = obj.m_styleSheet;
+ m_modified = obj.m_modified;
+ m_batchedCommandDepth = 0;
+ if (m_batchedCommand)
+ delete m_batchedCommand;
+ m_batchedCommand = NULL;
+ m_suppressUndo = obj.m_suppressUndo;
+ m_invalidRange = obj.m_invalidRange;
+ m_dimensionScale = obj.m_dimensionScale;
+ m_fontScale = obj.m_fontScale;
+}
+
+/// Push style sheet to top of stack
+bool wxRichTextBuffer::PushStyleSheet(wxRichTextStyleSheet* styleSheet)
+{
+ if (m_styleSheet)
+ styleSheet->InsertSheet(m_styleSheet);
+
+ SetStyleSheet(styleSheet);
+
+ return true;
+}
+
+/// Pop style sheet from top of stack
+wxRichTextStyleSheet* wxRichTextBuffer::PopStyleSheet()
+{
+ if (m_styleSheet)
+ {
+ wxRichTextStyleSheet* oldSheet = m_styleSheet;
+ m_styleSheet = oldSheet->GetNextSheet();
+ oldSheet->Unlink();
+
+ return oldSheet;
+ }
+ else
+ return NULL;
+}
+
+/// Submit command to insert paragraphs
+bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int flags)
+{
+ return ctrl->GetFocusObject()->InsertParagraphsWithUndo(this, pos, paragraphs, ctrl, flags);
+}
+
+/// Submit command to insert paragraphs
+bool wxRichTextParagraphLayoutBox::InsertParagraphsWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, int WXUNUSED(flags))
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
+
+ action->GetNewParagraphs() = paragraphs;
+
+ action->SetPosition(pos);
+
+ wxRichTextRange range = wxRichTextRange(pos, pos + paragraphs.GetOwnRange().GetEnd() - 1);
+ if (!paragraphs.GetPartialParagraph())
+ range.SetEnd(range.GetEnd()+1);
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(range);
+
+ buffer->SubmitAction(action);
+
+ return true;
+}
+
+/// Submit command to insert the given text
+bool wxRichTextBuffer::InsertTextWithUndo(long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags)
+{
+ if (ctrl)
+ return ctrl->GetFocusObject()->InsertTextWithUndo(this, pos, text, ctrl, flags);
+ else
+ return wxRichTextParagraphLayoutBox::InsertTextWithUndo(this, pos, text, ctrl, flags);
+}
+
+/// Submit command to insert the given text
+bool wxRichTextParagraphLayoutBox::InsertTextWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& text, wxRichTextCtrl* ctrl, int flags)
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
+
+ wxRichTextAttr* p = NULL;
+ wxRichTextAttr paraAttr;
+ if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
+ {
+ // Get appropriate paragraph style
+ paraAttr = GetStyleForNewParagraph(buffer, pos, false, false);
+ if (!paraAttr.IsDefault())
+ p = & paraAttr;
+ }
+
+ action->GetNewParagraphs().AddParagraphs(text, p);
+
+ int length = action->GetNewParagraphs().GetOwnRange().GetLength();
+
+ if (!text.empty() && text.Last() != wxT('\n'))
+ {
+ // Don't count the newline when undoing
+ length --;
+ action->GetNewParagraphs().SetPartialParagraph(true);
+ }
+ else if (!text.empty() && text.Last() == wxT('\n'))
+ length --;
+
+ action->SetPosition(pos);
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(wxRichTextRange(pos, pos + length - 1));
+
+ buffer->SubmitAction(action);
+
+ return true;
+}
+
+/// Submit command to insert the given text
+bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int flags)
+{
+ return ctrl->GetFocusObject()->InsertNewlineWithUndo(this, pos, ctrl, flags);
+}
+
+/// Submit command to insert the given text
+bool wxRichTextParagraphLayoutBox::InsertNewlineWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextCtrl* ctrl, int flags)
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
+
+ wxRichTextAttr* p = NULL;
+ wxRichTextAttr paraAttr;
+ if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
+ {
+ paraAttr = GetStyleForNewParagraph(buffer, pos, false, true /* look for next paragraph style */);
+ if (!paraAttr.IsDefault())
+ p = & paraAttr;
+ }
+
+ wxRichTextAttr attr(buffer->GetDefaultStyle());
+ // Don't include box attributes such as margins
+ attr.GetTextBoxAttr().Reset();
+
+ wxRichTextParagraph* newPara = new wxRichTextParagraph(wxEmptyString, this, & attr);
+ action->GetNewParagraphs().AppendChild(newPara);
+ action->GetNewParagraphs().UpdateRanges();
+ action->GetNewParagraphs().SetPartialParagraph(false);
+ wxRichTextParagraph* para = GetParagraphAtPosition(pos, false);
+ long pos1 = pos;
+
+ if (p)
+ newPara->SetAttributes(*p);
+
+ if (flags & wxRICHTEXT_INSERT_INTERACTIVE)
+ {
+ if (para && para->GetRange().GetEnd() == pos)
+ pos1 ++;
+
+ // Now see if we need to number the paragraph.
+ if (newPara->GetAttributes().HasBulletNumber())
+ {
+ wxRichTextAttr numberingAttr;
+ if (FindNextParagraphNumber(para, numberingAttr))
+ wxRichTextApplyStyle(newPara->GetAttributes(), (const wxRichTextAttr&) numberingAttr);
+ }
+ }
+
+ action->SetPosition(pos);
+
+ // Use the default character style
+ if (!buffer->GetDefaultStyle().IsDefault() && newPara->GetChildren().GetFirst())
+ {
+ // Check whether the default style merely reflects the paragraph/basic style,
+ // in which case don't apply it.
+ wxRichTextAttr defaultStyle(buffer->GetDefaultStyle());
+ defaultStyle.GetTextBoxAttr().Reset();
+ wxRichTextAttr toApply;
+ if (para)
+ {
+ wxRichTextAttr combinedAttr = para->GetCombinedAttributes(true /* include box attributes */);
+ wxRichTextAttr newAttr;
+ // This filters out attributes that are accounted for by the current
+ // paragraph/basic style
+ wxRichTextApplyStyle(toApply, defaultStyle, & combinedAttr);
+ }
+ else
+ toApply = defaultStyle;
+
+ if (!toApply.IsDefault())
+ newPara->GetChildren().GetFirst()->GetData()->SetAttributes(toApply);
+ }
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(wxRichTextRange(pos1, pos1));
+
+ buffer->SubmitAction(action);
+
+ return true;
+}
+
+/// Submit command to insert the given image
+bool wxRichTextBuffer::InsertImageWithUndo(long pos, const wxRichTextImageBlock& imageBlock, wxRichTextCtrl* ctrl, int flags,
+ const wxRichTextAttr& textAttr)
+{
+ return ctrl->GetFocusObject()->InsertImageWithUndo(this, pos, imageBlock, ctrl, flags, textAttr);
+}
+
+/// Submit command to insert the given image
+bool wxRichTextParagraphLayoutBox::InsertImageWithUndo(wxRichTextBuffer* buffer, long pos, const wxRichTextImageBlock& imageBlock,
+ wxRichTextCtrl* ctrl, int flags,
+ const wxRichTextAttr& textAttr)
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Image"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
+
+ wxRichTextAttr* p = NULL;
+ wxRichTextAttr paraAttr;
+ if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
+ {
+ paraAttr = GetStyleForNewParagraph(buffer, pos);
+ if (!paraAttr.IsDefault())
+ p = & paraAttr;
+ }
+
+ wxRichTextAttr attr(buffer->GetDefaultStyle());
+
+ // Don't include box attributes such as margins
+ attr.GetTextBoxAttr().Reset();
+
+ wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr);
+ if (p)
+ newPara->SetAttributes(*p);
+
+ wxRichTextImage* imageObject = new wxRichTextImage(imageBlock, newPara);
+ newPara->AppendChild(imageObject);
+ imageObject->SetAttributes(textAttr);
+ action->GetNewParagraphs().AppendChild(newPara);
+ action->GetNewParagraphs().UpdateRanges();
+
+ action->GetNewParagraphs().SetPartialParagraph(true);
+
+ action->SetPosition(pos);
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(wxRichTextRange(pos, pos));
+
+ buffer->SubmitAction(action);
+
+ return true;
+}
+
+// Insert an object with no change of it
+wxRichTextObject* wxRichTextBuffer::InsertObjectWithUndo(long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags)
+{
+ return ctrl->GetFocusObject()->InsertObjectWithUndo(this, pos, object, ctrl, flags);
+}
+
+// Insert an object with no change of it
+wxRichTextObject* wxRichTextParagraphLayoutBox::InsertObjectWithUndo(wxRichTextBuffer* buffer, long pos, wxRichTextObject *object, wxRichTextCtrl* ctrl, int flags)
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Object"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
+
+ wxRichTextAttr* p = NULL;
+ wxRichTextAttr paraAttr;
+ if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
+ {
+ paraAttr = GetStyleForNewParagraph(buffer, pos);
+ if (!paraAttr.IsDefault())
+ p = & paraAttr;
+ }
+
+ wxRichTextAttr attr(buffer->GetDefaultStyle());
+
+ // Don't include box attributes such as margins
+ attr.GetTextBoxAttr().Reset();
+
+ wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr);
+ if (p)
+ newPara->SetAttributes(*p);
+
+ newPara->AppendChild(object);
+ action->GetNewParagraphs().AppendChild(newPara);
+ action->GetNewParagraphs().UpdateRanges();
+
+ action->GetNewParagraphs().SetPartialParagraph(true);
+
+ action->SetPosition(pos);
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(wxRichTextRange(pos, pos));
+
+ buffer->SubmitAction(action);
+
+ wxRichTextObject* obj = GetLeafObjectAtPosition(pos);
+ return obj;
+}
+
+wxRichTextField* wxRichTextParagraphLayoutBox::InsertFieldWithUndo(wxRichTextBuffer* buffer, long pos, const wxString& fieldType,
+ const wxRichTextProperties& properties,
+ wxRichTextCtrl* ctrl, int flags,
+ const wxRichTextAttr& textAttr)
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Field"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
+
+ wxRichTextAttr* p = NULL;
+ wxRichTextAttr paraAttr;
+ if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
+ {
+ paraAttr = GetStyleForNewParagraph(buffer, pos);
+ if (!paraAttr.IsDefault())
+ p = & paraAttr;
+ }
+
+ wxRichTextAttr attr(buffer->GetDefaultStyle());
+
+ // Don't include box attributes such as margins
+ attr.GetTextBoxAttr().Reset();
+
+ wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr);
+ if (p)
+ newPara->SetAttributes(*p);
+
+ wxRichTextField* fieldObject = new wxRichTextField();
+ fieldObject->wxRichTextObject::SetProperties(properties);
+ fieldObject->SetFieldType(fieldType);
+ fieldObject->SetAttributes(textAttr);
+ newPara->AppendChild(fieldObject);
+ action->GetNewParagraphs().AppendChild(newPara);
+ action->GetNewParagraphs().UpdateRanges();
+ action->GetNewParagraphs().SetPartialParagraph(true);
+ action->SetPosition(pos);
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(wxRichTextRange(pos, pos));
+
+ buffer->SubmitAction(action);
+
+ wxRichTextField* obj = wxDynamicCast(GetLeafObjectAtPosition(pos), wxRichTextField);
+ return obj;
+}
+
+bool wxRichTextParagraphLayoutBox::SetObjectPropertiesWithUndo(wxRichTextObject& obj, const wxRichTextProperties& properties, wxRichTextObject* objToSet)
+{
+ wxRichTextBuffer* buffer = GetBuffer();
+ wxCHECK_MSG(buffer, false, wxT("Invalid buffer"));
+ wxRichTextCtrl* rtc = buffer->GetRichTextCtrl();
+ wxCHECK_MSG(rtc, false, wxT("Invalid rtc"));
+
+ wxRichTextAction* action = NULL;
+ wxRichTextObject* clone = NULL;
+
+ // The object on which to set properties will usually be 'obj', but use objToSet if it's valid.
+ // This is necessary e.g. on setting a wxRichTextCell's properties, when obj will be the parent table
+ if (objToSet == NULL)
+ objToSet = &obj;
+
+ if (rtc->SuppressingUndo())
+ objToSet->SetProperties(properties);
+ else
+ {
+ clone = obj.Clone();
+ objToSet->SetProperties(properties);
+
+ // The 'true' parameter in the next line says "Ignore first time"; otherwise the objects are prematurely switched
+ action = new wxRichTextAction(NULL, _("Change Properties"), wxRICHTEXT_CHANGE_OBJECT, buffer, obj.GetParentContainer(), rtc, true);
+ action->SetOldAndNewObjects(& obj, clone);
+ action->SetPosition(obj.GetRange().GetStart());
+ action->SetRange(obj.GetRange());
+ buffer->SubmitAction(action);
+ }
+
+ return true;
+}
+
+/// Get the style that is appropriate for a new paragraph at this position.
+/// If the previous paragraph has a paragraph style name, look up the next-paragraph
+/// style.
+wxRichTextAttr wxRichTextParagraphLayoutBox::GetStyleForNewParagraph(wxRichTextBuffer* buffer, long pos, bool caretPosition, bool lookUpNewParaStyle) const
+{
+ wxRichTextParagraph* para = GetParagraphAtPosition(pos, caretPosition);
+ if (para)
+ {
+ wxRichTextAttr attr;
+ bool foundAttributes = false;
+
+ // Look for a matching paragraph style
+ if (lookUpNewParaStyle && !para->GetAttributes().GetParagraphStyleName().IsEmpty() && buffer->GetStyleSheet())
+ {
+ wxRichTextParagraphStyleDefinition* paraDef = buffer->GetStyleSheet()->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName());
+ if (paraDef)
+ {
+ // If we're not at the end of the paragraph, then we apply THIS style, and not the designated next style.
+ if (para->GetRange().GetEnd() == pos && !paraDef->GetNextStyle().IsEmpty())
+ {
+ wxRichTextParagraphStyleDefinition* nextParaDef = buffer->GetStyleSheet()->FindParagraphStyle(paraDef->GetNextStyle());
+ if (nextParaDef)
+ {
+ foundAttributes = true;
+ attr = nextParaDef->GetStyleMergedWithBase(buffer->GetStyleSheet());
+ }
+ }
+
+ // If we didn't find the 'next style', use this style instead.
+ if (!foundAttributes)
+ {
+ foundAttributes = true;
+ attr = paraDef->GetStyleMergedWithBase(buffer->GetStyleSheet());
+ }
+ }
+ }
+
+ // Also apply list style if present
+ if (lookUpNewParaStyle && !para->GetAttributes().GetListStyleName().IsEmpty() && buffer->GetStyleSheet())
+ {
+ wxRichTextListStyleDefinition* listDef = buffer->GetStyleSheet()->FindListStyle(para->GetAttributes().GetListStyleName());
+ if (listDef)
+ {
+ int thisIndent = para->GetAttributes().GetLeftIndent();
+ int thisLevel = para->GetAttributes().HasOutlineLevel() ? para->GetAttributes().GetOutlineLevel() : listDef->FindLevelForIndent(thisIndent);
+
+ // Apply the overall list style, and item style for this level
+ wxRichTextAttr listStyle(listDef->GetCombinedStyleForLevel(thisLevel, buffer->GetStyleSheet()));
+ wxRichTextApplyStyle(attr, listStyle);
+ attr.SetOutlineLevel(thisLevel);
+ if (para->GetAttributes().HasBulletNumber())
+ attr.SetBulletNumber(para->GetAttributes().GetBulletNumber());
+ }
+ }
+
+ if (!foundAttributes)
+ {
+ attr = para->GetAttributes();
+ int flags = attr.GetFlags();
+
+ // Eliminate character styles
+ flags &= ( (~ wxTEXT_ATTR_FONT) |
+ (~ wxTEXT_ATTR_TEXT_COLOUR) |
+ (~ wxTEXT_ATTR_BACKGROUND_COLOUR) );
+ attr.SetFlags(flags);
+ }
+
+ return attr;
+ }
+ else
+ return wxRichTextAttr();
+}
+
+/// Submit command to delete this range
+bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl)
+{
+ return ctrl->GetFocusObject()->DeleteRangeWithUndo(range, ctrl, this);
+}
+
+/// Submit command to delete this range
+bool wxRichTextParagraphLayoutBox::DeleteRangeWithUndo(const wxRichTextRange& range, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer)
+{
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Delete"), wxRICHTEXT_DELETE, buffer, this, ctrl);
+
+ action->SetPosition(ctrl->GetCaretPosition());
+
+ // Set the range to delete
+ action->SetRange(range);
+
+ // Copy the fragment that we'll need to restore in Undo
+ CopyFragment(range, action->GetOldParagraphs());
+
+ // See if we're deleting a paragraph marker, in which case we need to
+ // make a note not to copy the attributes from the 2nd paragraph to the 1st.
+ if (range.GetStart() == range.GetEnd())
+ {
+ wxRichTextParagraph* para = GetParagraphAtPosition(range.GetStart());
+ if (para && para->GetRange().GetEnd() == range.GetEnd())
+ {
+ wxRichTextParagraph* nextPara = GetParagraphAtPosition(range.GetStart()+1);
+ if (nextPara && nextPara != para)
+ {
+ action->GetOldParagraphs().GetChildren().GetFirst()->GetData()->SetAttributes(nextPara->GetAttributes());
+ action->GetOldParagraphs().GetAttributes().SetFlags(action->GetOldParagraphs().GetAttributes().GetFlags() | wxTEXT_ATTR_KEEP_FIRST_PARA_STYLE);
+ }
+ }
+ }
+
+ buffer->SubmitAction(action);
+
+ return true;
+}
+
+/// Collapse undo/redo commands
+bool wxRichTextBuffer::BeginBatchUndo(const wxString& cmdName)
+{
+ if (m_batchedCommandDepth == 0)
+ {
+ wxASSERT(m_batchedCommand == NULL);
+ if (m_batchedCommand)
+ {
+ GetCommandProcessor()->Store(m_batchedCommand);
+ }
+ m_batchedCommand = new wxRichTextCommand(cmdName);
+ }
+
+ m_batchedCommandDepth ++;
+
+ return true;
+}
+
+/// Collapse undo/redo commands
+bool wxRichTextBuffer::EndBatchUndo()
+{
+ m_batchedCommandDepth --;
+
+ wxASSERT(m_batchedCommandDepth >= 0);
+ wxASSERT(m_batchedCommand != NULL);
+
+ if (m_batchedCommandDepth == 0)
+ {
+ GetCommandProcessor()->Store(m_batchedCommand);
+ m_batchedCommand = NULL;
+ }
+
+ return true;
+}
+
+/// Submit immediately, or delay according to whether collapsing is on
+bool wxRichTextBuffer::SubmitAction(wxRichTextAction* action)
+{
+ if (action && !action->GetNewParagraphs().IsEmpty())
+ PrepareContent(action->GetNewParagraphs());
+
+ if (BatchingUndo() && m_batchedCommand && !SuppressingUndo())
+ {
+ if (!action->GetIgnoreFirstTime())
+ {
+ wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName());
+ cmd->AddAction(action);
+ cmd->Do();
+ cmd->GetActions().Clear();
+ delete cmd;
+ }
+
+ m_batchedCommand->AddAction(action);
+ }
+ else
+ {
+ wxRichTextCommand* cmd = new wxRichTextCommand(action->GetName());
+ cmd->AddAction(action);
+
+ // Only store it if we're not suppressing undo.
+ if (!action->GetIgnoreFirstTime())
+ {
+ return GetCommandProcessor()->Submit(cmd, !SuppressingUndo());
+ }
+ else if (!SuppressingUndo())
+ {
+ GetCommandProcessor()->Store(cmd); // Just store it, without Do()ing anything
+ }
+ }
+
+ return true;
+}
+
+/// Begin suppressing undo/redo commands.
+bool wxRichTextBuffer::BeginSuppressUndo()
+{
+ m_suppressUndo ++;
+
+ return true;
+}
+
+/// End suppressing undo/redo commands.
+bool wxRichTextBuffer::EndSuppressUndo()
+{
+ m_suppressUndo --;
+
+ return true;
+}
+
+/// Begin using a style
+bool wxRichTextBuffer::BeginStyle(const wxRichTextAttr& style)
+{
+ wxRichTextAttr newStyle(GetDefaultStyle());
+ newStyle.GetTextBoxAttr().Reset();
+
+ // Save the old default style
+ m_attributeStack.Append((wxObject*) new wxRichTextAttr(newStyle));
+
+ wxRichTextApplyStyle(newStyle, style);
+ newStyle.SetFlags(style.GetFlags()|newStyle.GetFlags());
+
+ SetDefaultStyle(newStyle);
+
+ return true;
+}
+
+/// End the style
+bool wxRichTextBuffer::EndStyle()
+{
+ if (!m_attributeStack.GetFirst())
+ {
+ wxLogDebug(_("Too many EndStyle calls!"));
+ return false;
+ }
+
+ wxList::compatibility_iterator node = m_attributeStack.GetLast();
+ wxRichTextAttr* attr = (wxRichTextAttr*)node->GetData();
+ m_attributeStack.Erase(node);
+
+ SetDefaultStyle(*attr);
+
+ delete attr;
+ return true;
+}
+
+/// End all styles
+bool wxRichTextBuffer::EndAllStyles()
+{
+ while (m_attributeStack.GetCount() != 0)
+ EndStyle();
+ return true;
+}
+
+/// Clear the style stack
+void wxRichTextBuffer::ClearStyleStack()
+{
+ for (wxList::compatibility_iterator node = m_attributeStack.GetFirst(); node; node = node->GetNext())
+ delete (wxRichTextAttr*) node->GetData();
+ m_attributeStack.Clear();
+}
+
+/// Begin using bold
+bool wxRichTextBuffer::BeginBold()
+{
+ wxRichTextAttr attr;
+ attr.SetFontWeight(wxFONTWEIGHT_BOLD);
+
+ return BeginStyle(attr);
+}
+
+/// Begin using italic
+bool wxRichTextBuffer::BeginItalic()
+{
+ wxRichTextAttr attr;
+ attr.SetFontStyle(wxFONTSTYLE_ITALIC);
+
+ return BeginStyle(attr);
+}
+
+/// Begin using underline
+bool wxRichTextBuffer::BeginUnderline()
+{
+ wxRichTextAttr attr;
+ attr.SetFontUnderlined(true);
+
+ return BeginStyle(attr);
+}
+
+/// Begin using point size
+bool wxRichTextBuffer::BeginFontSize(int pointSize)
+{
+ wxRichTextAttr attr;
+ attr.SetFontSize(pointSize);
+
+ return BeginStyle(attr);
+}
+
+/// Begin using this font
+bool wxRichTextBuffer::BeginFont(const wxFont& font)
+{
+ wxRichTextAttr attr;
+ attr.SetFont(font);
+
+ return BeginStyle(attr);
+}
+
+/// Begin using this colour
+bool wxRichTextBuffer::BeginTextColour(const wxColour& colour)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_TEXT_COLOUR);
+ attr.SetTextColour(colour);
+
+ return BeginStyle(attr);
+}
+
+/// Begin using alignment
+bool wxRichTextBuffer::BeginAlignment(wxTextAttrAlignment alignment)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_ALIGNMENT);
+ attr.SetAlignment(alignment);
+
+ return BeginStyle(attr);
+}
+
+/// Begin left indent
+bool wxRichTextBuffer::BeginLeftIndent(int leftIndent, int leftSubIndent)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetLeftIndent(leftIndent, leftSubIndent);
+
+ return BeginStyle(attr);
+}
+
+/// Begin right indent
+bool wxRichTextBuffer::BeginRightIndent(int rightIndent)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_RIGHT_INDENT);
+ attr.SetRightIndent(rightIndent);
+
+ return BeginStyle(attr);
+}
+
+/// Begin paragraph spacing
+bool wxRichTextBuffer::BeginParagraphSpacing(int before, int after)
+{
+ long flags = 0;
+ if (before != 0)
+ flags |= wxTEXT_ATTR_PARA_SPACING_BEFORE;
+ if (after != 0)
+ flags |= wxTEXT_ATTR_PARA_SPACING_AFTER;
+
+ wxRichTextAttr attr;
+ attr.SetFlags(flags);
+ attr.SetParagraphSpacingBefore(before);
+ attr.SetParagraphSpacingAfter(after);
+
+ return BeginStyle(attr);
+}
+
+/// Begin line spacing
+bool wxRichTextBuffer::BeginLineSpacing(int lineSpacing)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_LINE_SPACING);
+ attr.SetLineSpacing(lineSpacing);
+
+ return BeginStyle(attr);
+}
+
+/// Begin numbered bullet
+bool wxRichTextBuffer::BeginNumberedBullet(int bulletNumber, int leftIndent, int leftSubIndent, int bulletStyle)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetBulletStyle(bulletStyle);
+ attr.SetBulletNumber(bulletNumber);
+ attr.SetLeftIndent(leftIndent, leftSubIndent);
+
+ return BeginStyle(attr);
+}
+
+/// Begin symbol bullet
+bool wxRichTextBuffer::BeginSymbolBullet(const wxString& symbol, int leftIndent, int leftSubIndent, int bulletStyle)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetBulletStyle(bulletStyle);
+ attr.SetLeftIndent(leftIndent, leftSubIndent);
+ attr.SetBulletText(symbol);
+
+ return BeginStyle(attr);
+}
+
+/// Begin standard bullet
+bool wxRichTextBuffer::BeginStandardBullet(const wxString& bulletName, int leftIndent, int leftSubIndent, int bulletStyle)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_BULLET_STYLE|wxTEXT_ATTR_LEFT_INDENT);
+ attr.SetBulletStyle(bulletStyle);
+ attr.SetLeftIndent(leftIndent, leftSubIndent);
+ attr.SetBulletName(bulletName);
+
+ return BeginStyle(attr);
+}
+
+/// Begin named character style
+bool wxRichTextBuffer::BeginCharacterStyle(const wxString& characterStyle)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterStyle);
+ if (def)
+ {
+ wxRichTextAttr attr = def->GetStyleMergedWithBase(GetStyleSheet());
+ return BeginStyle(attr);
+ }
+ }
+ return false;
+}
+
+/// Begin named paragraph style
+bool wxRichTextBuffer::BeginParagraphStyle(const wxString& paragraphStyle)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(paragraphStyle);
+ if (def)
+ {
+ wxRichTextAttr attr = def->GetStyleMergedWithBase(GetStyleSheet());
+ return BeginStyle(attr);
+ }
+ }
+ return false;
+}
+
+/// Begin named list style
+bool wxRichTextBuffer::BeginListStyle(const wxString& listStyle, int level, int number)
+{
+ if (GetStyleSheet())
+ {
+ wxRichTextListStyleDefinition* def = GetStyleSheet()->FindListStyle(listStyle);
+ if (def)
+ {
+ wxRichTextAttr attr(def->GetCombinedStyleForLevel(level));
+
+ attr.SetBulletNumber(number);
+
+ return BeginStyle(attr);
+ }
+ }
+ return false;
+}
+
+/// Begin URL
+bool wxRichTextBuffer::BeginURL(const wxString& url, const wxString& characterStyle)
+{
+ wxRichTextAttr attr;
+
+ if (!characterStyle.IsEmpty() && GetStyleSheet())
+ {
+ wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterStyle);
+ if (def)
+ {
+ attr = def->GetStyleMergedWithBase(GetStyleSheet());
+ }
+ }
+ attr.SetURL(url);
+
+ return BeginStyle(attr);
+}
+
+/// Adds a handler to the end
+void wxRichTextBuffer::AddHandler(wxRichTextFileHandler *handler)
+{
+ sm_handlers.Append(handler);
+}
+
+/// Inserts a handler at the front
+void wxRichTextBuffer::InsertHandler(wxRichTextFileHandler *handler)
+{
+ sm_handlers.Insert( handler );
+}
+
+/// Removes a handler
+bool wxRichTextBuffer::RemoveHandler(const wxString& name)
+{
+ wxRichTextFileHandler *handler = FindHandler(name);
+ if (handler)
+ {
+ sm_handlers.DeleteObject(handler);
+ delete handler;
+ return true;
+ }
+ else
+ return false;
+}
+
+/// Finds a handler by filename or, if supplied, type
+wxRichTextFileHandler *wxRichTextBuffer::FindHandlerFilenameOrType(const wxString& filename,
+ wxRichTextFileType imageType)
+{
+ if (imageType != wxRICHTEXT_TYPE_ANY)
+ return FindHandler(imageType);
+ else if (!filename.IsEmpty())
+ {
+ wxString path, file, ext;
+ wxFileName::SplitPath(filename, & path, & file, & ext);
+ return FindHandler(ext, imageType);
+ }
+ else
+ return NULL;
+}
+
+
+/// Finds a handler by name
+wxRichTextFileHandler* wxRichTextBuffer::FindHandler(const wxString& name)
+{
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
+ while (node)
+ {
+ wxRichTextFileHandler *handler = (wxRichTextFileHandler*)node->GetData();
+ if (handler->GetName().Lower() == name.Lower()) return handler;
+
+ node = node->GetNext();
+ }
+ return NULL;
+}
+
+/// Finds a handler by extension and type
+wxRichTextFileHandler* wxRichTextBuffer::FindHandler(const wxString& extension, wxRichTextFileType type)
+{
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
+ while (node)
+ {
+ wxRichTextFileHandler *handler = (wxRichTextFileHandler*)node->GetData();
+ if ( handler->GetExtension().Lower() == extension.Lower() &&
+ (type == wxRICHTEXT_TYPE_ANY || handler->GetType() == type) )
+ return handler;
+ node = node->GetNext();
+ }
+ return 0;
+}
+
+/// Finds a handler by type
+wxRichTextFileHandler* wxRichTextBuffer::FindHandler(wxRichTextFileType type)
+{
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
+ while (node)
+ {
+ wxRichTextFileHandler *handler = (wxRichTextFileHandler *)node->GetData();
+ if (handler->GetType() == type) return handler;
+ node = node->GetNext();
+ }
+ return NULL;
+}
+
+void wxRichTextBuffer::InitStandardHandlers()
+{
+ if (!FindHandler(wxRICHTEXT_TYPE_TEXT))
+ AddHandler(new wxRichTextPlainTextHandler);
+}
+
+void wxRichTextBuffer::CleanUpHandlers()
+{
+ wxList::compatibility_iterator node = sm_handlers.GetFirst();
+ while (node)
+ {
+ wxRichTextFileHandler* handler = (wxRichTextFileHandler*)node->GetData();
+ wxList::compatibility_iterator next = node->GetNext();
+ delete handler;
+ node = next;
+ }
+
+ sm_handlers.Clear();
+}
+
+wxString wxRichTextBuffer::GetExtWildcard(bool combine, bool save, wxArrayInt* types)
+{
+ if (types)
+ types->Clear();
+
+ wxString wildcard;
+
+ wxList::compatibility_iterator node = GetHandlers().GetFirst();
+ int count = 0;
+ while (node)
+ {
+ wxRichTextFileHandler* handler = (wxRichTextFileHandler*) node->GetData();
+ if (handler->IsVisible() && ((save && handler->CanSave()) || (!save && handler->CanLoad())))
+ {
+ if (combine)
+ {
+ if (count > 0)
+ wildcard += wxT(";");
+ wildcard += wxT("*.") + handler->GetExtension();
+ }
+ else
+ {
+ if (count > 0)
+ wildcard += wxT("|");
+ wildcard += handler->GetName();
+ wildcard += wxT(" ");
+ wildcard += _("files");
+ wildcard += wxT(" (*.");
+ wildcard += handler->GetExtension();
+ wildcard += wxT(")|*.");
+ wildcard += handler->GetExtension();
+ if (types)
+ types->Add(handler->GetType());
+ }
+ count ++;
+ }
+
+ node = node->GetNext();
+ }
+
+ if (combine)
+ wildcard = wxT("(") + wildcard + wxT(")|") + wildcard;
+ return wildcard;
+}
+
+#if wxUSE_FFILE && wxUSE_STREAMS
+/// Load a file
+bool wxRichTextBuffer::LoadFile(const wxString& filename, wxRichTextFileType type)
+{
+ wxRichTextFileHandler* handler = FindHandlerFilenameOrType(filename, type);
+ if (handler)
+ {
+ SetDefaultStyle(wxRichTextAttr());
+ handler->SetFlags(GetHandlerFlags());
+ bool success = handler->LoadFile(this, filename);
+ Invalidate(wxRICHTEXT_ALL);
+ return success;
+ }
+ else
+ return false;
+}
+
+/// Save a file
+bool wxRichTextBuffer::SaveFile(const wxString& filename, wxRichTextFileType type)
+{
+ wxRichTextFileHandler* handler = FindHandlerFilenameOrType(filename, type);
+ if (handler)
+ {
+ handler->SetFlags(GetHandlerFlags());
+ return handler->SaveFile(this, filename);
+ }
+ else
+ return false;
+}
+#endif // wxUSE_FFILE && wxUSE_STREAMS
+
+#if wxUSE_STREAMS
+/// Load from a stream
+bool wxRichTextBuffer::LoadFile(wxInputStream& stream, wxRichTextFileType type)
+{
+ wxRichTextFileHandler* handler = FindHandler(type);
+ if (handler)
+ {
+ SetDefaultStyle(wxRichTextAttr());
+ handler->SetFlags(GetHandlerFlags());
+ bool success = handler->LoadFile(this, stream);
+ Invalidate(wxRICHTEXT_ALL);
+ return success;
+ }
+ else
+ return false;
+}
+
+/// Save to a stream
+bool wxRichTextBuffer::SaveFile(wxOutputStream& stream, wxRichTextFileType type)
+{
+ wxRichTextFileHandler* handler = FindHandler(type);
+ if (handler)
+ {
+ handler->SetFlags(GetHandlerFlags());
+ return handler->SaveFile(this, stream);
+ }
+ else
+ return false;
+}
+#endif // wxUSE_STREAMS
+
+/// Copy the range to the clipboard
+bool wxRichTextBuffer::CopyToClipboard(const wxRichTextRange& range)
+{
+ bool success = false;
+ wxRichTextParagraphLayoutBox* container = this;
+ if (GetRichTextCtrl())
+ container = GetRichTextCtrl()->GetFocusObject();
+
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
+
+ if (!wxTheClipboard->IsOpened() && wxTheClipboard->Open())
+ {
+ wxTheClipboard->Clear();
+
+ // Add composite object
+
+ wxDataObjectComposite* compositeObject = new wxDataObjectComposite();
+
+ {
+ wxString text = container->GetTextForRange(range);
+
+#ifdef __WXMSW__
+ text = wxTextFile::Translate(text, wxTextFileType_Dos);
+#endif
+
+ compositeObject->Add(new wxTextDataObject(text), false /* not preferred */);
+ }
+
+ // Add rich text buffer data object. This needs the XML handler to be present.
+
+ if (FindHandler(wxRICHTEXT_TYPE_XML))
+ {
+ wxRichTextBuffer* richTextBuf = new wxRichTextBuffer;
+ container->CopyFragment(range, *richTextBuf);
+
+ compositeObject->Add(new wxRichTextBufferDataObject(richTextBuf), true /* preferred */);
+ }
+
+ if (wxTheClipboard->SetData(compositeObject))
+ success = true;
+
+ wxTheClipboard->Close();
+ }
+
+#else
+ wxUnusedVar(range);
+#endif
+ return success;
+}
+
+/// Paste the clipboard content to the buffer
+bool wxRichTextBuffer::PasteFromClipboard(long position)
+{
+ bool success = false;
+ wxRichTextParagraphLayoutBox* container = this;
+ if (GetRichTextCtrl())
+ container = GetRichTextCtrl()->GetFocusObject();
+
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
+ if (CanPasteFromClipboard())
+ {
+ if (wxTheClipboard->Open())
+ {
+ if (wxTheClipboard->IsSupported(wxDataFormat(wxRichTextBufferDataObject::GetRichTextBufferFormatId())))
+ {
+ wxRichTextBufferDataObject data;
+ wxTheClipboard->GetData(data);
+ wxRichTextBuffer* richTextBuffer = data.GetRichTextBuffer();
+ if (richTextBuffer)
+ {
+ container->InsertParagraphsWithUndo(this, position+1, *richTextBuffer, GetRichTextCtrl(), 0);
+ if (GetRichTextCtrl())
+ GetRichTextCtrl()->ShowPosition(position + richTextBuffer->GetOwnRange().GetEnd());
+ delete richTextBuffer;
+ }
+ }
+ else if (wxTheClipboard->IsSupported(wxDF_TEXT)
+ #if wxUSE_UNICODE
+ || wxTheClipboard->IsSupported(wxDF_UNICODETEXT)
+ #endif
+ )
+ {
+ wxTextDataObject data;
+ wxTheClipboard->GetData(data);
+ wxString text(data.GetText());
+#ifdef __WXMSW__
+ wxString text2;
+ text2.Alloc(text.Length()+1);
+ size_t i;
+ for (i = 0; i < text.Length(); i++)
+ {
+ wxChar ch = text[i];
+ if (ch != wxT('\r'))
+ text2 += ch;
+ }
+#else
+ wxString text2 = text;
+#endif
+ container->InsertTextWithUndo(this, position+1, text2, GetRichTextCtrl(), wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE);
+
+ if (GetRichTextCtrl())
+ GetRichTextCtrl()->ShowPosition(position + text2.Length());
+
+ success = true;
+ }
+ else if (wxTheClipboard->IsSupported(wxDF_BITMAP))
+ {
+ wxBitmapDataObject data;
+ wxTheClipboard->GetData(data);
+ wxBitmap bitmap(data.GetBitmap());
+ wxImage image(bitmap.ConvertToImage());
+
+ wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Image"), wxRICHTEXT_INSERT, this, container, GetRichTextCtrl(), false);
+
+ action->GetNewParagraphs().AddImage(image);
+
+ if (action->GetNewParagraphs().GetChildCount() == 1)
+ action->GetNewParagraphs().SetPartialParagraph(true);
+
+ action->SetPosition(position+1);
+
+ // Set the range we'll need to delete in Undo
+ action->SetRange(wxRichTextRange(position+1, position+1));
+
+ SubmitAction(action);
+
+ success = true;
+ }
+ wxTheClipboard->Close();
+ }
+ }
+#else
+ wxUnusedVar(position);
+#endif
+ return success;
+}
+
+/// Can we paste from the clipboard?
+bool wxRichTextBuffer::CanPasteFromClipboard() const
+{
+ bool canPaste = false;
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
+ if (!wxTheClipboard->IsOpened() && wxTheClipboard->Open())
+ {
+ if (wxTheClipboard->IsSupported(wxDF_TEXT)
+#if wxUSE_UNICODE
+ || wxTheClipboard->IsSupported(wxDF_UNICODETEXT)
+#endif
+ || wxTheClipboard->IsSupported(wxDataFormat(wxRichTextBufferDataObject::GetRichTextBufferFormatId())) ||
+ wxTheClipboard->IsSupported(wxDF_BITMAP))
+ {
+ canPaste = true;
+ }
+ wxTheClipboard->Close();
+ }
+#endif
+ return canPaste;
+}
+
+/// Dumps contents of buffer for debugging purposes
+void wxRichTextBuffer::Dump()
+{
+ wxString text;
+ {
+ wxStringOutputStream stream(& text);
+ wxTextOutputStream textStream(stream);
+ Dump(textStream);
+ }
+
+ wxLogDebug(text);
+}
+
+/// Add an event handler
+bool wxRichTextBuffer::AddEventHandler(wxEvtHandler* handler)
+{
+ m_eventHandlers.Append(handler);
+ return true;
+}
+
+/// Remove an event handler
+bool wxRichTextBuffer::RemoveEventHandler(wxEvtHandler* handler, bool deleteHandler)
+{
+ wxList::compatibility_iterator node = m_eventHandlers.Find(handler);
+ if (node)
+ {
+ m_eventHandlers.Erase(node);
+ if (deleteHandler)
+ delete handler;
+
+ return true;
+ }
+ else
+ return false;
+}
+
+/// Clear event handlers
+void wxRichTextBuffer::ClearEventHandlers()
+{
+ m_eventHandlers.Clear();
+}
+
+/// Send event to event handlers. If sendToAll is true, will send to all event handlers,
+/// otherwise will stop at the first successful one.
+bool wxRichTextBuffer::SendEvent(wxEvent& event, bool sendToAll)
+{
+ bool success = false;
+ for (wxList::compatibility_iterator node = m_eventHandlers.GetFirst(); node; node = node->GetNext())
+ {
+ wxEvtHandler* handler = (wxEvtHandler*) node->GetData();
+ if (handler->ProcessEvent(event))
+ {
+ success = true;
+ if (!sendToAll)
+ return true;
+ }
+ }
+ return success;
+}
+
+/// Set style sheet and notify of the change
+bool wxRichTextBuffer::SetStyleSheetAndNotify(wxRichTextStyleSheet* sheet)
+{
+ wxRichTextStyleSheet* oldSheet = GetStyleSheet();
+
+ wxWindowID winid = wxID_ANY;
+ if (GetRichTextCtrl())
+ winid = GetRichTextCtrl()->GetId();
+
+ wxRichTextEvent event(wxEVT_RICHTEXT_STYLESHEET_REPLACING, winid);
+ event.SetEventObject(GetRichTextCtrl());
+ event.SetContainer(GetRichTextCtrl()->GetFocusObject());
+ event.SetOldStyleSheet(oldSheet);
+ event.SetNewStyleSheet(sheet);
+ event.Allow();
+
+ if (SendEvent(event) && !event.IsAllowed())
+ {
+ if (sheet != oldSheet)
+ delete sheet;
+
+ return false;
+ }
+
+ if (oldSheet && oldSheet != sheet)
+ delete oldSheet;
+
+ SetStyleSheet(sheet);
+
+ event.SetEventType(wxEVT_RICHTEXT_STYLESHEET_REPLACED);
+ event.SetOldStyleSheet(NULL);
+ event.Allow();
+
+ return SendEvent(event);
+}
+
+/// Set renderer, deleting old one
+void wxRichTextBuffer::SetRenderer(wxRichTextRenderer* renderer)
+{
+ if (sm_renderer)
+ delete sm_renderer;
+ sm_renderer = renderer;
+}
+
+/// Hit-testing: returns a flag indicating hit test details, plus
+/// information about position
+int wxRichTextBuffer::HitTest(wxDC& dc, wxRichTextDrawingContext& context, const wxPoint& pt, long& textPosition, wxRichTextObject** obj, wxRichTextObject** contextObj, int flags)
+{
+ int ret = wxRichTextParagraphLayoutBox::HitTest(dc, context, pt, textPosition, obj, contextObj, flags);
+ if (ret != wxRICHTEXT_HITTEST_NONE)
+ {
+ return ret;
+ }
+ else
+ {
+ textPosition = m_ownRange.GetEnd()-1;
+ *obj = this;
+ *contextObj = this;
+ return wxRICHTEXT_HITTEST_AFTER|wxRICHTEXT_HITTEST_OUTSIDE;
+ }
+}
+
+void wxRichTextBuffer::SetFontScale(double fontScale)
+{
+ m_fontScale = fontScale;
+ m_fontTable.SetFontScale(fontScale);
+}
+
+void wxRichTextBuffer::SetDimensionScale(double dimScale)
+{
+ m_dimensionScale = dimScale;
+}
+
+bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& bulletAttr, const wxRect& rect)
+{
+ if (bulletAttr.GetTextColour().IsOk())
+ {
+ wxCheckSetPen(dc, wxPen(bulletAttr.GetTextColour()));
+ wxCheckSetBrush(dc, wxBrush(bulletAttr.GetTextColour()));
+ }
+ else
+ {
+ wxCheckSetPen(dc, *wxBLACK_PEN);
+ wxCheckSetBrush(dc, *wxBLACK_BRUSH);
+ }
+
+ wxFont font;
+ if (bulletAttr.HasFont())
+ {
+ font = paragraph->GetBuffer()->GetFontTable().FindFont(bulletAttr);
+ }
+ else
+ font = (*wxNORMAL_FONT);
+
+ wxCheckSetFont(dc, font);
+
+ int charHeight = dc.GetCharHeight();
+
+ int bulletWidth = (int) (((float) charHeight) * wxRichTextBuffer::GetBulletProportion());
+ int bulletHeight = bulletWidth;
+
+ int x = rect.x;
+
+ // Calculate the top position of the character (as opposed to the whole line height)
+ int y = rect.y + (rect.height - charHeight);
+
+ // Calculate where the bullet should be positioned
+ y = y + (charHeight+1)/2 - (bulletHeight+1)/2;
+
+ // The margin between a bullet and text.
+ int margin = paragraph->ConvertTenthsMMToPixels(dc, wxRichTextBuffer::GetBulletRightMargin());
+
+ if (bulletAttr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT)
+ x = rect.x + rect.width - bulletWidth - margin;
+ else if (bulletAttr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE)
+ x = x + (rect.width)/2 - bulletWidth/2;
+
+ if (bulletAttr.GetBulletName() == wxT("standard/square"))
+ {
+ dc.DrawRectangle(x, y, bulletWidth, bulletHeight);
+ }
+ else if (bulletAttr.GetBulletName() == wxT("standard/diamond"))
+ {
+ wxPoint pts[5];
+ pts[0].x = x; pts[0].y = y + bulletHeight/2;
+ pts[1].x = x + bulletWidth/2; pts[1].y = y;
+ pts[2].x = x + bulletWidth; pts[2].y = y + bulletHeight/2;
+ pts[3].x = x + bulletWidth/2; pts[3].y = y + bulletHeight;
+
+ dc.DrawPolygon(4, pts);
+ }
+ else if (bulletAttr.GetBulletName() == wxT("standard/triangle"))
+ {
+ wxPoint pts[3];
+ pts[0].x = x; pts[0].y = y;
+ pts[1].x = x + bulletWidth; pts[1].y = y + bulletHeight/2;
+ pts[2].x = x; pts[2].y = y + bulletHeight;
+
+ dc.DrawPolygon(3, pts);
+ }
+ else if (bulletAttr.GetBulletName() == wxT("standard/circle-outline"))
+ {
+ wxCheckSetBrush(dc, *wxTRANSPARENT_BRUSH);
+ dc.DrawEllipse(x, y, bulletWidth, bulletHeight);
+ }
+ else // "standard/circle", and catch-all
+ {
+ dc.DrawEllipse(x, y, bulletWidth, bulletHeight);
+ }
+
+ return true;
+}
+
+bool wxRichTextStdRenderer::DrawTextBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, const wxRect& rect, const wxString& text)
+{
+ if (!text.empty())
+ {
+ wxFont font;
+ if ((attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL) && !attr.GetBulletFont().IsEmpty() && attr.HasFont())
+ {
+ wxRichTextAttr fontAttr;
+ if (attr.HasFontPixelSize())
+ fontAttr.SetFontPixelSize(attr.GetFontSize());
+ else
+ fontAttr.SetFontPointSize(attr.GetFontSize());
+ fontAttr.SetFontStyle(attr.GetFontStyle());
+ fontAttr.SetFontWeight(attr.GetFontWeight());
+ fontAttr.SetFontUnderlined(attr.GetFontUnderlined());
+ fontAttr.SetFontFaceName(attr.GetBulletFont());
+ font = paragraph->GetBuffer()->GetFontTable().FindFont(fontAttr);
+ }
+ else if (attr.HasFont())
+ font = paragraph->GetBuffer()->GetFontTable().FindFont(attr);
+ else
+ font = (*wxNORMAL_FONT);
+
+ wxCheckSetFont(dc, font);
+
+ if (attr.GetTextColour().IsOk())
+ dc.SetTextForeground(attr.GetTextColour());
+
+ dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
+
+ int charHeight = dc.GetCharHeight();
+ wxCoord tw, th;
+ dc.GetTextExtent(text, & tw, & th);
+
+ int x = rect.x;
+
+ // Calculate the top position of the character (as opposed to the whole line height)
+ int y = rect.y + (rect.height - charHeight);
+
+ // The margin between a bullet and text.
+ int margin = paragraph->ConvertTenthsMMToPixels(dc, wxRichTextBuffer::GetBulletRightMargin());
+
+ if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT)
+ x = (rect.x + rect.width) - tw - margin;
+ else if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_ALIGN_CENTRE)
+ x = x + (rect.width)/2 - tw/2;
+
+ dc.DrawText(text, x, y);
+
+ return true;
+ }
+ else
+ return false;
+}
+
+bool wxRichTextStdRenderer::DrawBitmapBullet(wxRichTextParagraph* WXUNUSED(paragraph), wxDC& WXUNUSED(dc), const wxRichTextAttr& WXUNUSED(attr), const wxRect& WXUNUSED(rect))
+{
+ // Currently unimplemented. The intention is to store bitmaps by name in a media store associated
+ // with the buffer. The store will allow retrieval from memory, disk or other means.
+ return false;
+}
+
+/// Enumerate the standard bullet names currently supported
+bool wxRichTextStdRenderer::EnumerateStandardBulletNames(wxArrayString& bulletNames)
+{
+ bulletNames.Add(wxTRANSLATE("standard/circle"));
+ bulletNames.Add(wxTRANSLATE("standard/circle-outline"));
+ bulletNames.Add(wxTRANSLATE("standard/square"));
+ bulletNames.Add(wxTRANSLATE("standard/diamond"));
+ bulletNames.Add(wxTRANSLATE("standard/triangle"));
+
+ return true;
+}
+
+/*!
+ * wxRichTextBox
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxRichTextBox, wxRichTextParagraphLayoutBox)
+
+wxRichTextBox::wxRichTextBox(wxRichTextObject* parent):
+ wxRichTextParagraphLayoutBox(parent)
+{
+}
+
+/// Draw the item
+bool wxRichTextBox::Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style)
+{
+ if (!IsShown())
+ return true;
+
+ // TODO: if the active object in the control, draw an indication.
+ // We need to add the concept of active object, and not just focus object,
+ // so we can apply commands (properties, delete, ...) to objects such as text boxes and images.
+ // Ultimately we would like to be able to interactively resize an active object
+ // using drag handles.
+ return wxRichTextParagraphLayoutBox::Draw(dc, context, range, selection, rect, descent, style);
+}
+
+/// Copy
+void wxRichTextBox::Copy(const wxRichTextBox& obj)
+{
+ wxRichTextParagraphLayoutBox::Copy(obj);
+}
+
+// Edit properties via a GUI
+bool wxRichTextBox::EditProperties(wxWindow* parent, wxRichTextBuffer* buffer)
+{
+ wxRichTextObjectPropertiesDialog boxDlg(this, wxGetTopLevelParent(parent), wxID_ANY, _("Box Properties"));
+ boxDlg.SetAttributes(GetAttributes());
+
+ if (boxDlg.ShowModal() == wxID_OK)
+ {
+ // By passing wxRICHTEXT_SETSTYLE_RESET, indeterminate attributes set by the user will be set as
+ // indeterminate in the object.
+ boxDlg.ApplyStyle(buffer->GetRichTextCtrl(), wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_RESET);
+ return true;
+ }
+ else
+ return false;
+}
+
+/*!
+ * wxRichTextField
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxRichTextField, wxRichTextParagraphLayoutBox)
+
+wxRichTextField::wxRichTextField(const wxString& fieldType, wxRichTextObject* parent):
+ wxRichTextParagraphLayoutBox(parent)
+{
+ SetFieldType(fieldType);
+}
+
+/// Draw the item
+bool wxRichTextField::Draw(wxDC& dc, wxRichTextDrawingContext& context, const wxRichTextRange& range, const wxRichTextSelection& selection, const wxRect& rect, int descent, int style)
+{
+ if (!IsShown())
+ return true;
+
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType && fieldType->Draw(this, dc, context, range, selection, rect, descent, style))
+ return true;
+
+ // Fallback; but don't draw guidelines.
+ style &= ~wxRICHTEXT_DRAW_GUIDELINES;
+ return wxRichTextParagraphLayoutBox::Draw(dc, context, range, selection, rect, descent, style);
+}
+
+bool wxRichTextField::Layout(wxDC& dc, wxRichTextDrawingContext& context, const wxRect& rect, const wxRect& parentRect, int style)
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType && fieldType->Layout(this, dc, context, rect, parentRect, style))
+ return true;
+
+ // Fallback
+ return wxRichTextParagraphLayoutBox::Layout(dc, context, rect, parentRect, style);
+}
+
+bool wxRichTextField::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position, const wxSize& parentSize, wxArrayInt* partialExtents) const
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType)
+ return fieldType->GetRangeSize((wxRichTextField*) this, range, size, descent, dc, context, flags, position, parentSize, partialExtents);
+
+ return wxRichTextParagraphLayoutBox::GetRangeSize(range, size, descent, dc, context, flags, position, parentSize, partialExtents);
+}
+
+/// Calculate range
+void wxRichTextField::CalculateRange(long start, long& end)
+{
+ if (IsTopLevel())
+ wxRichTextParagraphLayoutBox::CalculateRange(start, end);
+ else
+ wxRichTextObject::CalculateRange(start, end);
+}
+
+/// Copy
+void wxRichTextField::Copy(const wxRichTextField& obj)
+{
+ wxRichTextParagraphLayoutBox::Copy(obj);
+
+ UpdateField(GetBuffer());
+}
+
+// Edit properties via a GUI
+bool wxRichTextField::EditProperties(wxWindow* parent, wxRichTextBuffer* buffer)
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType)
+ return fieldType->EditProperties(this, parent, buffer);
+
+ return false;
+}
+
+bool wxRichTextField::CanEditProperties() const
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType)
+ return fieldType->CanEditProperties((wxRichTextField*) this);
+
+ return false;
+}
+
+wxString wxRichTextField::GetPropertiesMenuLabel() const
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType)
+ return fieldType->GetPropertiesMenuLabel((wxRichTextField*) this);
+
+ return wxEmptyString;
+}
+
+bool wxRichTextField::UpdateField(wxRichTextBuffer* buffer)
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType)
+ return fieldType->UpdateField(buffer, (wxRichTextField*) this);
+
+ return false;
+}
+
+bool wxRichTextField::IsTopLevel() const
+{
+ wxRichTextFieldType* fieldType = wxRichTextBuffer::FindFieldType(GetFieldType());
+ if (fieldType)
+ return fieldType->IsTopLevel((wxRichTextField*) this);
+
+ return true;
+}
+
+IMPLEMENT_CLASS(wxRichTextFieldType, wxObject)
+
+IMPLEMENT_CLASS(wxRichTextFieldTypeStandard, wxRichTextFieldType)
+
+wxRichTextFieldTypeStandard::wxRichTextFieldTypeStandard(const wxString& name, const wxString& label, int displayStyle)
+{
+ Init();
+
+ SetName(name);
+ SetLabel(label);
+ SetDisplayStyle(displayStyle);
+}
+
+wxRichTextFieldTypeStandard::wxRichTextFieldTypeStandard(const wxString& name, const wxBitmap& bitmap, int displayStyle)
+{
+ Init();
+
+ SetName(name);
+ SetBitmap(bitmap);
+ SetDisplayStyle(displayStyle);
+}
+
+void wxRichTextFieldTypeStandard::Init()
+{
+ m_displayStyle = wxRICHTEXT_FIELD_STYLE_RECTANGLE;
+ m_font = wxFont(6, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
+ m_textColour = *wxWHITE;
+ m_borderColour = *wxBLACK;
+ m_backgroundColour = *wxBLACK;
+ m_verticalPadding = 1;
+ m_horizontalPadding = 3;
+ m_horizontalMargin = 2;
+ m_verticalMargin = 0;
+}
+
+void wxRichTextFieldTypeStandard::Copy(const wxRichTextFieldTypeStandard& field)
+{
+ wxRichTextFieldType::Copy(field);
+
+ m_label = field.m_label;
+ m_displayStyle = field.m_displayStyle;
+ m_font = field.m_font;
+ m_textColour = field.m_textColour;
+ m_borderColour = field.m_borderColour;
+ m_backgroundColour = field.m_backgroundColour;
+ m_verticalPadding = field.m_verticalPadding;
+ m_horizontalPadding = field.m_horizontalPadding;
+ m_horizontalMargin = field.m_horizontalMargin;
+ m_bitmap = field.m_bitmap;
+}
+
+bool wxRichTextFieldTypeStandard::Draw(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& WXUNUSED(context), const wxRichTextRange& WXUNUSED(range), const wxRichTextSelection& selection, const wxRect& rect, int descent, int WXUNUSED(style))
+{
+ if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_COMPOSITE)
+ return false; // USe default composite drawing
+ else // if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_RECTANGLE || m_displayStyle == wxRICHTEXT_FIELD_STYLE_NOBORDER)
+ {
+ int borderSize = 1;
+
+ wxPen borderPen(m_borderColour, 1, wxSOLID);
+ wxBrush backgroundBrush(m_backgroundColour);
+ wxColour textColour(m_textColour);
+
+ if (selection.WithinSelection(obj->GetRange().GetStart(), obj))
+ {
+ wxColour highlightColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
+ wxColour highlightTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
+
+ borderPen = wxPen(highlightTextColour, 1, wxSOLID);
+ backgroundBrush = wxBrush(highlightColour);
+
+ wxCheckSetBrush(dc, backgroundBrush);
+ wxCheckSetPen(dc, wxPen(highlightColour, 1, wxSOLID));
+ dc.DrawRectangle(rect);
+ }
+
+ if (m_displayStyle != wxRICHTEXT_FIELD_STYLE_NO_BORDER)
+ borderSize = 0;
+
+ // objectRect is the area where the content is drawn, after margins around it have been taken into account
+ wxRect objectRect = wxRect(wxPoint(rect.x + m_horizontalMargin, rect.y + wxMax(0, rect.height - descent - obj->GetCachedSize().y)),
+ wxSize(obj->GetCachedSize().x - 2*m_horizontalMargin - borderSize, obj->GetCachedSize().y));
+
+ // clientArea is where the text is actually written
+ wxRect clientArea = objectRect;
+
+ if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_RECTANGLE)
+ {
+ dc.SetPen(borderPen);
+ dc.SetBrush(backgroundBrush);
+ dc.DrawRoundedRectangle(objectRect, 4.0);
+ }
+ else if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_START_TAG)
+ {
+ int arrowLength = objectRect.height/2;
+ clientArea.width -= (arrowLength - m_horizontalPadding);
+
+ wxPoint pts[5];
+ pts[0].x = objectRect.x; pts[0].y = objectRect.y;
+ pts[1].x = objectRect.x + objectRect.width - arrowLength; pts[1].y = objectRect.y;
+ pts[2].x = objectRect.x + objectRect.width; pts[2].y = objectRect.y + (objectRect.height/2);
+ pts[3].x = objectRect.x + objectRect.width - arrowLength; pts[3].y = objectRect.y + objectRect.height;
+ pts[4].x = objectRect.x; pts[4].y = objectRect.y + objectRect.height;
+ dc.SetPen(borderPen);
+ dc.SetBrush(backgroundBrush);
+ dc.DrawPolygon(5, pts);
+ }
+ else if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_END_TAG)
+ {
+ int arrowLength = objectRect.height/2;
+ clientArea.width -= (arrowLength - m_horizontalPadding);
+ clientArea.x += (arrowLength - m_horizontalPadding);
+
+ wxPoint pts[5];
+ pts[0].x = objectRect.x + objectRect.width; pts[0].y = objectRect.y;
+ pts[1].x = objectRect.x + arrowLength; pts[1].y = objectRect.y;
+ pts[2].x = objectRect.x; pts[2].y = objectRect.y + (objectRect.height/2);
+ pts[3].x = objectRect.x + arrowLength; pts[3].y = objectRect.y + objectRect.height;
+ pts[4].x = objectRect.x + objectRect.width; pts[4].y = objectRect.y + objectRect.height;
+ dc.SetPen(borderPen);
+ dc.SetBrush(backgroundBrush);
+ dc.DrawPolygon(5, pts);
+ }
+
+ if (m_bitmap.IsOk())
+ {
+ int x = clientArea.x + (clientArea.width - m_bitmap.GetWidth())/2;
+ int y = clientArea.y + m_verticalPadding;
+ dc.DrawBitmap(m_bitmap, x, y, true);
+
+ if (selection.WithinSelection(obj->GetRange().GetStart(), obj))
+ {
+ wxCheckSetBrush(dc, *wxBLACK_BRUSH);
+ wxCheckSetPen(dc, *wxBLACK_PEN);
+ dc.SetLogicalFunction(wxINVERT);
+ dc.DrawRectangle(wxRect(x, y, m_bitmap.GetWidth(), m_bitmap.GetHeight()));
+ dc.SetLogicalFunction(wxCOPY);
+ }
+ }
+ else
+ {
+ wxString label(m_label);
+ if (label.IsEmpty())
+ label = wxT("??");
+ int w, h, maxDescent;
+ dc.SetFont(m_font);
+ dc.GetTextExtent(m_label, & w, &h, & maxDescent);
+ dc.SetTextForeground(textColour);
+
+ int x = clientArea.x + (clientArea.width - w)/2;
+ int y = clientArea.y + (clientArea.height - (h - maxDescent))/2;
+ dc.DrawText(m_label, x, y);
+ }
+ }
+
+ return true;
+}
+
+bool wxRichTextFieldTypeStandard::Layout(wxRichTextField* obj, wxDC& dc, wxRichTextDrawingContext& context, const wxRect& WXUNUSED(rect), const wxRect& WXUNUSED(parentRect), int style)
+{
+ if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_COMPOSITE)
+ return false; // USe default composite layout
+
+ wxSize size = GetSize(obj, dc, context, style);
+ obj->SetCachedSize(size);
+ obj->SetMinSize(size);
+ obj->SetMaxSize(size);
+ return true;
+}
+
+bool wxRichTextFieldTypeStandard::GetRangeSize(wxRichTextField* obj, const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, wxRichTextDrawingContext& context, int flags, const wxPoint& position, const wxSize& parentSize, wxArrayInt* partialExtents) const
+{
+ if (IsTopLevel(obj))
+ return obj->wxRichTextParagraphLayoutBox::GetRangeSize(range, size, descent, dc, context, flags, position, parentSize);
+ else
+ {
+ wxSize sz = GetSize(obj, dc, context, 0);
+ if (partialExtents)
+ {
+ int lastSize;
+ if (partialExtents->GetCount() > 0)
+ lastSize = (*partialExtents)[partialExtents->GetCount()-1];
+ else
+ lastSize = 0;
+ partialExtents->Add(lastSize + sz.x);
+ }
+ size = sz;
+ return true;
+ }
+}
+
+wxSize wxRichTextFieldTypeStandard::GetSize(wxRichTextField* WXUNUSED(obj), wxDC& dc, wxRichTextDrawingContext& WXUNUSED(context), int WXUNUSED(style)) const
+{
+ int borderSize = 1;
+ int w = 0, h = 0, maxDescent = 0;
+
+ wxSize sz;
+ if (m_bitmap.IsOk())
+ {
+ w = m_bitmap.GetWidth();
+ h = m_bitmap.GetHeight();
+
+ sz = wxSize(w + m_horizontalMargin*2, h + m_verticalMargin*2);
+ }
+ else
+ {
+ wxString label(m_label);
+ if (label.IsEmpty())
+ label = wxT("??");
+ dc.SetFont(m_font);
+ dc.GetTextExtent(label, & w, &h, & maxDescent);
+
+ sz = wxSize(w + m_horizontalPadding*2 + m_horizontalMargin*2, h + m_verticalPadding *2 + m_verticalMargin*2);
+ }
+
+ if (m_displayStyle != wxRICHTEXT_FIELD_STYLE_NO_BORDER)
+ {
+ sz.x += borderSize*2;
+ sz.y += borderSize*2;
+ }
+
+ if (m_displayStyle == wxRICHTEXT_FIELD_STYLE_START_TAG || m_displayStyle == wxRICHTEXT_FIELD_STYLE_END_TAG)
+ {
+ // Add space for the arrow
+ sz.x += (sz.y/2 - m_horizontalPadding);
+ }
+
+ return sz;
+}