*/
virtual bool IsSelectionUnderlined();
+ /**
+ Returns @true if all of the selection, or the current caret position, has the supplied wxTextAttrEffects flag(s).
+ */
+ virtual bool DoesSelectionHaveTextEffectFlag(int flag);
+
/**
Returns @true if all of the selection is aligned according to the specified flag.
*/
*/
virtual bool ApplyUnderlineToSelection();
+ /**
+ Applies one or more wxTextAttrEffects flags to the selection (undoable).
+ If there's no selection, it's is applied to the current caret position
+ */
+ virtual bool ApplyTextEffectToSelection(int flags);
+
/**
Applies the given alignment to the selection (undoable).
For alignment values, see wxTextAttr.
*/
virtual bool IsSelectionUnderlined();
+ /**
+ Returns @true if all of the selection, or the current caret position, has the supplied wxTextAttrEffects flag(s).
+ */
+ virtual bool DoesSelectionHaveTextEffectFlag(int flag);
+
/**
Returns @true if all of the selection is aligned according to the specified flag.
*/
*/
virtual bool ApplyUnderlineToSelection();
+ /**
+ Applies one or more wxTextAttrEffects flags to the selection (undoable).
+ If there's no selection, it's applied to the current caret position
+ */
+ virtual bool ApplyTextEffectToSelection(int flags);
+
/**
Applies the given alignment to the selection (undoable).
For alignment values, see wxTextAttr.
/**
Styles for wxTextAttr::SetTextEffects(). They can be combined together as a bitlist.
- Of these, only wxTEXT_ATTR_EFFECT_CAPITALS and wxTEXT_ATTR_EFFECT_STRIKETHROUGH are implemented.
+ Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
+ wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
*/
enum wxTextAttrEffects
{
Sets the text effects, a bit list of styles.
The ::wxTextAttrEffects enumeration values can be used.
- Of these, only wxTEXT_ATTR_EFFECT_CAPITALS and wxTEXT_ATTR_EFFECT_STRIKETHROUGH
- are implemented.
+ Of these, only wxTEXT_ATTR_EFFECT_CAPITALS, wxTEXT_ATTR_EFFECT_STRIKETHROUGH,
+ wxTEXT_ATTR_EFFECT_SUPERSCRIPT and wxTEXT_ATTR_EFFECT_SUBSCRIPT are implemented.
wxTEXT_ATTR_EFFECT_CAPITALS capitalises text when displayed (leaving the case
of the actual buffer text unchanged), and wxTEXT_ATTR_EFFECT_STRIKETHROUGH draws
void OnItalic(wxCommandEvent& event);
void OnUnderline(wxCommandEvent& event);
+ void OnStrikethrough(wxCommandEvent& event);
+ void OnSuperscript(wxCommandEvent& event);
+ void OnSubscript(wxCommandEvent& event);
+
void OnUpdateBold(wxUpdateUIEvent& event);
void OnUpdateItalic(wxUpdateUIEvent& event);
void OnUpdateUnderline(wxUpdateUIEvent& event);
+ void OnUpdateStrikethrough(wxUpdateUIEvent& event);
+ void OnUpdateSuperscript(wxUpdateUIEvent& event);
+ void OnUpdateSubscript(wxUpdateUIEvent& event);
void OnAlignLeft(wxCommandEvent& event);
void OnAlignCentre(wxCommandEvent& event);
ID_FORMAT_BOLD = 100,
ID_FORMAT_ITALIC,
ID_FORMAT_UNDERLINE,
+ ID_FORMAT_STRIKETHROUGH,
+ ID_FORMAT_SUPERSCRIPT,
+ ID_FORMAT_SUBSCRIPT,
ID_FORMAT_FONT,
ID_FORMAT_IMAGE,
ID_FORMAT_PARAGRAPH,
EVT_MENU(ID_FORMAT_ITALIC, MyFrame::OnItalic)
EVT_MENU(ID_FORMAT_UNDERLINE, MyFrame::OnUnderline)
+ EVT_MENU(ID_FORMAT_STRIKETHROUGH, MyFrame::OnStrikethrough)
+ EVT_MENU(ID_FORMAT_SUPERSCRIPT, MyFrame::OnSuperscript)
+ EVT_MENU(ID_FORMAT_SUBSCRIPT, MyFrame::OnSubscript)
+
EVT_UPDATE_UI(ID_FORMAT_BOLD, MyFrame::OnUpdateBold)
EVT_UPDATE_UI(ID_FORMAT_ITALIC, MyFrame::OnUpdateItalic)
EVT_UPDATE_UI(ID_FORMAT_UNDERLINE, MyFrame::OnUpdateUnderline)
+ EVT_UPDATE_UI(ID_FORMAT_STRIKETHROUGH, MyFrame::OnUpdateStrikethrough)
+ EVT_UPDATE_UI(ID_FORMAT_SUPERSCRIPT, MyFrame::OnUpdateSuperscript)
+ EVT_UPDATE_UI(ID_FORMAT_SUBSCRIPT, MyFrame::OnUpdateSubscript)
+
EVT_MENU(ID_FORMAT_ALIGN_LEFT, MyFrame::OnAlignLeft)
EVT_MENU(ID_FORMAT_ALIGN_CENTRE, MyFrame::OnAlignCentre)
EVT_MENU(ID_FORMAT_ALIGN_RIGHT, MyFrame::OnAlignRight)
formatMenu->AppendCheckItem(ID_FORMAT_ITALIC, _("&Italic\tCtrl+I"));
formatMenu->AppendCheckItem(ID_FORMAT_UNDERLINE, _("&Underline\tCtrl+U"));
formatMenu->AppendSeparator();
+ formatMenu->AppendCheckItem(ID_FORMAT_STRIKETHROUGH, _("Stri&kethrough"));
+ formatMenu->AppendCheckItem(ID_FORMAT_SUPERSCRIPT, _("Superscrip&t"));
+ formatMenu->AppendCheckItem(ID_FORMAT_SUBSCRIPT, _("Subscrip&t"));
+ formatMenu->AppendSeparator();
formatMenu->AppendCheckItem(ID_FORMAT_ALIGN_LEFT, _("L&eft Align"));
formatMenu->AppendCheckItem(ID_FORMAT_ALIGN_RIGHT, _("&Right Align"));
formatMenu->AppendCheckItem(ID_FORMAT_ALIGN_CENTRE, _("&Centre"));
r.Freeze();
-#if 1
r.BeginParagraphSpacing(0, 20);
r.BeginAlignment(wxTEXT_ALIGNMENT_CENTRE);
imageAttr.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_LEFT);
r.WriteText(wxString(wxT("This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side.")));
r.WriteImage(wxBitmap(zebra_xpm), wxBITMAP_TYPE_PNG, imageAttr);
+
imageAttr.GetTextBoxAttr().GetTop().SetValue(200);
imageAttr.GetTextBoxAttr().GetTop().SetUnits(wxTEXT_ATTR_UNITS_PIXELS);
imageAttr.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_RIGHT);
r.WriteText(wxT("Note: this sample content was generated programmatically from within the MyFrame constructor in the demo. The images were loaded from inline XPMs. Enjoy wxRichTextCtrl!\n"));
r.EndParagraphSpacing();
-#endif
#if 1
{
// Add a text box
r.Newline();
-
+
wxRichTextAttr attr;
attr.GetTextBoxAttr().GetMargins().GetLeft().SetValue(20, wxTEXT_ATTR_UNITS_PIXELS);
attr.GetTextBoxAttr().GetMargins().GetTop().SetValue(20, wxTEXT_ATTR_UNITS_PIXELS);
// Add a table
r.Newline();
-
+
wxRichTextAttr attr;
attr.GetTextBoxAttr().GetMargins().GetLeft().SetValue(5, wxTEXT_ATTR_UNITS_PIXELS);
attr.GetTextBoxAttr().GetMargins().GetTop().SetValue(5, wxTEXT_ATTR_UNITS_PIXELS);
r.SetInsertionPointEnd();
}
#endif
+
r.Thaw();
r.EndSuppressUndo();
m_richTextCtrl->ApplyUnderlineToSelection();
}
+void MyFrame::OnStrikethrough(wxCommandEvent& WXUNUSED(event))
+{
+ m_richTextCtrl->ApplyTextEffectToSelection(wxTEXT_ATTR_EFFECT_STRIKETHROUGH);
+}
+
+void MyFrame::OnSuperscript(wxCommandEvent& WXUNUSED(event))
+{
+ m_richTextCtrl->ApplyTextEffectToSelection(wxTEXT_ATTR_EFFECT_SUPERSCRIPT);
+}
+
+void MyFrame::OnSubscript(wxCommandEvent& WXUNUSED(event))
+{
+ m_richTextCtrl->ApplyTextEffectToSelection(wxTEXT_ATTR_EFFECT_SUBSCRIPT);
+}
+
void MyFrame::OnUpdateBold(wxUpdateUIEvent& event)
{
event.Check(m_richTextCtrl->IsSelectionUnderlined());
}
+void MyFrame::OnUpdateStrikethrough(wxUpdateUIEvent& event)
+{
+ event.Check(m_richTextCtrl->DoesSelectionHaveTextEffectFlag(wxTEXT_ATTR_EFFECT_STRIKETHROUGH));
+}
+
+void MyFrame::OnUpdateSuperscript(wxUpdateUIEvent& event)
+{
+ event.Check(m_richTextCtrl->DoesSelectionHaveTextEffectFlag(wxTEXT_ATTR_EFFECT_SUPERSCRIPT));
+}
+
+void MyFrame::OnUpdateSubscript(wxUpdateUIEvent& event)
+{
+ event.Check(m_richTextCtrl->DoesSelectionHaveTextEffectFlag(wxTEXT_ATTR_EFFECT_SUBSCRIPT));
+}
+
void MyFrame::OnAlignLeft(wxCommandEvent& WXUNUSED(event))
{
m_richTextCtrl->ApplyAlignmentToSelection(wxTEXT_ALIGNMENT_LEFT);
TAG_HANDLER_END(FONT)
-TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
+TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE,DEL")
TAG_HANDLER_CONSTR(FACES_U) { }
return true;
}
-/// Is all of the selection bold?
+/// Is all of the selection, or the current caret position, bold?
bool wxRichTextCtrl::IsSelectionBold()
{
if (HasSelection())
return false;
}
-/// Is all of the selection italics?
+/// Is all of the selection, or the current caret position, italics?
bool wxRichTextCtrl::IsSelectionItalics()
{
if (HasSelection())
return false;
}
-/// Is all of the selection underlined?
+/// Is all of the selection, or the current caret position, underlined?
bool wxRichTextCtrl::IsSelectionUnderlined()
{
if (HasSelection())
return false;
}
+/// Does all of the selection, or the current caret position, have this wxTextAttrEffects flag(s)?
+bool wxRichTextCtrl::DoesSelectionHaveTextEffectFlag(int flag)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_EFFECTS);
+ attr.SetTextEffectFlags(flag);
+ attr.SetTextEffects(flag);
+
+ if (HasSelection())
+ {
+ return HasCharacterAttributes(GetSelectionRange(), attr);
+ }
+ else
+ {
+ // If no selection, then we need to combine current style with default style
+ // to see what the effect would be if we started typing.
+ long pos = GetAdjustedCaretPosition(GetCaretPosition());
+ if (GetStyle(pos, attr))
+ {
+ if (IsDefaultStyleShowing())
+ wxRichTextApplyStyle(attr, GetDefaultStyleEx());
+ return (attr.GetTextEffectFlags() & flag);
+ }
+ }
+ return false;
+}
+
/// Apply bold to the selection
bool wxRichTextCtrl::ApplyBoldToSelection()
{
return true;
}
+/// Apply the wxTextAttrEffects flag(s) to the selection, or the current caret position if there's no selection
+bool wxRichTextCtrl::ApplyTextEffectToSelection(int flags)
+{
+ wxRichTextAttr attr;
+ attr.SetFlags(wxTEXT_ATTR_EFFECTS);
+ attr.SetTextEffectFlags(flags);
+ if (!DoesSelectionHaveTextEffectFlag(flags))
+ attr.SetTextEffects(flags);
+ else
+ attr.SetTextEffects(attr.GetTextEffectFlags() & ~flags);
+
+ if (HasSelection())
+ return SetStyleEx(GetSelectionRange(), attr, wxRICHTEXT_SETSTYLE_WITH_UNDO|wxRICHTEXT_SETSTYLE_OPTIMIZE|wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY);
+ else
+ {
+ wxRichTextAttr current = GetDefaultStyleEx();
+ current.Apply(attr);
+ SetAndShowDefaultStyle(current);
+ }
+ return true;
+}
+
/// Is all of the selection aligned according to the specified flag?
bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment)
{
if (thisStyle.HasURL())
str << wxT("<a href=\"") << thisStyle.GetURL() << wxT("\">");
+
+ if (thisStyle.HasTextEffects())
+ {
+ if (thisStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH)
+ str << wxT("<del>");
+ if (thisStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT)
+ str << wxT("<sup>");
+ if (thisStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT)
+ str << wxT("<sub>");
+ }
}
void wxRichTextHTMLHandler::EndCharacterFormatting(const wxRichTextAttr& WXUNUSED(currentStyle), const wxRichTextAttr& thisStyle, const wxRichTextAttr& WXUNUSED(paraStyle), wxTextOutputStream& stream)
if (thisStyle.GetFontWeight() == wxBOLD)
stream << wxT("</b>");
+ if (thisStyle.HasTextEffects())
+ {
+ if (thisStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_STRIKETHROUGH)
+ stream << wxT("</del>");
+ if (thisStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT)
+ stream << wxT("</sup>");
+ if (thisStyle.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT)
+ stream << wxT("</sub>");
+ }
+
if (m_font)
{
m_font = false;