X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f120af9d565df0ad12cddda8c8164c6d3917a11c..85a0a12a9c6fe2885c0de8801e91a2f6d6e4119a:/src/richtext/richtextbuffer.cpp?ds=sidebyside diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 3e01cab6fd..ee680385d7 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richtext/richtextbuffer.cpp +// Name: src/richtext/richtextbuffer.cpp // Purpose: Buffer for wxRichTextCtrl // Author: Julian Smart // Modified by: @@ -13,7 +13,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif #if wxUSE_RICHTEXT @@ -21,12 +21,14 @@ #include "wx/richtext/richtextbuffer.h" #ifndef WX_PRECOMP - #include "wx/wx.h" + #include "wx/dc.h" + #include "wx/intl.h" + #include "wx/log.h" + #include "wx/dataobj.h" #endif #include "wx/filename.h" #include "wx/clipbrd.h" -#include "wx/dataobj.h" #include "wx/wfstream.h" #include "wx/module.h" #include "wx/mstream.h" @@ -441,13 +443,13 @@ bool wxRichTextBox::Layout(wxDC& dc, const wxRect& rect, int style) } /// Get/set the size for the given range. Assume only has one child. -bool wxRichTextBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const +bool wxRichTextBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position) const { wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst(); if (node) { wxRichTextObject* child = node->GetData(); - return child->GetRangeSize(range, size, descent, dc, flags); + return child->GetRangeSize(range, size, descent, dc, flags, position); } else return false; @@ -567,7 +569,9 @@ bool wxRichTextParagraphLayoutBox::Layout(wxDC& dc, const wxRect& rect, int styl if (firstParagraph) { wxRichTextObjectList::compatibility_iterator firstNode = m_children.Find(firstParagraph); - wxRichTextObjectList::compatibility_iterator previousNode = firstNode ? firstNode->GetPrevious() : wxRichTextObjectList::compatibility_iterator(); + wxRichTextObjectList::compatibility_iterator previousNode; + if ( firstNode ) + previousNode = firstNode->GetPrevious(); if (firstNode && previousNode) { wxRichTextParagraph* previousParagraph = wxDynamicCast(previousNode->GetData(), wxRichTextParagraph); @@ -655,7 +659,7 @@ void wxRichTextParagraphLayoutBox::Copy(const wxRichTextParagraphLayoutBox& obj) } /// Get/set the size for the given range. -bool wxRichTextParagraphLayoutBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const +bool wxRichTextParagraphLayoutBox::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position) const { wxSize sz; @@ -711,7 +715,7 @@ bool wxRichTextParagraphLayoutBox::GetRangeSize(const wxRichTextRange& range, wx wxSize childSize; int childDescent = 0; - child->GetRangeSize(rangeToFind, childSize, childDescent, dc, flags); + child->GetRangeSize(rangeToFind, childSize, childDescent, dc, flags, position); descent = wxMax(childDescent, descent); @@ -904,7 +908,7 @@ wxRichTextRange wxRichTextParagraphLayoutBox::AddParagraphs(const wxString& text wxRichTextRange range(-1, -1); size_t i = 0; - size_t len = text.Length(); + size_t len = text.length(); wxString line; while (i < len) { @@ -1409,7 +1413,7 @@ wxString wxRichTextParagraphLayoutBox::GetText() const /// Get the paragraph by number wxRichTextParagraph* wxRichTextParagraphLayoutBox::GetParagraphAtLine(long paragraphNumber) const { - if ((size_t) paragraphNumber <= GetChildCount()) + if ((size_t) paragraphNumber >= GetChildCount()) return NULL; return (wxRichTextParagraph*) GetChild((size_t) paragraphNumber); @@ -1669,7 +1673,13 @@ bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxRichTextAttr& style /// Set default style bool wxRichTextParagraphLayoutBox::SetDefaultStyle(const wxTextAttrEx& style) { - m_defaultAttributes = style; + // keep the old attributes if the new style doesn't specify them unless the + // new style is empty - then reset m_defaultStyle (as there is no other way + // to do it) + if ( style.IsDefault() ) + m_defaultAttributes = style; + else + m_defaultAttributes = wxTextAttrEx::CombineEx(style, m_defaultAttributes, NULL); return true; } @@ -1960,7 +1970,7 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& WXUNUSED(range), wxSize objectSize; int descent = 0; - child->GetRangeSize(objectRange, objectSize, descent, dc, wxRICHTEXT_UNFORMATTED); + child->GetRangeSize(objectRange, objectSize, descent, dc, wxRICHTEXT_UNFORMATTED, objectPosition); // Use the child object's width, but the whole line's height wxRect childRect(objectPosition, wxSize(objectSize.x, line->GetSize().y)); @@ -2073,7 +2083,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) childDescent = child->GetDescent(); } else - GetRangeSize(wxRichTextRange(lastEndPos+1, child->GetRange().GetEnd()), childSize, childDescent, dc, wxRICHTEXT_UNFORMATTED); + GetRangeSize(wxRichTextRange(lastEndPos+1, child->GetRange().GetEnd()), childSize, childDescent, dc, wxRICHTEXT_UNFORMATTED,rect.GetPosition()); if (childSize.x + currentWidth > availableSpaceForText) { @@ -2256,7 +2266,7 @@ bool wxRichTextParagraph::InsertText(long pos, const wxString& text) text + textObject->GetText().Mid(posInString); textObject->SetText(newText); - int textLength = text.Length(); + int textLength = text.length(); textObject->SetRange(wxRichTextRange(textObject->GetRange().GetStart(), textObject->GetRange().GetEnd() + textLength)); @@ -2308,7 +2318,7 @@ void wxRichTextParagraph::ClearLines() /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. -bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags) const +bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int flags, wxPoint position) const { if (!range.IsWithin(GetRange())) return false; @@ -2332,7 +2342,7 @@ bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& siz rangeToUse.LimitTo(child->GetRange()); int childDescent = 0; - if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags)) + if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, position)) { sz.y = wxMax(sz.y, childSize.y); sz.x += childSize.x; @@ -2377,7 +2387,7 @@ bool wxRichTextParagraph::GetRangeSize(const wxRichTextRange& range, wxSize& siz wxSize childSize; int childDescent = 0; - if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags)) + if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags, position)) { lineSize.y = wxMax(lineSize.y, childSize.y); lineSize.x += childSize.x; @@ -2478,7 +2488,7 @@ bool wxRichTextParagraph::FindPosition(wxDC& dc, long index, wxPoint& pt, int* h // then we can add this size to the line start position and // paragraph start position to find the actual position. - if (GetRangeSize(r, rangeSize, descent, dc, wxRICHTEXT_UNFORMATTED)) + if (GetRangeSize(r, rangeSize, descent, dc, wxRICHTEXT_UNFORMATTED, line->GetPosition()+ GetPosition())) { pt.x = line->GetPosition().x + GetPosition().x + rangeSize.x; *height = line->GetSize().y; @@ -2531,7 +2541,7 @@ int wxRichTextParagraph::HitTest(wxDC& dc, const wxPoint& pt, long& textPosition wxRichTextRange rangeToUse(lineRange.GetStart(), i); - GetRangeSize(rangeToUse, childSize, descent, dc, wxRICHTEXT_UNFORMATTED); + GetRangeSize(rangeToUse, childSize, descent, dc, wxRICHTEXT_UNFORMATTED, linePos); int nextX = childSize.x + linePos.x; @@ -2750,7 +2760,7 @@ bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& d int spacePos = plainText.Find(wxT(' '), true); if (spacePos != wxNOT_FOUND) { - int positionsFromEndOfString = plainText.Length() - spacePos - 1; + int positionsFromEndOfString = plainText.length() - spacePos - 1; breakPosition = breakPosition - positionsFromEndOfString; } } @@ -2945,7 +2955,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR // (a) All selected. if (selectionRange.GetStart() <= range.GetStart() && selectionRange.GetEnd() >= range.GetEnd()) - { + {/* // Draw all selected dc.SetBrush(*wxBLACK_BRUSH); dc.SetPen(*wxBLACK_PEN); @@ -2955,15 +2965,18 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR dc.DrawRectangle(selRect); dc.SetTextForeground(*wxWHITE); dc.SetBackgroundMode(wxTRANSPARENT); - dc.DrawText(stringChunk, x, y); + dc.DrawText(stringChunk, x, y);*/ + DrawTabbedString(dc, rect,stringChunk, x, y, true); } // (b) None selected. else if (selectionRange.GetEnd() < range.GetStart() || selectionRange.GetStart() > range.GetEnd()) { // Draw all unselected + /* dc.SetTextForeground(GetAttributes().GetTextColour()); dc.SetBackgroundMode(wxTRANSPARENT); - dc.DrawText(stringChunk, x, y); + dc.DrawText(stringChunk, x, y);*/ + DrawTabbedString(dc, rect,stringChunk, x, y, false); } else { @@ -2981,13 +2994,14 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR if (fragmentLen < 0) wxLogDebug(wxT("Mid(%d, %d"), (int)(r1 - offset), (int)fragmentLen); wxString stringFragment = m_text.Mid(r1 - offset, fragmentLen); - +/* dc.SetTextForeground(GetAttributes().GetTextColour()); dc.DrawText(stringFragment, x, y); wxCoord w, h; dc.GetTextExtent(stringFragment, & w, & h); - x += w; + x += w;*/ + DrawTabbedString(dc, rect,stringFragment, x, y, false); } // 2. Selected chunk, if any. @@ -3000,7 +3014,7 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR if (fragmentLen < 0) wxLogDebug(wxT("Mid(%d, %d"), (int)(s1 - offset), (int)fragmentLen); wxString stringFragment = m_text.Mid(s1 - offset, fragmentLen); - +/* wxCoord w, h; dc.GetTextExtent(stringFragment, & w, & h); wxRect selRect(x, rect.y, w, rect.GetHeight()); @@ -3011,7 +3025,8 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR dc.SetTextForeground(*wxWHITE); dc.DrawText(stringFragment, x, y); - x += w; + x += w;*/ + DrawTabbedString(dc, rect,stringFragment, x, y, true); } // 3. Remaining unselected chunk, if any @@ -3024,15 +3039,76 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR if (fragmentLen < 0) wxLogDebug(wxT("Mid(%d, %d"), (int)(s2 - offset), (int)fragmentLen); wxString stringFragment = m_text.Mid(s2 - offset, fragmentLen); - +/* dc.SetTextForeground(GetAttributes().GetTextColour()); - dc.DrawText(stringFragment, x, y); + dc.DrawText(stringFragment, x, y);*/ + DrawTabbedString(dc, rect,stringFragment, x, y, false); } } return true; } +bool wxRichTextPlainText::DrawTabbedString(wxDC& dc,const wxRect& rect,wxString& str, wxCoord& x, wxCoord& y, bool selected) +{ + wxArrayInt tab_array = GetAttributes().GetTabs(); + if(tab_array.IsEmpty()){// create a default tab list at 10 mm each. + for( int i = 0; i < 20; ++i){ + tab_array.Add(i*100); + } + } + int map_mode = dc.GetMapMode(); + dc.SetMapMode(wxMM_LOMETRIC ); + int num_tabs = tab_array.GetCount(); + for( int i = 0; i < num_tabs; ++i){ + tab_array[i] = dc.LogicalToDeviceXRel(tab_array[i]); + } + dc.SetMapMode(map_mode ); + int next_tab_pos = -1; + int tab_pos = -1; + wxCoord w, h; + if(selected){ + dc.SetBrush(*wxBLACK_BRUSH); + dc.SetPen(*wxBLACK_PEN); + dc.SetTextForeground(*wxWHITE); + dc.SetBackgroundMode(wxTRANSPARENT); + } + else{ + dc.SetTextForeground(GetAttributes().GetTextColour()); + dc.SetBackgroundMode(wxTRANSPARENT); + } + while(str.Find(wxT('\t')) >= 0){// 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); + tab_pos = x + w; + bool not_found = true; + for( int i = 0; i < num_tabs && not_found; ++i){ + next_tab_pos = tab_array.Item(i); + if( next_tab_pos > tab_pos){ + not_found = false; + if(selected){ + w = next_tab_pos - x; + wxRect selRect(x, rect.y, w, rect.GetHeight()); + dc.DrawRectangle(selRect); + } + dc.DrawText(stringChunk, x, y); + x = next_tab_pos; + } + } + } + + dc.GetTextExtent(str, & w, & h); + if(selected){ + wxRect selRect(x, rect.y, w, rect.GetHeight()); + dc.DrawRectangle(selRect); + } + dc.DrawText(str, x, y); + x += w; + return true; + +} /// Lay the item out bool wxRichTextPlainText::Layout(wxDC& dc, const wxRect& WXUNUSED(rect), int WXUNUSED(style)) { @@ -3056,7 +3132,7 @@ void wxRichTextPlainText::Copy(const wxRichTextPlainText& obj) /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. -bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int WXUNUSED(flags)) const +bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& descent, wxDC& dc, int WXUNUSED(flags), wxPoint position) const { if (!range.IsWithin(GetRange())) return false; @@ -3072,8 +3148,47 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz long len = range.GetLength(); wxString stringChunk = m_text.Mid(startPos, (size_t) len); wxCoord w, h; + int width = 0; + if(stringChunk.Find(wxT('\t')) >= 0){// the string has a tab + wxArrayInt tab_array = GetAttributes().GetTabs(); + if(tab_array.IsEmpty()) + { + // create a default tab list at 10 mm each. + for( int i = 0; i < 20; ++i) + { + tab_array.Add(i*100); + } + } + int map_mode = dc.GetMapMode(); + dc.SetMapMode(wxMM_LOMETRIC ); + int num_tabs = tab_array.GetCount(); + for( int i = 0; i < num_tabs; ++i) + { + tab_array[i] = dc.LogicalToDeviceXRel(tab_array[i]); + } + dc.SetMapMode(map_mode ); + int next_tab_pos = -1; + + while(stringChunk.Find(wxT('\t')) >= 0){// the string has a tab + // break up the string at the Tab + wxString stringFragment = stringChunk.BeforeFirst(wxT('\t')); + stringChunk = stringChunk.AfterFirst(wxT('\t')); + dc.GetTextExtent(stringFragment, & w, & h); + width += w; + int absolute_width = width + position.x; + bool not_found = true; + for( int i = 0; i < num_tabs && not_found; ++i){ + next_tab_pos = tab_array.Item(i); + if( next_tab_pos > absolute_width){ + not_found = false; + width = next_tab_pos - position.x; + } + } + } + } dc.GetTextExtent(stringChunk, & w, & h, & descent); - size = wxSize(w, dc.GetCharHeight()); + width += w; + size = wxSize(width, dc.GetCharHeight()); return true; } @@ -3083,7 +3198,7 @@ bool wxRichTextPlainText::GetRangeSize(const wxRichTextRange& range, wxSize& siz wxRichTextObject* wxRichTextPlainText::DoSplit(long pos) { int index = pos - GetRange().GetStart(); - if (index < 0 || index >= (int) m_text.Length()) + if (index < 0 || index >= (int) m_text.length()) return NULL; wxString firstPart = m_text.Mid(0, index); @@ -3103,7 +3218,7 @@ wxRichTextObject* wxRichTextPlainText::DoSplit(long pos) /// Calculate range void wxRichTextPlainText::CalculateRange(long start, long& end) { - end = start + m_text.Length() - 1; + end = start + m_text.length() - 1; m_range.SetRange(start, end); } @@ -3228,7 +3343,7 @@ bool wxRichTextBuffer::InsertTextWithUndo(long pos, const wxString& text, wxRich action->SetPosition(pos); // Set the range we'll need to delete in Undo - action->SetRange(wxRichTextRange(pos, pos + text.Length() - 1)); + action->SetRange(wxRichTextRange(pos, pos + text.length() - 1)); SubmitAction(action); @@ -3852,6 +3967,7 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) wxTextDataObject data; wxTheClipboard->GetData(data); wxString text(data.GetText()); + text.Replace(_T("\r\n"), _T("\n")); InsertTextWithUndo(position+1, text, GetRichTextCtrl()); @@ -4257,7 +4373,7 @@ bool wxRichTextImage::Layout(wxDC& WXUNUSED(dc), const wxRect& rect, int WXUNUSE /// Get/set the object size for the given range. Returns false if the range /// is invalid for this object. -bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& WXUNUSED(descent), wxDC& WXUNUSED(dc), int WXUNUSED(flags)) const +bool wxRichTextImage::GetRangeSize(const wxRichTextRange& range, wxSize& size, int& WXUNUSED(descent), wxDC& WXUNUSED(dc), int WXUNUSED(flags), wxPoint WXUNUSED(position)) const { if (!range.IsWithin(GetRange())) return false; @@ -4809,6 +4925,94 @@ bool wxRichTextAttr::GetFontAttributes(const wxFont& font) return true; } +wxRichTextAttr wxRichTextAttr::Combine(const wxRichTextAttr& attr, + const wxRichTextAttr& attrDef, + const wxTextCtrlBase *text) +{ + wxColour colFg = attr.GetTextColour(); + if ( !colFg.Ok() ) + { + colFg = attrDef.GetTextColour(); + + if ( text && !colFg.Ok() ) + colFg = text->GetForegroundColour(); + } + + wxColour colBg = attr.GetBackgroundColour(); + if ( !colBg.Ok() ) + { + colBg = attrDef.GetBackgroundColour(); + + if ( text && !colBg.Ok() ) + colBg = text->GetBackgroundColour(); + } + + wxRichTextAttr newAttr(colFg, colBg); + + if (attr.HasWeight()) + newAttr.SetFontWeight(attr.GetFontWeight()); + + if (attr.HasSize()) + newAttr.SetFontSize(attr.GetFontSize()); + + if (attr.HasItalic()) + newAttr.SetFontStyle(attr.GetFontStyle()); + + if (attr.HasUnderlined()) + newAttr.SetFontUnderlined(attr.GetFontUnderlined()); + + if (attr.HasFaceName()) + newAttr.SetFontFaceName(attr.GetFontFaceName()); + + if (attr.HasAlignment()) + newAttr.SetAlignment(attr.GetAlignment()); + else if (attrDef.HasAlignment()) + newAttr.SetAlignment(attrDef.GetAlignment()); + + if (attr.HasTabs()) + newAttr.SetTabs(attr.GetTabs()); + else if (attrDef.HasTabs()) + newAttr.SetTabs(attrDef.GetTabs()); + + if (attr.HasLeftIndent()) + newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent()); + else if (attrDef.HasLeftIndent()) + newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent()); + + if (attr.HasRightIndent()) + newAttr.SetRightIndent(attr.GetRightIndent()); + else if (attrDef.HasRightIndent()) + newAttr.SetRightIndent(attrDef.GetRightIndent()); + + // NEW ATTRIBUTES + + if (attr.HasParagraphSpacingAfter()) + newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter()); + + if (attr.HasParagraphSpacingBefore()) + newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore()); + + if (attr.HasLineSpacing()) + newAttr.SetLineSpacing(attr.GetLineSpacing()); + + if (attr.HasCharacterStyleName()) + newAttr.SetCharacterStyleName(attr.GetCharacterStyleName()); + + if (attr.HasParagraphStyleName()) + newAttr.SetParagraphStyleName(attr.GetParagraphStyleName()); + + if (attr.HasBulletStyle()) + newAttr.SetBulletStyle(attr.GetBulletStyle()); + + if (attr.HasBulletNumber()) + newAttr.SetBulletNumber(attr.GetBulletNumber()); + + if (attr.HasBulletSymbol()) + newAttr.SetBulletSymbol(attr.GetBulletSymbol()); + + return newAttr; +} + /*! * wxTextAttrEx is an extended version of wxTextAttr with more paragraph attributes. */ @@ -4858,6 +5062,146 @@ void wxTextAttrEx::operator= (const wxTextAttr& attr) wxTextAttr::operator= (attr); } +wxTextAttrEx wxTextAttrEx::CombineEx(const wxTextAttrEx& attr, + const wxTextAttrEx& attrDef, + const wxTextCtrlBase *text) +{ + wxTextAttrEx newAttr; + + // If attr specifies the complete font, just use that font, overriding all + // default font attributes. + if ((attr.GetFlags() & wxTEXT_ATTR_FONT) == wxTEXT_ATTR_FONT) + newAttr.SetFont(attr.GetFont()); + else + { + // First find the basic, default font + long flags = 0; + + wxFont font; + if (attrDef.HasFont()) + { + flags = (attrDef.GetFlags() & wxTEXT_ATTR_FONT); + font = attrDef.GetFont(); + } + else + { + if (text) + font = text->GetFont(); + + // We leave flags at 0 because no font attributes have been specified yet + } + if (!font.Ok()) + font = *wxNORMAL_FONT; + + // Otherwise, if there are font attributes in attr, apply them + if (attr.HasFont()) + { + if (attr.HasSize()) + { + flags |= wxTEXT_ATTR_FONT_SIZE; + font.SetPointSize(attr.GetFont().GetPointSize()); + } + if (attr.HasItalic()) + { + flags |= wxTEXT_ATTR_FONT_ITALIC;; + font.SetStyle(attr.GetFont().GetStyle()); + } + if (attr.HasWeight()) + { + flags |= wxTEXT_ATTR_FONT_WEIGHT; + font.SetWeight(attr.GetFont().GetWeight()); + } + if (attr.HasFaceName()) + { + flags |= wxTEXT_ATTR_FONT_FACE; + font.SetFaceName(attr.GetFont().GetFaceName()); + } + if (attr.HasUnderlined()) + { + flags |= wxTEXT_ATTR_FONT_UNDERLINE; + font.SetUnderlined(attr.GetFont().GetUnderlined()); + } + newAttr.SetFont(font); + newAttr.SetFlags(newAttr.GetFlags()|flags); + } + } + + // TODO: should really check we are specifying these in the flags, + // before setting them, as per above; or we will set them willy-nilly. + // However, we should also check whether this is the intention + // as per wxTextAttr::Combine, i.e. always to have valid colours + // in the style. + wxColour colFg = attr.GetTextColour(); + if ( !colFg.Ok() ) + { + colFg = attrDef.GetTextColour(); + + if ( text && !colFg.Ok() ) + colFg = text->GetForegroundColour(); + } + + wxColour colBg = attr.GetBackgroundColour(); + if ( !colBg.Ok() ) + { + colBg = attrDef.GetBackgroundColour(); + + if ( text && !colBg.Ok() ) + colBg = text->GetBackgroundColour(); + } + + newAttr.SetTextColour(colFg); + newAttr.SetBackgroundColour(colBg); + + if (attr.HasAlignment()) + newAttr.SetAlignment(attr.GetAlignment()); + else if (attrDef.HasAlignment()) + newAttr.SetAlignment(attrDef.GetAlignment()); + + if (attr.HasTabs()) + newAttr.SetTabs(attr.GetTabs()); + else if (attrDef.HasTabs()) + newAttr.SetTabs(attrDef.GetTabs()); + + if (attr.HasLeftIndent()) + newAttr.SetLeftIndent(attr.GetLeftIndent(), attr.GetLeftSubIndent()); + else if (attrDef.HasLeftIndent()) + newAttr.SetLeftIndent(attrDef.GetLeftIndent(), attr.GetLeftSubIndent()); + + if (attr.HasRightIndent()) + newAttr.SetRightIndent(attr.GetRightIndent()); + else if (attrDef.HasRightIndent()) + newAttr.SetRightIndent(attrDef.GetRightIndent()); + + // NEW ATTRIBUTES + + if (attr.HasParagraphSpacingAfter()) + newAttr.SetParagraphSpacingAfter(attr.GetParagraphSpacingAfter()); + + if (attr.HasParagraphSpacingBefore()) + newAttr.SetParagraphSpacingBefore(attr.GetParagraphSpacingBefore()); + + if (attr.HasLineSpacing()) + newAttr.SetLineSpacing(attr.GetLineSpacing()); + + if (attr.HasCharacterStyleName()) + newAttr.SetCharacterStyleName(attr.GetCharacterStyleName()); + + if (attr.HasParagraphStyleName()) + newAttr.SetParagraphStyleName(attr.GetParagraphStyleName()); + + if (attr.HasBulletStyle()) + newAttr.SetBulletStyle(attr.GetBulletStyle()); + + if (attr.HasBulletNumber()) + newAttr.SetBulletNumber(attr.GetBulletNumber()); + + if (attr.HasBulletSymbol()) + newAttr.SetBulletSymbol(attr.GetBulletSymbol()); + + return newAttr; +} + + /*! * wxRichTextFileHandler * Base class for file handlers @@ -4942,7 +5286,7 @@ bool wxRichTextPlainTextHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputSt wxString text = buffer->GetText(); wxCharBuffer buf = text.ToAscii(); - stream.Write((const char*) buf, text.Length()); + stream.Write((const char*) buf, text.length()); return true; } #endif // wxUSE_STREAMS @@ -5141,7 +5485,7 @@ bool wxRichTextImageBlock::WriteHex(wxOutputStream& stream) hex = wxDecToHex(m_data[i]); wxCharBuffer buf = hex.ToAscii(); - stream.Write((const char*) buf, hex.Length()); + stream.Write((const char*) buf, hex.length()); } return true;