Exemple #1
0
void TextEdit::onKeyPress(XEvent& event)
{
    if (inputDisabled) return;

    preProcessCommand();

    // State of modifiers keys (Shift, Controld, Alt, etc.)
    unsigned int state = event.xkey.state;

    KeySym keySymbol; // X11 keyboard symbol (see "/usr/include/X11/keysymdef.h")
    char keyName[256];
    int keyNameLen;

    keyNameLen = XLookupString( // define keyboard symbol
        &(event.xkey), keyName, 255, &keySymbol, 0
    );

    // Look up the command in the table
    const struct CommandDsc* command = editorCommands;
    bool commandFound = false;
    while (!commandFound && command->method != 0)
    {
        if (keySymbol == command->keysym && (state & command->stateMask) == command->state)
        { commandFound = true; break; }
        ++command;
    }

    if (commandFound) {
        (this->*(command->method))();   // Perform the command
        if (command->change) {
            textChanged = true;         // Command changes the text
        }
    } else if ((state & ControlMask) == 0) {
        // This is not a Control character
        if (keyNameLen > 0) {
            // Normal character (Latin letter, etc.)
            lastChar = keyName[0];
            onCharTyped();
            textChanged = true;
        } else if ((keySymbol & 0x8000) == 0) {
            // This is not a special character. Probably, it is a Russian letter
            lastChar = (keySymbol & 0xff);
            onCharTyped();
            textChanged = true;
        }
    }

    postProcessCommand();
}
Exemple #2
0
bool InputField::onKeyDown(SDLKey key, unsigned char translatedChar)
{
    switch (key) {
    case SDLK_BACKSPACE:
        if (cursorPos > 0) {
            text.erase(cursorPos - 1, 1);
            moveCursor(cursorPos - 1);
        } else
            moveCursor(cursorPos);
        draw();
        return true;

    case SDLK_LEFT:
        if (cursorPos > 0)
            moveCursor(cursorPos - 1);
        else
            moveCursor(cursorPos);
        draw();
        return true;

    case SDLK_RIGHT:
        if (cursorPos < (int)text.length())
            moveCursor(cursorPos + 1);
        else
            moveCursor(cursorPos);
        draw();
        return true;

    case SDLK_HOME:
        moveCursor(0);
        draw();
        return true;

    case SDLK_END:
        moveCursor(text.length());
        draw();
        return true;

    case SDLK_DELETE:
        if (cursorPos < (int)text.length())
            text.erase(cursorPos, 1);
        moveCursor(cursorPos);
        draw();
        return true;

    default:
        ;
    }

    if (translatedChar > 31)
        onCharTyped(translatedChar);
    return false;
}
Exemple #3
0
void TextEdit::onInsert() { // Insert a space
    lastChar = ' ';
    onCharTyped();
    --cursorX;
}