X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d75a69e8329cecf6f07c667ffc015186c230a2b5..dc72e2adfa7e7de367c244e91c0402733c2904a8:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index aae4eaa579..fc722e8b62 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) @@ -680,7 +683,7 @@ bool wxRichTextParagraphLayoutBox::Layout(wxDC& dc, const wxRect& rect, int styl // Assume this box only contains paragraphs wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph); - wxCHECK_MSG( child, false, _T("Unknown object in layout") ); + wxCHECK_MSG( child, false, wxT("Unknown object in layout") ); // TODO: what if the child hasn't been laid out (e.g. involved in Undo) but still has 'old' lines if ( !forceQuickLayout && @@ -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(); @@ -2815,7 +2854,7 @@ bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, co bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0); // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0); -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0); #endif @@ -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); @@ -3316,8 +3355,8 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) wxPoint currentPosition(0, spaceBeforePara); // We will calculate lines relative to paragraph int lineHeight = 0; int maxWidth = 0; + int maxAscent = 0; int maxDescent = 0; - int lineCount = 0; wxRichTextObjectList::compatibility_iterator node; @@ -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); @@ -3441,8 +3484,9 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) #endif currentWidth = actualSize.x; - lineHeight = wxMax(lineHeight, actualSize.y); maxDescent = wxMax(childDescent, maxDescent); + maxAscent = wxMax(actualSize.y-childDescent, maxAscent); + lineHeight = maxDescent + maxAscent; // Add a new line wxRichTextLine* line = AllocateLine(lineCount); @@ -3458,6 +3502,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) currentPosition.y += lineSpacing; currentWidth = 0; maxDescent = 0; + maxAscent = 0; maxWidth = wxMax(maxWidth, currentWidth); lineCount ++; @@ -3481,8 +3526,9 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) { // We still fit, so don't add a line, and keep going currentWidth += childSize.x; - lineHeight = wxMax(lineHeight, childSize.y); maxDescent = wxMax(childDescent, maxDescent); + maxAscent = wxMax(childSize.y-childDescent, maxAscent); + lineHeight = maxDescent + maxAscent; maxWidth = wxMax(maxWidth, currentWidth); lastEndPos = child->GetRange().GetEnd(); @@ -3529,7 +3575,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 +3627,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 +3643,14 @@ 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 - rightIndent - size.x)/2 + pos.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.GetWidth() - size.x - rightIndent; line->SetPosition(pos); } @@ -4152,7 +4200,9 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex text += textObj->GetTextForRange(range); } else - return true; + { + text += wxT(" "); + } } node = node->GetNext(); @@ -4172,7 +4222,9 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex text = textObj->GetTextForRange(range) + text; } else - return true; + { + text = wxT(" ") + text; + } } node = node->GetPrevious(); @@ -4203,7 +4255,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; @@ -4618,7 +4670,9 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR int s1 = selectionRange.GetStart()-1; int fragmentLen = s1 - r1 + 1; if (fragmentLen < 0) + { wxLogDebug(wxT("Mid(%d, %d"), (int)(r1 - offset), (int)fragmentLen); + } wxString stringFragment = str.Mid(r1 - offset, fragmentLen); DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, false); @@ -4649,7 +4703,9 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR 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); @@ -4680,7 +4736,9 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR 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); @@ -4741,6 +4799,7 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); } + wxCoord x_orig = x; while (hasTabs) { // the string has a tab @@ -4752,7 +4811,7 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con bool not_found = true; for (int i = 0; i < tabCount && not_found; ++i) { - nextTabPos = tabArray.Item(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. @@ -5315,8 +5374,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); @@ -5425,6 +5490,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(); @@ -5437,14 +5521,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 @@ -5616,7 +5692,7 @@ void wxRichTextBuffer::ClearStyleStack() bool wxRichTextBuffer::BeginBold() { wxTextAttr attr; - attr.SetFontWeight(wxBOLD); + attr.SetFontWeight(wxFONTWEIGHT_BOLD); return BeginStyle(attr); } @@ -5625,7 +5701,7 @@ bool wxRichTextBuffer::BeginBold() bool wxRichTextBuffer::BeginItalic() { wxTextAttr attr; - attr.SetFontStyle(wxITALIC); + attr.SetFontStyle(wxFONTSTYLE_ITALIC); return BeginStyle(attr); } @@ -5861,7 +5937,7 @@ wxRichTextFileHandler *wxRichTextBuffer::FindHandlerFilenameOrType(const wxStrin else if (!filename.IsEmpty()) { wxString path, file, ext; - wxSplitPath(filename, & path, & file, & ext); + wxFileName::SplitPath(filename, & path, & file, & ext); return FindHandler(ext, imageType); } else @@ -5943,7 +6019,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) { @@ -6141,10 +6217,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); @@ -6418,10 +6494,10 @@ bool wxRichTextStdRenderer::DrawBitmapBullet(wxRichTextParagraph* WXUNUSED(parag /// Enumerate the standard bullet names currently supported bool wxRichTextStdRenderer::EnumerateStandardBulletNames(wxArrayString& bulletNames) { - bulletNames.Add(wxT("standard/circle")); - bulletNames.Add(wxT("standard/square")); - bulletNames.Add(wxT("standard/diamond")); - bulletNames.Add(wxT("standard/triangle")); + bulletNames.Add(wxTRANSLATE("standard/circle")); + bulletNames.Add(wxTRANSLATE("standard/square")); + bulletNames.Add(wxTRANSLATE("standard/diamond")); + bulletNames.Add(wxTRANSLATE("standard/triangle")); return true; } @@ -7025,10 +7101,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(); } @@ -7258,7 +7335,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()); } @@ -7374,17 +7451,15 @@ bool wxRichTextImageBlock::MakeImageBlock(const wxString& filename, wxBitmapType 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; @@ -7416,14 +7491,11 @@ bool wxRichTextImageBlock::MakeImageBlock(wxImage& image, wxBitmapType imageType 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)) { @@ -7490,9 +7562,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)) { @@ -7546,7 +7617,10 @@ bool wxRichTextImageBlock::ReadHex(wxInputStream& stream, int length, wxBitmapTy 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 ++) @@ -7774,6 +7848,7 @@ wxRichTextFontTable::wxRichTextFontTable() } wxRichTextFontTable::wxRichTextFontTable(const wxRichTextFontTable& table) + : wxObject() { (*this) = table; }