X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/336d8ae9a3feae7b2c3ecd8f64fe0e16984edfe7..18138662efd0bc550d78cbe32e93e25b43bbcbd2:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 6388b00489..47f1e8d8e3 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1561,11 +1561,12 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const bool parasOnly = ((flags & wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY) != 0); bool charactersOnly = ((flags & wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY) != 0); bool resetExistingStyle = ((flags & wxRICHTEXT_SETSTYLE_RESET) != 0); + bool removeStyle = ((flags & wxRICHTEXT_SETSTYLE_REMOVE) != 0); // Apply paragraph style first, if any wxRichTextAttr wholeStyle(style); - if (wholeStyle.HasParagraphStyleName() && GetStyleSheet()) + if (!removeStyle && wholeStyle.HasParagraphStyleName() && GetStyleSheet()) { wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(wholeStyle.GetParagraphStyleName()); if (def) @@ -1576,7 +1577,7 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const wxRichTextAttr characterAttributes(wholeStyle); characterAttributes.SetFlags(characterAttributes.GetFlags() & (wxTEXT_ATTR_CHARACTER)); - if (characterAttributes.HasCharacterStyleName() && GetStyleSheet()) + if (!removeStyle && characterAttributes.HasCharacterStyleName() && GetStyleSheet()) { wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterAttributes.GetCharacterStyleName()); if (def) @@ -1630,7 +1631,12 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const // to be included in the paragraph style if ((paragraphStyle || parasOnly) && !charactersOnly) { - if (resetExistingStyle) + if (removeStyle) + { + // Removes the given style from the paragraph + wxRichTextRemoveStyle(newPara->GetAttributes(), style); + } + else if (resetExistingStyle) newPara->GetAttributes() = wholeStyle; else { @@ -1705,7 +1711,12 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const { wxRichTextObject* child = node2->GetData(); - if (resetExistingStyle) + if (removeStyle) + { + // Removes the given style from the paragraph + wxRichTextRemoveStyle(child->GetAttributes(), style); + } + else if (resetExistingStyle) child->GetAttributes() = characterAttributes; else { @@ -3017,6 +3028,16 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR wxTextAttrEx bulletAttr(GetCombinedAttributes()); + // Combine with the font of the first piece of content, if one is specified + if (GetChildren().GetCount() > 0) + { + wxRichTextObject* firstObj = (wxRichTextObject*) GetChildren().GetFirst()->GetData(); + if (firstObj->GetAttributes().HasFont()) + { + wxRichTextApplyStyle(bulletAttr, firstObj->GetAttributes()); + } + } + // Get line height from first line, if any wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL; @@ -3658,12 +3679,12 @@ int wxRichTextParagraph::HitTest(wxDC& dc, const wxPoint& pt, long& textPosition if (pt.x < linePos.x) { textPosition = lineRange.GetStart(); - return wxRICHTEXT_HITTEST_BEFORE; + return wxRICHTEXT_HITTEST_BEFORE|wxRICHTEXT_HITTEST_OUTSIDE; } else if (pt.x >= (linePos.x + lineSize.x)) { textPosition = lineRange.GetEnd(); - return wxRICHTEXT_HITTEST_AFTER; + return wxRICHTEXT_HITTEST_AFTER|wxRICHTEXT_HITTEST_OUTSIDE; } else { @@ -4730,7 +4751,8 @@ bool wxRichTextBuffer::InsertTextWithUndo(long pos, const wxString& text, wxRich wxTextAttrEx paraAttr; if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE) { - paraAttr = GetStyleForNewParagraph(pos); + // Get appropriate paragraph style + paraAttr = GetStyleForNewParagraph(pos, false, false); if (!paraAttr.IsDefault()) p = & paraAttr; } @@ -4745,6 +4767,8 @@ bool wxRichTextBuffer::InsertTextWithUndo(long pos, const wxString& text, wxRich length --; action->GetNewParagraphs().SetPartialParagraph(true); } + else if (text.length() > 0 && text.Last() == wxT('\n')) + length --; action->SetPosition(pos); @@ -4765,7 +4789,7 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int wxTextAttrEx paraAttr; if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE) { - paraAttr = GetStyleForNewParagraph(pos); + paraAttr = GetStyleForNewParagraph(pos, false, true /* look for next paragraph style */); if (!paraAttr.IsDefault()) p = & paraAttr; } @@ -4829,7 +4853,7 @@ bool wxRichTextBuffer::InsertImageWithUndo(long pos, const wxRichTextImageBlock& /// 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 wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPosition) const +wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPosition, bool lookUpNewParaStyle) const { wxRichTextParagraph* para = GetParagraphAtPosition(pos, caretPosition); if (para) @@ -4838,7 +4862,7 @@ wxRichTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPos bool foundAttributes = false; // Look for a matching paragraph style - if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && GetStyleSheet()) + if (lookUpNewParaStyle && !para->GetAttributes().GetParagraphStyleName().IsEmpty() && GetStyleSheet()) { wxRichTextParagraphStyleDefinition* paraDef = GetStyleSheet()->FindParagraphStyle(para->GetAttributes().GetParagraphStyleName()); if (paraDef) @@ -6038,6 +6062,13 @@ bool wxRichTextAction::Do() // Don't take into account the last newline if (m_newParagraphs.GetPartialParagraph()) newCaretPosition --; + else + if (m_newParagraphs.GetChildren().GetCount() > 1) + { + wxRichTextObject* p = (wxRichTextObject*) m_newParagraphs.GetChildren().GetLast()->GetData(); + if (p->GetRange().GetLength() == 1) + newCaretPosition --; + } newCaretPosition = wxMin(newCaretPosition, (m_buffer->GetRange().GetEnd()-1)); @@ -7079,6 +7110,17 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style, return true; } +// Remove attributes +bool wxRichTextRemoveStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style) +{ + int flags = style.GetFlags(); + int destFlags = destStyle.GetFlags(); + + destStyle.SetFlags(destFlags & ~flags); + + return true; +} + /// Combine two bitlists, specifying the bits of interest with separate flags. bool wxRichTextCombineBitlists(int& valueA, int valueB, int& flagsA, int flagsB) {