void Screen::displayCharacter(unsigned short c) { // Note that VT100 does wrapping BEFORE putting the character. // This has impact on the assumption of valid cursor positions. // We indicate the fact that a newline has to be triggered by // putting the cursor one right to the last column of the screen. int w = konsole_wcwidth(c); if (w <= 0) return; if (cuX+w > columns) { if (getMode(MODE_Wrap)) { lineProperties[cuY] = (LineProperty)(lineProperties[cuY] | LINE_WRAPPED); nextLine(); } else cuX = columns-w; } // ensure current line vector has enough elements int size = screenLines[cuY].size(); if (size < cuX+w) { screenLines[cuY].resize(cuX+w); } if (getMode(MODE_Insert)) insertChars(w); lastPos = loc(cuX,cuY); // check if selection is still valid. checkSelection(lastPos, lastPos); Character& currentChar = screenLines[cuY][cuX]; currentChar.character = c; currentChar.foregroundColor = effectiveForeground; currentChar.backgroundColor = effectiveBackground; currentChar.rendition = effectiveRendition; int i = 0; int newCursorX = cuX + w--; while(w) { i++; if ( screenLines[cuY].size() < cuX + i + 1 ) screenLines[cuY].resize(cuX+i+1); Character& ch = screenLines[cuY][cuX + i]; ch.character = 0; ch.foregroundColor = effectiveForeground; ch.backgroundColor = effectiveBackground; ch.rendition = effectiveRendition; w--; } cuX = newCursorX; }
void Text::paste() { // --- see if there is anything to do ---- if (! textBuffer_) return; insertChars(textBuffer_->Text(), textBuffer_->Length()); }
bool UIEdit::handleKeypress(Common::Event *event, bool printable) { bool handled = false; if (event->type == Common::EVENT_KEYDOWN && !printable) { switch (event->kbd.keycode) { case Common::KEYCODE_ESCAPE: case Common::KEYCODE_TAB: case Common::KEYCODE_RETURN: return false; // ctrl+A case Common::KEYCODE_a: if (BaseKeyboardState::isControlDown()) { _selStart = 0; _selEnd = strlen(_text); handled = true; } break; case Common::KEYCODE_BACKSPACE: if (_selStart == _selEnd) { if (_gameRef->_textRTL) { deleteChars(_selStart, _selStart + 1); } else { deleteChars(_selStart - 1, _selStart); } } else { deleteChars(_selStart, _selEnd); } if (_selEnd >= _selStart) { _selEnd -= MAX(1, _selEnd - _selStart); } _selStart = _selEnd; handled = true; break; case Common::KEYCODE_LEFT: case Common::KEYCODE_UP: _selEnd--; if (!BaseKeyboardState::isShiftDown()) { _selStart = _selEnd; } handled = true; break; case Common::KEYCODE_RIGHT: case Common::KEYCODE_DOWN: _selEnd++; if (!BaseKeyboardState::isShiftDown()) { _selStart = _selEnd; } handled = true; break; case Common::KEYCODE_HOME: if (_gameRef->_textRTL) { _selEnd = strlen(_text); if (!BaseKeyboardState::isShiftDown()) { _selStart = _selEnd; } } else { _selEnd = 0; if (!BaseKeyboardState::isShiftDown()) { _selStart = _selEnd; } } handled = true; break; case Common::KEYCODE_END: if (_gameRef->_textRTL) { _selEnd = 0; if (!BaseKeyboardState::isShiftDown()) { _selStart = _selEnd; } } else { _selEnd = strlen(_text); if (!BaseKeyboardState::isShiftDown()) { _selStart = _selEnd; } } handled = true; break; case Common::KEYCODE_DELETE: if (_selStart == _selEnd) { if (_gameRef->_textRTL) { deleteChars(_selStart - 1, _selStart); _selEnd--; if (_selEnd < 0) { _selEnd = 0; } } else { deleteChars(_selStart, _selStart + 1); } } else { deleteChars(_selStart, _selEnd); } if (_selEnd > _selStart) { _selEnd -= (_selEnd - _selStart); } _selStart = _selEnd; handled = true; break; default: break; } return handled; } else if (event->type == Common::EVENT_KEYDOWN && printable) { if (_selStart != _selEnd) { deleteChars(_selStart, _selEnd); } //WideString wstr = StringUtil::Utf8ToWide(event->kbd.ascii); WideString wstr; wstr += (char)event->kbd.ascii; _selEnd += insertChars(_selEnd, (const byte *)StringUtil::wideToAnsi(wstr).c_str(), 1); if (_gameRef->_textRTL) { _selEnd = _selStart; } else { _selStart = _selEnd; } return true; } return false; }
void Text::keystroke(const Event& event) { if (readOnly_) { return; } char buffer[8]; // needs to be dynamically adjusted int count = event.mapkey(buffer, 8); if (count <= 0) { return; } // return causes a newline if (buffer[0] == '\r') { buffer[0] = '\n'; } context_key(buffer[0]); if (buffer[0] == 2) // control-b { if (insertion_.column_ > 0) { --insertion_.column_; damage(insertion_); repair(); }else if (insertion_.line_ > 0) { damage(insertion_); --insertion_.line_; // now just like a control-e int index = text_->LineIndex(insertion_.line_); int end = text_->EndOfLine(index); insertion_.column_ = end - index; damage(insertion_); repair(); } return; } else if (buffer[0] == 1) // control-a { insertion_.column_ = 0; damage(insertion_); repair(); return; } else if (buffer[0] == 6) // control-f { int index = text_->LineIndex(insertion_.line_); int end = text_->EndOfLine(index); if (insertion_.column_ < end - index) { ++insertion_.column_; damage(insertion_); repair(); }else if (insertion_.line_ < text_->Height()-1) { damage(insertion_); ++insertion_.line_; // now just like control-a insertion_.column_ = 0; damage(insertion_); repair(); } return; } else if (buffer[0] == 5) // control-e { int index = text_->LineIndex(insertion_.line_); int end = text_->EndOfLine(index); insertion_.column_ = end - index; damage(insertion_); repair(); return; } else if (buffer[0] == 16) { // control-p if (insertion_.line_ > 0) { damage(insertion_); --insertion_.line_; insertion_.column_ = ctl_pn_col_; int index = text_->LineIndex(insertion_.line_); int col = text_->EndOfLine(index) - index; if (col < insertion_.column_){ insertion_.column_ = col; } damage(insertion_); repair(); } return; }else if (buffer[0] == 14) { // control-n if (insertion_.line_ < text_->Height()-1) { damage(insertion_); ++insertion_.line_; insertion_.column_ = ctl_pn_col_; int index = text_->LineIndex(insertion_.line_); int col = text_->EndOfLine(index) - index; if (col < insertion_.column_){ insertion_.column_ = col; } damage(insertion_); repair(); } return; }else if (escape_ == 1) { // escaped chars if (buffer[0] == '>') { // to end of buffer damage(insertion_); if (text_->Height() >0) { insertion_.line_ = text_->Height()-1; } else { insertion_.line_ = 0; } int index = text_->LineIndex(text_->EndOfText()); insertion_.column_ = text_->EndOfText()-index; damage(insertion_); repair(); }else if (buffer[0] == '<') {// to beginning of buffer damage(insertion_); insertion_.line_ = 0; insertion_.column_ = 0; damage(insertion_); repair(); } return; }else if (buffer[0] == 033) { // ignore the escape itself return; } else if (buffer[0] == 4) // ctrl-d { if (!delete_selection()) { // like a ctrl-f then backspace int index = text_->LineIndex(insertion_.line_); int end = text_->EndOfLine(index); if (insertion_.column_ < end - index) { ++insertion_.column_; backspace(); }else if (insertion_.line_ < text_->Height()-1) { ++insertion_.line_; // now just like control-a insertion_.column_ = 0; backspace(); } } } else if (buffer[0] == 21) { // control u eraseLine(); } else if ((buffer[0] == '\b') || (buffer[0] == 127)) { // backspace and delete if (!delete_selection()) { backspace(); } } else { delete_selection(); insertChars(buffer, count); } dirty(true); }
void Text::paste(const char* buffer, unsigned count) { insertChars(buffer, count); }