Beispiel #1
0
//----------------------------------------------------------------------------//
void Editbox::handleDelete(void)
{
    if (!isReadOnly())
    {
        String tmp(getText());

        if (getSelectionLength() != 0)
        {
            tmp.erase(getSelectionStartIndex(), 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);
            }
        }
        else if (getCaretIndex() < tmp.length())
        {
            tmp.erase(d_caretPos, 1);

            if (handleValidityChangeForString(tmp))
            {
                // set text to the newly modified string
                setText(tmp);
            }
        }

    }

}
Beispiel #2
0
void Editbox::handleDelete(void)
{
    if (!isReadOnly())
    {
        String tmp(getText());

        if (getSelectionLength() != 0)
        {
            UndoHandler::UndoAction undoSelection;
            undoSelection.d_type = UndoHandler::UAT_DELETE;
            undoSelection.d_startIdx = getSelectionStart();
            undoSelection.d_text = tmp.substr(getSelectionStart(), getSelectionLength());

            tmp.erase(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);
                d_undoHandler->addUndoHistory(undoSelection);
            }
        }
        else if (getCaretIndex() < tmp.length())
        {
            UndoHandler::UndoAction undo;
            undo.d_type = UndoHandler::UAT_DELETE;
            undo.d_startIdx = d_caretPos;

#if CEGUI_STRING_CLASS != CEGUI_STRING_CLASS_UTF_8
            size_t eraseLength = 1;
#else
            size_t eraseLength = String::getCodePointSize(tmp[d_caretPos]);
#endif

            undo.d_text = tmp.substr(d_caretPos, eraseLength);

            tmp.erase(d_caretPos, eraseLength);

            if (handleValidityChangeForString(tmp))
            {
                // set text to the newly modified string
                setText(tmp);
                d_undoHandler->addUndoHistory(undo);
            }
        }

    }

}
Beispiel #3
0
bool Editbox::performPaste(Clipboard& clipboard)
{
    if (isReadOnly())
        return false;

    String clipboardText = clipboard.getText();

    if (clipboardText.empty())
        return false;

    // backup current text
    String tmp(getText());

    UndoHandler::UndoAction undoSelection;
    undoSelection.d_type = UndoHandler::UAT_DELETE;
    undoSelection.d_startIdx = getSelectionStart();
    undoSelection.d_text = tmp.substr(getSelectionStart(), getSelectionLength());

    tmp.erase(getSelectionStart(), getSelectionLength());

    // if there is room
    if (tmp.length() < d_maxTextLen)
    {
        UndoHandler::UndoAction undo;
        undo.d_type = UndoHandler::UAT_INSERT;
        undo.d_startIdx = getCaretIndex();
        undo.d_text = clipboardText;

        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!)
            d_caretPos += clipboardText.length();

            // set text to the newly modified string
            setText(tmp);
            d_undoHandler->addUndoHistory(undo);
            if (getSelectionLength() > 0)
                d_undoHandler->addUndoHistory(undoSelection);

            return true;
        }
    }

    return false;
}
Beispiel #4
0
void Editbox::handleBackspace(void)
{
    if (!isReadOnly())
    {
        String tmp(getText());

        if (getSelectionLength() != 0)
        {
            UndoHandler::UndoAction undoSelection;
            undoSelection.d_type = UndoHandler::UAT_DELETE;
            undoSelection.d_startIdx = getSelectionStart();
            undoSelection.d_text = tmp.substr(getSelectionStart(), getSelectionLength());

            tmp.erase(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);
                d_undoHandler->addUndoHistory(undoSelection);
            }
        }
        else if (getCaretIndex() > 0)
        {
            UndoHandler::UndoAction undo;
            undo.d_type = UndoHandler::UAT_DELETE;

#if CEGUI_STRING_CLASS != CEGUI_STRING_CLASS_UTF_8
            size_t deleteStartPos = d_caretPos - 1;
            size_t deleteLength = 1;
#else
            String::codepoint_iterator caretIter(tmp.begin() + d_caretPos,
                                                 tmp.begin(), tmp.end());
            --caretIter;

            size_t deleteStartPos = caretIter.getCodeUnitIndexFromStart();
            size_t deleteLength = d_caretPos - deleteStartPos;
#endif

            undo.d_startIdx = deleteStartPos;
            undo.d_text = tmp.substr(deleteStartPos, deleteLength);

            tmp.erase(deleteStartPos, deleteLength);

            if (handleValidityChangeForString(tmp))
            {
                setCaretIndex(deleteStartPos);

                // set text to the newly modified string
                setText(tmp);
                d_undoHandler->addUndoHistory(undo);
            }
        }

    }

}