X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/07854e5edda33cdb2c4ff50f545f7a3eb94badc3..ba53bf083e768a770a7011d0ba0143484a8d3a33:/src/richtext/richtextctrl.cpp diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index f480f23015..3ff5366e30 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -630,7 +630,7 @@ void wxRichTextCtrl::OnChar(wxKeyEvent& event) event.Skip(); return; } - + default: { if (event.CmdDown() || event.AltDown()) @@ -1721,14 +1721,14 @@ bool wxRichTextCtrl::SelectWord(long position) { if (position < 0 || position > GetBuffer().GetRange().GetEnd()) return false; - + wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(position); if (!para) return false; long positionStart = position; long positionEnd = position; - + for (positionStart = position; positionStart >= para->GetRange().GetStart(); positionStart --) { wxString text = GetBuffer().GetTextForRange(wxRichTextRange(positionStart, positionStart)); @@ -1740,7 +1740,7 @@ bool wxRichTextCtrl::SelectWord(long position) } if (positionStart < para->GetRange().GetStart()) positionStart = para->GetRange().GetStart(); - + for (positionEnd = position; positionEnd < para->GetRange().GetEnd(); positionEnd ++) { wxString text = GetBuffer().GetTextForRange(wxRichTextRange(positionEnd, positionEnd)); @@ -1752,13 +1752,13 @@ bool wxRichTextCtrl::SelectWord(long position) } if (positionEnd >= para->GetRange().GetEnd()) positionEnd = para->GetRange().GetEnd(); - + SetSelection(positionStart, positionEnd+1); if (positionStart >= 0) { MoveCaret(positionStart-1, true); - SetDefaultStyleToCursorStyle(); + SetDefaultStyleToCursorStyle(); } return true; @@ -2738,21 +2738,38 @@ bool wxRichTextCtrl::ApplyAlignmentToSelection(wxTextAttrAlignment alignment) } /// Apply a named style to the selection -void wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) +bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) { // Flags are defined within each definition, so only certain // attributes are applied. wxRichTextAttr attr(def->GetStyle()); - + int flags = wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE; + if (def->IsKindOf(CLASSINFO(wxRichTextListStyleDefinition))) + { + flags |= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY; + + wxRichTextRange range; + + if (HasSelection()) + range = GetSelectionRange(); + else + { + long pos = GetAdjustedCaretPosition(GetCaretPosition()); + range = wxRichTextRange(pos, pos+1); + } + + return SetListStyle(range, (wxRichTextListStyleDefinition*) def, flags); + } + // Make sure the attr has the style name if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition))) { attr.SetParagraphStyleName(def->GetName()); - + // If applying a paragraph style, we only want the paragraph nodes to adopt these - // attributes, and not the leaf nodes. This will allow the context (e.g. text) + // attributes, and not the leaf nodes. This will allow the content (e.g. text) // to change its style independently. flags |= wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY; } @@ -2760,9 +2777,12 @@ void wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) attr.SetCharacterStyleName(def->GetName()); if (HasSelection()) - SetStyleEx(GetSelectionRange(), attr, flags); + return SetStyleEx(GetSelectionRange(), attr, flags); else + { SetAndShowDefaultStyle(attr); + return true; + } } /// Apply the style sheet to the buffer, for example if the styles have changed. @@ -2849,6 +2869,45 @@ void wxRichTextCtrl::SetSelectionRange(const wxRichTextRange& range) SetInternalSelectionRange(range1); } +/// Set list style +bool wxRichTextCtrl::SetListStyle(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel) +{ + return GetBuffer().SetListStyle(range.ToInternal(), def, flags, startFrom, specifiedLevel); +} + +bool wxRichTextCtrl::SetListStyle(const wxRichTextRange& range, const wxString& defName, int flags, int startFrom, int specifiedLevel) +{ + return GetBuffer().SetListStyle(range.ToInternal(), defName, flags, startFrom, specifiedLevel); +} + +/// Clear list for given range +bool wxRichTextCtrl::ClearListStyle(const wxRichTextRange& range, int flags) +{ + return GetBuffer().ClearListStyle(range.ToInternal(), flags); +} + +/// Number/renumber any list elements in the given range +bool wxRichTextCtrl::NumberList(const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int startFrom, int specifiedLevel) +{ + return GetBuffer().NumberList(range.ToInternal(), def, flags, startFrom, specifiedLevel); +} + +bool wxRichTextCtrl::NumberList(const wxRichTextRange& range, const wxString& defName, int flags, int startFrom, int specifiedLevel) +{ + return GetBuffer().NumberList(range.ToInternal(), defName, flags, startFrom, specifiedLevel); +} + +/// Promote the list items within the given range. promoteBy can be a positive or negative number, e.g. 1 or -1 +bool wxRichTextCtrl::PromoteList(int promoteBy, const wxRichTextRange& range, wxRichTextListStyleDefinition* def, int flags, int specifiedLevel) +{ + return GetBuffer().PromoteList(promoteBy, range.ToInternal(), def, flags, specifiedLevel); +} + +bool wxRichTextCtrl::PromoteList(int promoteBy, const wxRichTextRange& range, const wxString& defName, int flags, int specifiedLevel) +{ + return GetBuffer().PromoteList(promoteBy, range.ToInternal(), defName, flags, specifiedLevel); +} + #endif // wxUSE_RICHTEXT