X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1c13f06e4e758005ab5a92459482bc0ffd25b145..821baf7da4a57028eaa17830b6195056216b71f9:/src/richtext/richtextbuffer.cpp?ds=sidebyside diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 92e0577424..5fa710cdad 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -57,6 +57,7 @@ const wxChar wxRichTextLineBreakChar = (wxChar) 29; inline void wxCheckSetFont(wxDC& dc, const wxFont& font) { +#if 0 const wxFont& font1 = dc.GetFont(); if (font1.IsOk() && font.IsOk()) { @@ -65,9 +66,11 @@ inline void wxCheckSetFont(wxDC& dc, const wxFont& font) font1.GetStyle() == font.GetStyle() && font1.GetWeight() == font.GetWeight() && font1.GetUnderlined() == font.GetUnderlined() && + font1.GetFamily() == font.GetFamily() && font1.GetFaceName() == font.GetFaceName()) return; } +#endif dc.SetFont(font); } @@ -431,7 +434,7 @@ bool wxRichTextCompositeObject::Defragment(const wxRichTextRange& range) while (node) { wxRichTextObject* child = node->GetData(); - if (!child->GetRange().IsOutside(range)) + if (range == wxRICHTEXT_ALL || !child->GetRange().IsOutside(range)) { wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject); if (composite) @@ -875,7 +878,7 @@ wxRichTextLine* wxRichTextParagraphLayoutBox::GetLineAtPosition(long pos, bool c // If the position is end-of-paragraph, then return the last line of // of the paragraph. - (range.GetEnd() == child->GetRange().GetEnd()-1) && (pos == child->GetRange().GetEnd())) + ((range.GetEnd() == child->GetRange().GetEnd()-1) && (pos == child->GetRange().GetEnd()))) return line; node2 = node2->GetNext(); @@ -1796,8 +1799,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const // we only want the paragraphs to hold this character style, then we _don't_ want to // apply the character style. So we need to be able to choose. - // if (!paragraphStyle && characterStyle && range.GetStart() != newPara->GetRange().GetEnd()) - if (!parasOnly && characterStyle && range.GetStart() != newPara->GetRange().GetEnd()) + if (!parasOnly && (characterStyle|charactersOnly) && range.GetStart() != newPara->GetRange().GetEnd()) { wxRichTextRange childRange(range); childRange.LimitTo(newPara->GetRange()); @@ -1946,11 +1948,14 @@ static bool wxHasStyle(long flags, long style) /// Combines 'style' with 'currentStyle' for the purpose of summarising the attributes of a range of /// content. -bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const wxTextAttr& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes) +bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const wxTextAttr& style, long& multipleStyleAttributes, int& multipleTextEffectAttributes, int& absentStyleAttributes, int& absentTextEffectAttributes) { + absentStyleAttributes |= (~style.GetFlags() & wxTEXT_ATTR_ALL); + absentTextEffectAttributes |= (~style.GetTextEffectFlags() & 0xFFFF); + if (style.HasFont()) { - if (style.HasFontSize() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_SIZE)) + if (style.HasFontSize() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_SIZE)) { if (currentStyle.HasFontSize()) { @@ -1967,7 +1972,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasFontItalic() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_ITALIC)) + if (style.HasFontItalic() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_ITALIC)) { if (currentStyle.HasFontItalic()) { @@ -1984,7 +1989,24 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT)) + if (style.HasFontFamily() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_FAMILY)) + { + if (currentStyle.HasFontFamily()) + { + if (currentStyle.GetFontFamily() != style.GetFontFamily()) + { + // Clash of style - mark as such + multipleStyleAttributes |= wxTEXT_ATTR_FONT_FAMILY; + currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_FAMILY); + } + } + else + { + currentStyle.SetFontFamily(style.GetFontFamily()); + } + } + + if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT)) { if (currentStyle.HasFontWeight()) { @@ -2001,7 +2023,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasFontFaceName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_FACE)) + if (style.HasFontFaceName() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_FACE)) { if (currentStyle.HasFontFaceName()) { @@ -2021,7 +2043,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasFontUnderlined() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_FONT_UNDERLINE)) + if (style.HasFontUnderlined() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_UNDERLINE)) { if (currentStyle.HasFontUnderlined()) { @@ -2039,7 +2061,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasTextColour() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_TEXT_COLOUR)) + if (style.HasTextColour() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_TEXT_COLOUR)) { if (currentStyle.HasTextColour()) { @@ -2054,7 +2076,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetTextColour(style.GetTextColour()); } - if (style.HasBackgroundColour() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BACKGROUND_COLOUR)) + if (style.HasBackgroundColour() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_BACKGROUND_COLOUR)) { if (currentStyle.HasBackgroundColour()) { @@ -2069,7 +2091,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetBackgroundColour(style.GetBackgroundColour()); } - if (style.HasAlignment() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_ALIGNMENT)) + if (style.HasAlignment() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_ALIGNMENT)) { if (currentStyle.HasAlignment()) { @@ -2084,7 +2106,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetAlignment(style.GetAlignment()); } - if (style.HasTabs() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_TABS)) + if (style.HasTabs() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_TABS)) { if (currentStyle.HasTabs()) { @@ -2099,7 +2121,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetTabs(style.GetTabs()); } - if (style.HasLeftIndent() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LEFT_INDENT)) + if (style.HasLeftIndent() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_LEFT_INDENT)) { if (currentStyle.HasLeftIndent()) { @@ -2114,7 +2136,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetLeftIndent(style.GetLeftIndent(), style.GetLeftSubIndent()); } - if (style.HasRightIndent() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_RIGHT_INDENT)) + if (style.HasRightIndent() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_RIGHT_INDENT)) { if (currentStyle.HasRightIndent()) { @@ -2129,7 +2151,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetRightIndent(style.GetRightIndent()); } - if (style.HasParagraphSpacingAfter() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_PARA_SPACING_AFTER)) + if (style.HasParagraphSpacingAfter() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_PARA_SPACING_AFTER)) { if (currentStyle.HasParagraphSpacingAfter()) { @@ -2144,7 +2166,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetParagraphSpacingAfter(style.GetParagraphSpacingAfter()); } - if (style.HasParagraphSpacingBefore() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_PARA_SPACING_BEFORE)) + if (style.HasParagraphSpacingBefore() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_PARA_SPACING_BEFORE)) { if (currentStyle.HasParagraphSpacingBefore()) { @@ -2159,7 +2181,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetParagraphSpacingBefore(style.GetParagraphSpacingBefore()); } - if (style.HasLineSpacing() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LINE_SPACING)) + if (style.HasLineSpacing() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_LINE_SPACING)) { if (currentStyle.HasLineSpacing()) { @@ -2174,7 +2196,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetLineSpacing(style.GetLineSpacing()); } - if (style.HasCharacterStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_CHARACTER_STYLE_NAME)) + if (style.HasCharacterStyleName() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_CHARACTER_STYLE_NAME)) { if (currentStyle.HasCharacterStyleName()) { @@ -2189,7 +2211,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetCharacterStyleName(style.GetCharacterStyleName()); } - if (style.HasParagraphStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_PARAGRAPH_STYLE_NAME)) + if (style.HasParagraphStyleName() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_PARAGRAPH_STYLE_NAME)) { if (currentStyle.HasParagraphStyleName()) { @@ -2204,7 +2226,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetParagraphStyleName(style.GetParagraphStyleName()); } - if (style.HasListStyleName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_LIST_STYLE_NAME)) + if (style.HasListStyleName() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_LIST_STYLE_NAME)) { if (currentStyle.HasListStyleName()) { @@ -2219,7 +2241,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetListStyleName(style.GetListStyleName()); } - if (style.HasBulletStyle() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_STYLE)) + if (style.HasBulletStyle() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_BULLET_STYLE)) { if (currentStyle.HasBulletStyle()) { @@ -2234,7 +2256,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetBulletStyle(style.GetBulletStyle()); } - if (style.HasBulletNumber() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_NUMBER)) + if (style.HasBulletNumber() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_BULLET_NUMBER)) { if (currentStyle.HasBulletNumber()) { @@ -2249,7 +2271,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetBulletNumber(style.GetBulletNumber()); } - if (style.HasBulletText() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_TEXT)) + if (style.HasBulletText() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_BULLET_TEXT)) { if (currentStyle.HasBulletText()) { @@ -2267,7 +2289,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasBulletName() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_BULLET_NAME)) + if (style.HasBulletName() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_BULLET_NAME)) { if (currentStyle.HasBulletName()) { @@ -2284,7 +2306,7 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasURL() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_URL)) + if (style.HasURL() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_URL)) { if (currentStyle.HasURL()) { @@ -2301,13 +2323,17 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } - if (style.HasTextEffects() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_EFFECTS)) + if (style.HasTextEffects() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_EFFECTS)) { if (currentStyle.HasTextEffects()) { // We need to find the bits in the new style that are different: // just look at those bits that are specified by the new style. + // We need to remove the bits and flags that are not common between current style + // and new style. In so doing we need to take account of the styles absent from one or more of the + // previous styles. + int currentRelevantTextEffects = currentStyle.GetTextEffects() & style.GetTextEffectFlags(); int newRelevantTextEffects = style.GetTextEffects() & style.GetTextEffectFlags(); @@ -2326,9 +2352,17 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const currentStyle.SetTextEffects(style.GetTextEffects()); currentStyle.SetTextEffectFlags(style.GetTextEffectFlags()); } + + // Mask out the flags and values that cannot be common because they were absent in one or more objecrs + // that we've looked at so far + currentStyle.SetTextEffects(currentStyle.GetTextEffects() & ~absentTextEffectAttributes); + currentStyle.SetTextEffectFlags(currentStyle.GetTextEffectFlags() & ~absentTextEffectAttributes); + + if (currentStyle.GetTextEffectFlags() == 0) + currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_EFFECTS); } - if (style.HasOutlineLevel() && !wxHasStyle(multipleStyleAttributes, wxTEXT_ATTR_OUTLINE_LEVEL)) + if (style.HasOutlineLevel() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_OUTLINE_LEVEL)) { if (currentStyle.HasOutlineLevel()) { @@ -2358,6 +2392,11 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range long multipleStyleAttributes = 0; int multipleTextEffectAttributes = 0; + int absentStyleAttributesPara = 0; + int absentStyleAttributesChar = 0; + int absentTextEffectAttributesPara = 0; + int absentTextEffectAttributesChar = 0; + wxRichTextObjectList::compatibility_iterator node = GetChildren().GetFirst(); while (node) { @@ -2368,7 +2407,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range { wxTextAttr paraStyle = para->GetCombinedAttributes(); - CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes); + CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes, absentStyleAttributesPara, absentTextEffectAttributesPara); } else { @@ -2378,7 +2417,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range // First collect paragraph attributes only wxTextAttr paraStyle = para->GetCombinedAttributes(); paraStyle.SetFlags(paraStyle.GetFlags() & wxTEXT_ATTR_PARAGRAPH); - CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes); + CollectStyle(style, paraStyle, multipleStyleAttributes, multipleTextEffectAttributes, absentStyleAttributesPara, absentTextEffectAttributesPara); wxRichTextObjectList::compatibility_iterator childNode = para->GetChildren().GetFirst(); @@ -2392,7 +2431,7 @@ bool wxRichTextParagraphLayoutBox::GetStyleForRange(const wxRichTextRange& range // Now collect character attributes only childStyle.SetFlags(childStyle.GetFlags() & wxTEXT_ATTR_CHARACTER); - CollectStyle(style, childStyle, multipleStyleAttributes, multipleTextEffectAttributes); + CollectStyle(style, childStyle, multipleStyleAttributes, multipleTextEffectAttributes, absentStyleAttributesChar, absentTextEffectAttributesChar); } childNode = childNode->GetNext(); @@ -3134,7 +3173,7 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR } // Get line height from first line, if any - wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL; + wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : NULL; wxPoint linePos; int lineHeight wxDUMMY_INITIALIZE(0); @@ -3432,6 +3471,10 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) wxSize actualSize; wxRichTextRange actualRange(lastCompletedEndPos+1, wrapPosition); + /// Use previous descent, not the wrapping descent we just found, since this may be too big + /// for the fragment we're about to add. + childDescent = maxDescent; + #if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS // Get height only, then the width using the partial extents GetRangeSize(actualRange, actualSize, childDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_HEIGHT_ONLY); @@ -3529,7 +3572,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) ClearUnusedLines(lineCount); // Apply styles to wrapped lines - ApplyParagraphStyle(attr, rect); + ApplyParagraphStyle(attr, rect, dc); SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceBeforePara + spaceAfterPara)); @@ -3581,7 +3624,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) } /// Apply paragraph styles, such as centering, to wrapped lines -void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect) +void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect, wxDC& dc) { if (!attr.HasAlignment()) return; @@ -3597,12 +3640,18 @@ void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRe // centering, right-justification if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE) { - pos.x = (rect.GetWidth() - size.x)/2 + pos.x; + int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); + pos.x = (rect.GetWidth() - (pos.x - rect.x) - rightIndent - size.x)/2 + pos.x; + // Lines are relative to the paragraph position + pos.x -= GetPosition().x; line->SetPosition(pos); } else if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_RIGHT) { - pos.x = pos.x + rect.GetWidth() - size.x; + int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); + pos.x = rect.x + rect.GetWidth() - size.x - rightIndent; + // Lines are relative to the paragraph position + pos.x -= GetPosition().x; line->SetPosition(pos); } @@ -4152,7 +4201,9 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex text += textObj->GetTextForRange(range); } else - return true; + { + text += wxT(" "); + } } node = node->GetNext(); @@ -4172,7 +4223,9 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex text = textObj->GetTextForRange(range) + text; } else - return true; + { + text = wxT(" ") + text; + } } node = node->GetPrevious(); @@ -4203,7 +4256,7 @@ bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& d widthBefore = 0; size_t i; - for (i = (size_t) range.GetStart(); i < (size_t) range.GetEnd(); i++) + for (i = (size_t) range.GetStart(); i <= (size_t) range.GetEnd(); i++) { int widthFromStartOfThisRange = (*partialExtents)[i - GetRange().GetStart()] - widthBefore; @@ -5224,6 +5277,15 @@ bool wxRichTextBuffer::InsertParagraphsWithUndo(long pos, const wxRichTextParagr action->GetNewParagraphs() = paragraphs; + if (p && !p->IsDefault()) + { + for (wxRichTextObjectList::compatibility_iterator node = action->GetNewParagraphs().GetChildren().GetFirst(); node; node = node->GetNext()) + { + wxRichTextObject* child = node->GetData(); + child->SetAttributes(*p); + } + } + action->SetPosition(pos); wxRichTextRange range = wxRichTextRange(pos, pos + paragraphs.GetRange().GetEnd() - 1); @@ -5306,8 +5368,14 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int { if (para && para->GetRange().GetEnd() == pos) pos1 ++; + + // Now see if we need to number the paragraph. if (newPara->GetAttributes().HasBulletNumber()) - newPara->GetAttributes().SetBulletNumber(newPara->GetAttributes().GetBulletNumber()+1); + { + wxRichTextAttr numberingAttr; + if (FindNextParagraphNumber(para, numberingAttr)) + wxRichTextApplyStyle(newPara->GetAttributes(), (const wxRichTextAttr&) numberingAttr); + } } action->SetPosition(pos); @@ -5416,6 +5484,25 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio } } } + + // Also apply list style if present + if (lookUpNewParaStyle && !para->GetAttributes().GetListStyleName().IsEmpty() && GetStyleSheet()) + { + wxRichTextListStyleDefinition* listDef = 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, GetStyleSheet())); + wxRichTextApplyStyle(attr, listStyle); + attr.SetOutlineLevel(thisLevel); + if (para->GetAttributes().HasBulletNumber()) + attr.SetBulletNumber(para->GetAttributes().GetBulletNumber()); + } + } + if (!foundAttributes) { attr = para->GetAttributes(); @@ -5428,14 +5515,6 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio attr.SetFlags(flags); } - // Now see if we need to number the paragraph. - if (attr.HasBulletStyle()) - { - wxTextAttr numberingAttr; - if (FindNextParagraphNumber(para, numberingAttr)) - wxRichTextApplyStyle(attr, (const wxTextAttr&) numberingAttr); - } - return attr; } else @@ -5607,7 +5686,7 @@ void wxRichTextBuffer::ClearStyleStack() bool wxRichTextBuffer::BeginBold() { wxTextAttr attr; - attr.SetFontWeight(wxBOLD); + attr.SetFontWeight(wxFONTWEIGHT_BOLD); return BeginStyle(attr); } @@ -5616,7 +5695,7 @@ bool wxRichTextBuffer::BeginBold() bool wxRichTextBuffer::BeginItalic() { wxTextAttr attr; - attr.SetFontStyle(wxITALIC); + attr.SetFontStyle(wxFONTSTYLE_ITALIC); return BeginStyle(attr); } @@ -5844,14 +5923,15 @@ bool wxRichTextBuffer::RemoveHandler(const wxString& name) } /// Finds a handler by filename or, if supplied, type -wxRichTextFileHandler *wxRichTextBuffer::FindHandlerFilenameOrType(const wxString& filename, int imageType) +wxRichTextFileHandler *wxRichTextBuffer::FindHandlerFilenameOrType(const wxString& filename, + wxRichTextFileType imageType) { if (imageType != wxRICHTEXT_TYPE_ANY) return FindHandler(imageType); else if (!filename.IsEmpty()) { wxString path, file, ext; - wxSplitPath(filename, & path, & file, & ext); + wxFileName::SplitPath(filename, & path, & file, & ext); return FindHandler(ext, imageType); } else @@ -5874,7 +5954,7 @@ wxRichTextFileHandler* wxRichTextBuffer::FindHandler(const wxString& name) } /// Finds a handler by extension and type -wxRichTextFileHandler* wxRichTextBuffer::FindHandler(const wxString& extension, int type) +wxRichTextFileHandler* wxRichTextBuffer::FindHandler(const wxString& extension, wxRichTextFileType type) { wxList::compatibility_iterator node = sm_handlers.GetFirst(); while (node) @@ -5889,7 +5969,7 @@ wxRichTextFileHandler* wxRichTextBuffer::FindHandler(const wxString& extension, } /// Finds a handler by type -wxRichTextFileHandler* wxRichTextBuffer::FindHandler(int type) +wxRichTextFileHandler* wxRichTextBuffer::FindHandler(wxRichTextFileType type) { wxList::compatibility_iterator node = sm_handlers.GetFirst(); while (node) @@ -5933,7 +6013,7 @@ wxString wxRichTextBuffer::GetExtWildcard(bool combine, bool save, wxArrayInt* t while (node) { wxRichTextFileHandler* handler = (wxRichTextFileHandler*) node->GetData(); - if (handler->IsVisible() && ((save && handler->CanSave()) || !save && handler->CanLoad())) + if (handler->IsVisible() && ((save && handler->CanSave()) || (!save && handler->CanLoad()))) { if (combine) { @@ -5967,7 +6047,7 @@ wxString wxRichTextBuffer::GetExtWildcard(bool combine, bool save, wxArrayInt* t } /// Load a file -bool wxRichTextBuffer::LoadFile(const wxString& filename, int type) +bool wxRichTextBuffer::LoadFile(const wxString& filename, wxRichTextFileType type) { wxRichTextFileHandler* handler = FindHandlerFilenameOrType(filename, type); if (handler) @@ -5983,7 +6063,7 @@ bool wxRichTextBuffer::LoadFile(const wxString& filename, int type) } /// Save a file -bool wxRichTextBuffer::SaveFile(const wxString& filename, int type) +bool wxRichTextBuffer::SaveFile(const wxString& filename, wxRichTextFileType type) { wxRichTextFileHandler* handler = FindHandlerFilenameOrType(filename, type); if (handler) @@ -5996,7 +6076,7 @@ bool wxRichTextBuffer::SaveFile(const wxString& filename, int type) } /// Load from a stream -bool wxRichTextBuffer::LoadFile(wxInputStream& stream, int type) +bool wxRichTextBuffer::LoadFile(wxInputStream& stream, wxRichTextFileType type) { wxRichTextFileHandler* handler = FindHandler(type); if (handler) @@ -6012,7 +6092,7 @@ bool wxRichTextBuffer::LoadFile(wxInputStream& stream, int type) } /// Save to a stream -bool wxRichTextBuffer::SaveFile(wxOutputStream& stream, int type) +bool wxRichTextBuffer::SaveFile(wxOutputStream& stream, wxRichTextFileType type) { wxRichTextFileHandler* handler = FindHandler(type); if (handler) @@ -6086,7 +6166,7 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) wxRichTextBuffer* richTextBuffer = data.GetRichTextBuffer(); if (richTextBuffer) { - InsertParagraphsWithUndo(position+1, *richTextBuffer, GetRichTextCtrl(), wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE); + InsertParagraphsWithUndo(position+1, *richTextBuffer, GetRichTextCtrl(), 0); if (GetRichTextCtrl()) GetRichTextCtrl()->ShowPosition(position + richTextBuffer->GetRange().GetEnd()); delete richTextBuffer; @@ -6110,7 +6190,7 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) #else wxString text2 = text; #endif - InsertTextWithUndo(position+1, text2, GetRichTextCtrl()); + InsertTextWithUndo(position+1, text2, GetRichTextCtrl(), wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE); if (GetRichTextCtrl()) GetRichTextCtrl()->ShowPosition(position + text2.Length()); @@ -6131,10 +6211,10 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) if (action->GetNewParagraphs().GetChildCount() == 1) action->GetNewParagraphs().SetPartialParagraph(true); - action->SetPosition(position); + action->SetPosition(position+1); // Set the range we'll need to delete in Undo - action->SetRange(wxRichTextRange(position, position)); + action->SetRange(wxRichTextRange(position+1, position+1)); SubmitAction(action); @@ -7015,10 +7095,11 @@ bool wxRichTextImage::LoadFromBlock() /// Make block from the wxImage bool wxRichTextImage::MakeBlock() { - if (m_imageBlock.GetImageType() == wxBITMAP_TYPE_ANY || m_imageBlock.GetImageType() == -1) - m_imageBlock.SetImageType(wxBITMAP_TYPE_PNG); + wxBitmapType type = m_imageBlock.GetImageType(); + if ( type == wxBITMAP_TYPE_ANY || type == wxBITMAP_TYPE_INVALID ) + m_imageBlock.SetImageType(type = wxBITMAP_TYPE_PNG); - m_imageBlock.MakeImageBlock(m_image, m_imageBlock.GetImageType()); + m_imageBlock.MakeImageBlock(m_image, type); return m_imageBlock.Ok(); } @@ -7248,7 +7329,7 @@ bool wxRichTextFileHandler::SaveFile(wxRichTextBuffer *buffer, const wxString& f bool wxRichTextFileHandler::CanHandle(const wxString& filename) const { wxString path, file, ext; - wxSplitPath(filename, & path, & file, & ext); + wxFileName::SplitPath(filename, & path, & file, & ext); return (ext.Lower() == GetExtension()); } @@ -7338,7 +7419,7 @@ void wxRichTextImageBlock::Init() { m_data = NULL; m_dataSize = 0; - m_imageType = -1; + m_imageType = wxBITMAP_TYPE_INVALID; } void wxRichTextImageBlock::Clear() @@ -7346,7 +7427,7 @@ void wxRichTextImageBlock::Clear() delete[] m_data; m_data = NULL; m_dataSize = 0; - m_imageType = -1; + m_imageType = wxBITMAP_TYPE_INVALID; } @@ -7356,24 +7437,23 @@ void wxRichTextImageBlock::Clear() // If it's not a JPEG we can make use of 'image', already scaled, so we don't have to // load the image a 2nd time. -bool wxRichTextImageBlock::MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG) +bool wxRichTextImageBlock::MakeImageBlock(const wxString& filename, wxBitmapType imageType, + wxImage& image, bool convertToJPEG) { m_imageType = imageType; wxString filenameToRead(filename); bool removeFile = false; - if (imageType == -1) + if (imageType == wxBITMAP_TYPE_INVALID) return false; // Could not determine image type if ((imageType != wxBITMAP_TYPE_JPEG) && convertToJPEG) { - wxString tempFile; - bool success = wxGetTempFileName(_("image"), tempFile) ; + wxString tempFile = + wxFileName::CreateTempFileName(_("image")); - wxASSERT(success); - - wxUnusedVar(success); + wxASSERT(!tempFile.IsEmpty()); image.SaveFile(tempFile, wxBITMAP_TYPE_JPEG); filenameToRead = tempFile; @@ -7400,19 +7480,16 @@ bool wxRichTextImageBlock::MakeImageBlock(const wxString& filename, int imageTyp // Make an image block from the wxImage in the given // format. -bool wxRichTextImageBlock::MakeImageBlock(wxImage& image, int imageType, int quality) +bool wxRichTextImageBlock::MakeImageBlock(wxImage& image, wxBitmapType imageType, int quality) { m_imageType = imageType; image.SetOption(wxT("quality"), quality); - if (imageType == -1) + if (imageType == wxBITMAP_TYPE_INVALID) return false; // Could not determine image type - wxString tempFile; - bool success = wxGetTempFileName(_("image"), tempFile) ; - - wxASSERT(success); - wxUnusedVar(success); + wxString tempFile = wxFileName::CreateTempFileName(_("image")) ; + wxASSERT(!tempFile.IsEmpty()); if (!image.SaveFile(tempFile, m_imageType)) { @@ -7479,9 +7556,8 @@ bool wxRichTextImageBlock::Load(wxImage& image) wxMemoryInputStream mstream(m_data, m_dataSize); bool success = image.LoadFile(mstream, GetImageType()); #else - wxString tempFile; - bool success = wxGetTempFileName(_("image"), tempFile) ; - wxASSERT(success); + wxString tempFile = wxFileName::CreateTempFileName(_("image")); + wxASSERT(!tempFile.IsEmpty()); if (!WriteBlock(tempFile, m_data, m_dataSize)) { @@ -7528,14 +7604,17 @@ bool wxRichTextImageBlock::WriteHex(wxOutputStream& stream) } // Read data in hex from a stream -bool wxRichTextImageBlock::ReadHex(wxInputStream& stream, int length, int imageType) +bool wxRichTextImageBlock::ReadHex(wxInputStream& stream, int length, wxBitmapType imageType) { int dataSize = length/2; if (m_data) delete[] m_data; - wxChar str[2]; + // create a null terminated temporary string: + char str[3]; + str[2] = '\0'; + m_data = new unsigned char[dataSize]; int i; for (i = 0; i < dataSize; i ++) @@ -7763,6 +7842,7 @@ wxRichTextFontTable::wxRichTextFontTable() } wxRichTextFontTable::wxRichTextFontTable(const wxRichTextFontTable& table) + : wxObject() { (*this) = table; }