Exemple #1
0
void Editbox::eraseSelectedText(bool modify_text)
{
    if (getSelectionLength() != 0)
    {
        // setup new caret position and remove selection highlight.
        setCaretIndex(d_selectionStart);
        clearSelection();

        // erase the selected characters (if required)
        if (modify_text)
        {
            String newText = getText();
            UndoHandler::UndoAction undo;
            undo.d_type = UndoHandler::UAT_DELETE;
            undo.d_startIdx = getSelectionStart();
            undo.d_text = newText.substr(getSelectionStart(), getSelectionLength());
            d_undoHandler->addUndoHistory(undo);

            newText.erase(getSelectionStart(), getSelectionLength());
            setText(newText);

            // trigger notification that text has changed.
            WindowEventArgs args(this);
            onTextChanged(args);
        }

    }

}
Exemple #2
0
//----------------------------------------------------------------------------//
void Editbox::onMouseDoubleClicked(MouseEventArgs& e)
{
    // base class processing
    Window::onMouseDoubleClicked(e);

    if (e.button == LeftButton)
    {
        // if masked, set up to select all
        if (isTextMasked())
        {
            d_dragAnchorIdx = 0;
            setCaretIndex(getText().length());
        }
        // not masked, so select the word that was double-clicked.
        else
        {
            d_dragAnchorIdx = TextUtils::getWordStartIdx(getText(),
                (d_caretPos == getText().length()) ? d_caretPos :
                                                     d_caretPos + 1);
            d_caretPos = TextUtils::getNextWordStartIdx(getText(), d_caretPos);
        }

        // perform actual selection operation.
        setSelection(d_dragAnchorIdx, d_caretPos);

        ++e.handled;
    }

}
Exemple #3
0
//----------------------------------------------------------------------------//
void Editbox::onMouseButtonDown(MouseEventArgs& e)
{
    // base class handling
    Window::onMouseButtonDown(e);

    if (e.button == LeftButton)
    {
        // grab inputs
        if (captureInput())
        {
            // handle mouse down
            clearSelection();
            d_dragging = true;
            d_dragAnchorIdx = getTextIndexFromPosition(e.position);
#ifdef CEGUI_BIDI_SUPPORT
            if (d_bidiVisualMapping->getV2lMapping().size() > d_dragAnchorIdx)
                d_dragAnchorIdx =
                    d_bidiVisualMapping->getV2lMapping()[d_dragAnchorIdx];
#endif
            setCaretIndex(d_dragAnchorIdx);
        }

        ++e.handled;
    }

}
//----------------------------------------------------------------------------//
void Editbox::handleEnd(uint sysKeys)
{
    if (d_caretPos < getText().length())
        setCaretIndex(getText().length());

    if (sysKeys & Shift)
        setSelection(d_caretPos, d_dragAnchorIdx);
    else
        clearSelection();
}
//----------------------------------------------------------------------------//
void Editbox::handleHome(uint sysKeys)
{
    if (d_caretPos > 0)
        setCaretIndex(0);

    if (sysKeys & Shift)
        setSelection(d_caretPos, d_dragAnchorIdx);
    else
        clearSelection();
}
//----------------------------------------------------------------------------//
void Editbox::handleWordRight(uint sysKeys)
{
    if (d_caretPos < getText().length())
        setCaretIndex(TextUtils::getNextWordStartIdx(getText(), d_caretPos));

    if (sysKeys & Shift)
        setSelection(d_caretPos, d_dragAnchorIdx);
    else
        clearSelection();
}
//----------------------------------------------------------------------------//
void Editbox::onTextChanged(WindowEventArgs& e)
{
    // base class processing
    Window::onTextChanged(e);

    // clear selection
    clearSelection();

    // make sure caret is within the text
    if (d_caretPos > getText().length())
        setCaretIndex(getText().length());

    ++e.handled;
}
//----------------------------------------------------------------------------//
void Editbox::onMouseTripleClicked(MouseEventArgs& e)
{
    // base class processing
    Window::onMouseTripleClicked(e);

    if (e.button == LeftButton)
    {
        d_dragAnchorIdx = 0;
        setCaretIndex(getText().length());
        setSelection(d_dragAnchorIdx, d_caretPos);
        ++e.handled;
    }

}
//----------------------------------------------------------------------------//
void Editbox::onMouseMove(MouseEventArgs& e)
{
    // base class processing
    Window::onMouseMove(e);

    if (d_dragging)
    {
        size_t anchorIdx = getTextIndexFromPosition(e.position);
#ifdef CEGUI_BIDI_SUPPORT
        if (d_bidiVisualMapping->getV2lMapping().size() > anchorIdx)
            anchorIdx = d_bidiVisualMapping->getV2lMapping()[anchorIdx];
#endif
        setCaretIndex(anchorIdx);

        setSelection(d_caretPos, d_dragAnchorIdx);
    }

    ++e.handled;
}
Exemple #10
0
//----------------------------------------------------------------------------//
void Editbox::eraseSelectedText(bool modify_text)
{
    if (getSelectionLength() != 0)
    {
        // setup new caret position and remove selection highlight.
        setCaretIndex(d_selectionStart);
        clearSelection();

        // erase the selected characters (if required)
        if (modify_text)
        {
            String newText = getText();
            newText.erase(getSelectionStartIndex(), getSelectionLength());
            setText(newText);

            // trigger notification that text has changed.
            WindowEventArgs args(this);
            onTextChanged(args);
        }

    }

}
Exemple #11
0
//----------------------------------------------------------------------------//
void Editbox::handleBackspace(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() > 0)
        {
            tmp.erase(d_caretPos - 1, 1);

            if (handleValidityChangeForString(tmp))
            {
                setCaretIndex(d_caretPos - 1);

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

    }

}
Exemple #12
0
void Editbox::onSemanticInputEvent(SemanticEventArgs& e)
{
    if (isDisabled())
        return;

    if (e.d_semanticValue == SV_SelectAll && e.d_payload.source == CIS_Left)
    {
        d_dragAnchorIdx = 0;
        setCaretIndex(getText().length());
        setSelection(d_dragAnchorIdx, d_caretPos);
        ++e.handled;
    }
    else if (e.d_semanticValue == SV_SelectWord && e.d_payload.source == CIS_Left)
    {
        // if masked, set up to select all
        if (isTextMaskingEnabled())
        {
            d_dragAnchorIdx = 0;
            setCaretIndex(getText().length());
        }
        // not masked, so select the word that was double-clicked.
        else
        {
            d_dragAnchorIdx = TextUtils::getWordStartIdx(getText(),
                (d_caretPos == getText().length()) ? d_caretPos :
                d_caretPos + 1);
            d_caretPos = TextUtils::getNextWordStartIdx(getText(), d_caretPos);
        }

        // perform actual selection operation.
        setSelection(d_dragAnchorIdx, d_caretPos);

        ++e.handled;
    }

    if (e.handled == 0 && hasInputFocus())
    {
        if (isReadOnly())
        {
            Window::onSemanticInputEvent(e);
            return;
        }

        if (getSelectionLength() == 0 && isSelectionSemanticValue(e.d_semanticValue))
            d_dragAnchorIdx = d_caretPos;

        // Check if the semantic value to be handled is of a general type and can thus be
        // handled via common EditboxBase handlers
        bool isSemanticValueHandled = handleBasicSemanticValue(e);

        // If the semantic value was not handled, check for specific values
        if (!isSemanticValueHandled)
        {
            // We assume it will be handled now, if not it will be set to false in default-case
            isSemanticValueHandled = true;

            switch (e.d_semanticValue)
            {
            case SV_Confirm:
            {
                WindowEventArgs args(this);
                // Fire 'input accepted' event
                onTextAcceptedEvent(args);
                break;
            }

            case SV_GoToStartOfLine:
                handleHome(false);
                break;

            case SV_GoToEndOfLine:
                handleEnd(false);
                break;

            case SV_SelectToStartOfLine:
                handleHome(true);
                break;

            case SV_SelectToEndOfLine:
                handleEnd(true);
                break;

            default:
                Window::onSemanticInputEvent(e);
                isSemanticValueHandled = false;
            }
        }

        if (isSemanticValueHandled)
            ++e.handled;
    }
}
Exemple #13
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);
            }
        }

    }

}