Пример #1
0
        protected override void EraseSelectedText(bool modifyText = true)
        {
            if (GetSelectionLength() != 0)
            {
                // setup new caret position and remove selection highlight.
                SetCaretIndex(_selectionStart);
                ClearSelection();

                // erase the selected characters (if required)
                if (modifyText)
                {
                    var newText = GetText();
                    var undo    = new UndoHandler.UndoAction
                    {
                        d_type     = UndoHandler.UndoActionType.UAT_DELETE,
                        d_startIdx = GetSelectionStart(),
                        d_text     =
                            newText.CEGuiSubstring(GetSelectionStart(),
                                                   GetSelectionLength())
                    };
                    _undoHandler.AddUndoHistory(undo);

                    newText = GetText().Remove(GetSelectionStart(), GetSelectionLength());
                    SetText(newText);

                    // trigger notification that text has changed.
                    OnTextChanged(new WindowEventArgs(this));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Processing for backspace key
        /// </summary>
        protected override void HandleBackspace()
        {
            if (!IsReadOnly())
            {
                var tmp = GetText();

                if (GetSelectionLength() != 0)
                {
                    var undoSelection = new UndoHandler.UndoAction
                    {
                        d_type     = UndoHandler.UndoActionType.UAT_DELETE,
                        d_startIdx = GetSelectionStart(),
                        d_text     = tmp.CEGuiSubstring(GetSelectionStart(), GetSelectionLength())
                    };

                    tmp = tmp.Remove(GetSelectionStart(), GetSelectionLength());

                    if (HandleValidityChangeForString(tmp))
                    {
                        // erase selection using mode that does not modify getText()
                        // (we just want to update state)
                        EraseSelectedText(false);

                        // set text to the newly modified string
                        SetText(tmp);
                        _undoHandler.AddUndoHistory(undoSelection);
                    }
                }
                else if (GetCaretIndex() > 0)
                {
                    var undo = new UndoHandler.UndoAction
                    {
                        d_type     = UndoHandler.UndoActionType.UAT_DELETE,
                        d_startIdx = _caretPos - 1,
                        d_text     = tmp.CEGuiSubstring(_caretPos - 1, 1)
                    };

                    tmp = tmp.Remove(_caretPos - 1, 1);

                    if (HandleValidityChangeForString(tmp))
                    {
                        SetCaretIndex(_caretPos - 1);

                        // set text to the newly modified string
                        SetText(tmp);
                        _undoHandler.AddUndoHistory(undo);
                    }
                }
            }
        }
Пример #3
0
//        protected internal override void OnCursorMove(CursorInputEventArgs e)
//        {
//            // base class processing
//            base.OnCursorMove(e);

//            if (_dragging)
//            {
//                var anchorIdx = GetTextIndexFromPosition(e.Position);
//#if CEGUI_BIDI_SUPPORT
//                if (d_bidiVisualMapping.GetV2lMapping().Count > anchorIdx)
//                    anchorIdx = d_bidiVisualMapping.GetV2lMapping()[anchorIdx];
//#endif
//                SetCaretIndex(anchorIdx);
//                SetSelection(_caretPos, _dragAnchorIdx);
//            }
//            ++e.handled;
//        }

        protected internal override void OnCharacter(TextEventArgs e)
        {
            // NB: We are not calling the base class handler here because it propogates
            // inputs back up the window hierarchy, whereas, as a consumer of key
            // events, we want such propogation to cease with us regardless of whether
            // we actually handle the event.

            // fire event.
            FireEvent(EventCharacterKey, e, EventNamespace);

            // only need to take notice if we have focus
            if (e.handled == 0 && HasInputFocus() && !IsReadOnly() &&
                GetFont().IsCodepointAvailable(e.d_character))
            {
                // backup current text
                var tmp = GetText();

                var undoSelection = new UndoHandler.UndoAction
                {
                    d_type     = UndoHandler.UndoActionType.UAT_DELETE,
                    d_startIdx = GetSelectionStart(),
                    d_text     = tmp.CEGuiSubstring(GetSelectionStart(), GetSelectionLength())
                };

                tmp = tmp.Remove(GetSelectionStart(), GetSelectionLength());

                // if there is room
                if (tmp.Length < _maxTextLen)
                {
                    var undo = new UndoHandler.UndoAction
                    {
                        d_type     = UndoHandler.UndoActionType.UAT_INSERT,
                        d_startIdx = GetSelectionStart(),
                        d_text     = e.d_character.ToString(global::System.Globalization.CultureInfo.InvariantCulture)
                    };

                    tmp = tmp.Insert(GetSelectionStart(),
                                     e.d_character.ToString(global::System.Globalization.CultureInfo.InvariantCulture));

                    if (HandleValidityChangeForString(tmp))
                    {
                        // erase selection using mode that does not modify getText()
                        // (we just want to update state)
                        EraseSelectedText(false);

                        // advance caret (done first so we can "do stuff" in event handlers!)
                        _caretPos++;

                        // set text to the newly modified string
                        SetText(tmp);

                        // char was accepted into the Editbox - mark event as handled.
                        ++e.handled;

                        _undoHandler.AddUndoHistory(undo);
                        if (GetSelectionLength() > 0)
                        {
                            _undoHandler.AddUndoHistory(undoSelection);
                        }
                    }
                }
                else
                {
                    // Trigger text box full event
                    OnEditboxFullEvent(new WindowEventArgs(this));
                }
            }
        }
Пример #4
0
        public override bool PerformPaste(Clipboard clipboard)
        {
            if (IsReadOnly())
            {
                return(false);
            }

            var clipboardText = clipboard.GetText();

            if (String.IsNullOrEmpty(clipboardText))
            {
                return(false);
            }

            // backup current text
            var tmp = GetText();

            var undoSelection = new UndoHandler.UndoAction
            {
                d_type     = UndoHandler.UndoActionType.UAT_DELETE,
                d_startIdx = GetSelectionStart(),
                d_text     = tmp.CEGuiSubstring(GetSelectionStart(), GetSelectionLength())
            };

            tmp = tmp.Remove(GetSelectionStart(), GetSelectionLength());


            // if there is room
            if (tmp.Length < _maxTextLen)
            {
                var undo = new UndoHandler.UndoAction
                {
                    d_type     = UndoHandler.UndoActionType.UAT_INSERT,
                    d_startIdx = GetCaretIndex(),
                    d_text     = clipboardText
                };

                tmp = tmp.Insert(GetSelectionStart(), clipboardText);

                if (HandleValidityChangeForString(tmp))
                {
                    // erase selection using mode that does not modify getText()
                    // (we just want to update state)
                    EraseSelectedText(false);

                    // advance caret (done first so we can "do stuff" in event
                    // handlers!)
                    _caretPos += clipboardText.Length;

                    // set text to the newly modified string
                    SetText(tmp);

                    _undoHandler.AddUndoHistory(undo);
                    if (GetSelectionLength() > 0)
                    {
                        _undoHandler.AddUndoHistory(undoSelection);
                    }

                    return(true);
                }
            }

            return(false);
        }