#include "wx/filename.h"
#include "wx/dcbuffer.h"
#include "wx/arrimpl.cpp"
+#include "wx/fontenum.h"
// DLL options compatibility check:
#include "wx/app.h"
* wxRichTextCtrl
*/
+wxArrayString wxRichTextCtrl::sm_availableFontNames;
+
wxRichTextCtrl::wxRichTextCtrl()
: wxScrollHelper(this)
{
GetBuffer().SetRichTextCtrl(this);
+ if (style & wxTE_READONLY)
+ SetEditable(false);
+
wxTextAttrEx attributes;
attributes.SetFont(GetFont());
attributes.SetTextColour(*wxBLACK);
// Paint the background
PaintBackground(dc);
- wxRegion dirtyRegion = GetUpdateRegion();
-
wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
wxRect availableSpace(GetClientSize());
if (GetBuffer().GetDirty())
event.Skip();
return;
}
-
+
default:
{
if (event.CmdDown() || event.AltDown())
return;
}
+ if (keycode == wxT('\t'))
+ {
+ // See if we need to promote or demote the selection or paragraph at the cursor
+ // position, instead of inserting a tab.
+ long pos = GetAdjustedCaretPosition(GetCaretPosition());
+ wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(pos);
+ if (para && para->GetRange().GetStart() == pos && para->GetAttributes().HasListStyleName())
+ {
+ wxRichTextRange range;
+ if (HasSelection())
+ range = GetSelectionRange();
+ else
+ range = para->GetRange().FromInternal();
+
+ int promoteBy = event.ShiftDown() ? 1 : -1;
+
+ PromoteList(promoteBy, range, NULL);
+ return;
+ }
+ }
+
BeginBatchUndo(_("Insert Text"));
long newPos = m_caretPosition;
{
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));
}
if (positionStart < para->GetRange().GetStart())
positionStart = para->GetRange().GetStart();
-
+
for (positionEnd = position; positionEnd < para->GetRange().GetEnd(); positionEnd ++)
{
wxString text = GetBuffer().GetTextForRange(wxRichTextRange(positionEnd, positionEnd));
}
if (positionEnd >= para->GetRange().GetEnd())
positionEnd = para->GetRange().GetEnd();
-
+
SetSelection(positionStart, positionEnd+1);
if (positionStart >= 0)
{
MoveCaret(positionStart-1, true);
- SetDefaultStyleToCursorStyle();
+ SetDefaultStyleToCursorStyle();
}
return true;
}
/// 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;
}
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.
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);
+}
+
+const wxArrayString& wxRichTextCtrl::GetAvailableFontNames()
+{
+ if (sm_availableFontNames.GetCount() == 0)
+ {
+ sm_availableFontNames = wxFontEnumerator::GetFacenames();
+ sm_availableFontNames.Sort();
+ }
+ return sm_availableFontNames;
+}
+
+void wxRichTextCtrl::ClearAvailableFontNames()
+{
+ sm_availableFontNames.Clear();
+}
+
#endif
// wxUSE_RICHTEXT
-