#include "wx/fontenum.h"
#include "wx/accel.h"
+#if defined (__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__)
+#define wxHAVE_PRIMARY_SELECTION 1
+#else
+#define wxHAVE_PRIMARY_SELECTION 0
+#endif
+
+#if wxUSE_CLIPBOARD && wxHAVE_PRIMARY_SELECTION
+#include "wx/clipbrd.h"
+#endif
+
// DLL options compatibility check:
#include "wx/app.h"
WX_CHECK_BUILD_OPTIONS("wxRichTextCtrl")
}
}
}
+
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
+ if (HasSelection() && GetFocusObject() && GetFocusObject()->GetBuffer())
+ {
+ // Put the selection in PRIMARY, if it exists
+ wxTheClipboard->UsePrimarySelection(true);
+
+ wxRichTextRange range = GetInternalSelectionRange();
+ GetFocusObject()->GetBuffer()->CopyToClipboard(range);
+
+ wxTheClipboard->UsePrimarySelection(false);
+ }
+#endif
}
/// Left-click
if (!GetEventHandler()->ProcessEvent(cmdEvent))
event.Skip();
+
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ && wxHAVE_PRIMARY_SELECTION
+ // Paste any PRIMARY selection, if it exists
+ wxTheClipboard->UsePrimarySelection(true);
+ Paste();
+ wxTheClipboard->UsePrimarySelection(false);
+#endif
}
/// Key press
if (GetCaret()->GetSize() != newSz)
GetCaret()->SetSize(newSz);
- int halfSize = newSz.y/2;
- // If the caret is beyond the margin, hide it by moving it out of the way
- if (((pt.y + halfSize) < GetBuffer().GetTopMargin()) || ((pt.y + halfSize) > (GetClientSize().y - GetBuffer().GetBottomMargin())))
+ // Adjust size so the caret size and position doesn't appear in the margins
+ if (((pt.y + newSz.y) <= GetBuffer().GetTopMargin()) || (pt.y >= (GetClientSize().y - GetBuffer().GetBottomMargin())))
{
pt.x = -200;
pt.y = -200;
}
+ else if (pt.y < GetBuffer().GetTopMargin() && (pt.y + newSz.y) > GetBuffer().GetTopMargin())
+ {
+ newSz.y -= (GetBuffer().GetTopMargin() - pt.y);
+ if (newSz.y > 0)
+ {
+ pt.y = GetBuffer().GetTopMargin();
+ GetCaret()->SetSize(newSz);
+ }
+ }
+ else if (pt.y < (GetClientSize().y - GetBuffer().GetBottomMargin()) && (pt.y + newSz.y) > (GetClientSize().y - GetBuffer().GetBottomMargin()))
+ {
+ newSz.y = GetClientSize().y - GetBuffer().GetBottomMargin() - pt.y;
+ GetCaret()->SetSize(newSz);
+ }
GetCaret()->Move(pt);
GetCaret()->Show();
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) != 0;
+ }
+ }
+ 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)
{